Source code of Windows XP (NT5)
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.

173 lines
3.1 KiB

  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. // Caution: See function header for usage and side effects.
  67. //
  68. BOOL
  69. TString::
  70. bFormat(
  71. IN LPCTSTR pszFmt,
  72. IN ...
  73. );
  74. //
  75. // Caution: See function header for usage and side effects.
  76. //
  77. BOOL
  78. TString::
  79. bvFormat(
  80. IN LPCTSTR pszFmt,
  81. IN va_list avlist
  82. );
  83. //
  84. // Operator overloads.
  85. //
  86. operator LPCTSTR( VOID ) const
  87. { return _pszString; }
  88. friend INT operator==(const TString& String, LPCTSTR& psz)
  89. { return !lstrcmp(String._pszString, psz); }
  90. friend INT operator==(LPCTSTR& psz, const TString& String)
  91. { return !lstrcmp(psz, String._pszString); }
  92. friend INT operator==(const TString& String1, const TString& String2)
  93. { return !lstrcmp(String1._pszString, String2._pszString); }
  94. friend INT operator!=(const TString& String, LPCTSTR& psz)
  95. { return lstrcmp(String._pszString, psz) != 0; }
  96. friend INT operator!=(LPCTSTR& psz, const TString& String)
  97. { return lstrcmp(psz, String._pszString) != 0; }
  98. friend INT operator!=(const TString& String1, const TString& String2)
  99. { return lstrcmp(String1._pszString, String2._pszString) != 0; }
  100. protected:
  101. //
  102. // Not defined; used bUpdate since this forces clients to
  103. // check whether the assignment succeeded (it may fail due
  104. // to lack of memory, etc.).
  105. //
  106. TString& operator=( LPCTSTR psz );
  107. TString& operator=(const TString& String);
  108. private:
  109. enum StringStatus {
  110. kValid = 0,
  111. kInValid = 1,
  112. };
  113. enum {
  114. kStrIncrement = 256,
  115. kStrMaxFormatSize = 1024 * 100,
  116. };
  117. LPTSTR _pszString;
  118. static TCHAR gszNullState[2];
  119. LPTSTR
  120. TString::
  121. vsntprintf(
  122. IN LPCTSTR szFmt,
  123. IN va_list pArgs
  124. );
  125. VOID
  126. TString::
  127. vFree(
  128. IN LPTSTR pszString
  129. );
  130. };
  131. #endif // ndef _STRING_HXX