Windows NT 4.0 source code leak
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

154 lines
2.7 KiB

4 years ago
  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. All rights reserved.
  4. Module Name:
  5. String.hxx
  6. Abstract:
  7. Short-short implementation of strings.
  8. Author:
  9. Albert Ting (AlbertT) 9-June-1994
  10. Revision History:
  11. --*/
  12. #ifndef _STRING_HXX
  13. #define _STRING_HXX
  14. class TString {
  15. SIGNATURE( 'strg' )
  16. SAFE_NEW
  17. public:
  18. //
  19. // For the default constructor, we initialize _pszString to a
  20. // global gszState[kValid] string. This allows them to work correctly,
  21. // but prevents the extra memory allocation.
  22. //
  23. // Note: if this class is extended (with reference counting
  24. // or "smart" reallocations), this strategy may break.
  25. //
  26. TString(
  27. VOID
  28. );
  29. TString(
  30. IN LPCTSTR psz
  31. );
  32. ~TString(
  33. VOID
  34. );
  35. TString(
  36. IN const TString &String
  37. );
  38. BOOL
  39. bEmpty(
  40. VOID
  41. ) const;
  42. BOOL
  43. bValid(
  44. VOID
  45. ) const;
  46. BOOL
  47. bUpdate(
  48. IN LPCTSTR pszNew
  49. );
  50. BOOL
  51. bLoadString(
  52. IN HINSTANCE hInst,
  53. IN UINT uID
  54. );
  55. UINT
  56. TString::
  57. uLen(
  58. VOID
  59. ) const;
  60. BOOL
  61. TString::
  62. bCat(
  63. IN LPCTSTR psz
  64. );
  65. //
  66. // Operator overloads.
  67. //
  68. operator LPCTSTR( VOID ) const
  69. { return _pszString; }
  70. friend INT operator==(const TString& String, LPCTSTR& psz)
  71. { return !lstrcmp(String._pszString, psz); }
  72. friend INT operator==(LPCTSTR& psz, const TString& String)
  73. { return !lstrcmp(psz, String._pszString); }
  74. friend INT operator==(const TString& String1, const TString& String2)
  75. { return !lstrcmp(String1._pszString, String2._pszString); }
  76. friend INT operator!=(const TString& String, LPCTSTR& psz)
  77. { return lstrcmp(String._pszString, psz) != 0; }
  78. friend INT operator!=(LPCTSTR& psz, const TString& String)
  79. { return lstrcmp(psz, String._pszString) != 0; }
  80. friend INT operator!=(const TString& String1, const TString& String2)
  81. { return lstrcmp(String1._pszString, String2._pszString) != 0; }
  82. protected:
  83. //
  84. // Not defined; used bUpdate since this forces clients to
  85. // check whether the assignment succeeded (it may fail due
  86. // to lack of memory, etc.).
  87. //
  88. TString& operator=( LPCTSTR psz );
  89. TString& operator=(const TString& String);
  90. private:
  91. enum StringStatus {
  92. kValid = 0,
  93. kInValid = 1,
  94. };
  95. LPTSTR _pszString;
  96. static TCHAR gszNullState[2];
  97. VOID
  98. TString::
  99. vFree(
  100. IN LPTSTR pszString
  101. );
  102. };
  103. LPTSTR
  104. pszLoadString(
  105. HINSTANCE hInst,
  106. UINT uID
  107. );
  108. #ifdef UNICODE
  109. #define lstrchr wcschr
  110. #else
  111. #define lstrchr strchr
  112. #endif
  113. #endif // ndef _STRING_HXX