Leaked source code of windows server 2003
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.

196 lines
5.5 KiB

  1. //-----------------------------------------------------------------------------
  2. //
  3. // File: passtr.h
  4. // Copyright (C) 1994-1997 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // Declaration for a pascal (counted) style wide character string class.
  8. // The count reflects the number of characters (including NUL characters),
  9. // not the amount of storage. Any string in a PascalString is automatically
  10. // given a NULL terminator, even if it already has one. This extra terminator
  11. // is NOT in the count of characters in the string.
  12. //
  13. //-----------------------------------------------------------------------------
  14. #ifndef PASSTR_H
  15. #define PASSTR_H
  16. class _bstr_t;
  17. class CUnicodeException : public CSimpleException
  18. {
  19. public:
  20. enum UnicodeCause
  21. {
  22. noCause = 0,
  23. invalidChar = 1,
  24. unknownCodePage
  25. };
  26. UnicodeCause m_cause;
  27. NOTHROW CUnicodeException(UnicodeCause);
  28. NOTHROW CUnicodeException(UnicodeCause, BOOL);
  29. NOTHROW ~CUnicodeException();
  30. virtual BOOL GetErrorMessage(LPTSTR lpszError, UINT nMaxError,
  31. PUINT pnHelpContext = NULL );
  32. };
  33. void LTAPIENTRY ThrowUnicodeException(CUnicodeException::UnicodeCause);
  34. class LTAPIENTRY CPascalString
  35. {
  36. public:
  37. NOTHROW CPascalString();
  38. NOTHROW CPascalString(const CPascalString &);
  39. void AssertValid(void) const;
  40. //
  41. // The ultimate assignment operator - any random collection
  42. // of WIDE characters can be placed in the string.
  43. // Also, we can convert any collection of DBCS style strings,
  44. // so long as the user provides a code page to work with...
  45. //
  46. void SetString(const WCHAR *, UINT);
  47. void SetString(const char *, UINT, CodePage);
  48. void SetString(const CLString &, CodePage);
  49. //
  50. // Useful assignment operators
  51. //
  52. const CPascalString & operator=(const CPascalString &);
  53. const CPascalString & operator=(const WCHAR *);
  54. const CPascalString & operator=(const _bstr_t &);
  55. const CPascalString & operator+=(const CPascalString &);
  56. const CPascalString & operator+=(const WCHAR *);
  57. const CPascalString & operator+=(const WCHAR);
  58. void Format(const WCHAR *, ...);
  59. //
  60. // Comparison operators for counted strings.
  61. //
  62. NOTHROW int operator==(const CPascalString &) const;
  63. NOTHROW int operator!=(const CPascalString &) const;
  64. NOTHROW int operator==(const _bstr_t &) const;
  65. NOTHROW int operator!=(const _bstr_t &) const;
  66. NOTHROW int operator==(const WCHAR *) const;
  67. NOTHROW int operator!=(const WCHAR *) const;
  68. NOTHROW BOOL IsNull(void) const;
  69. //
  70. // Retrieving the data from the string.
  71. //
  72. NOTHROW UINT GetStringLength(void) const;
  73. void SetStringLength(UINT);
  74. void ReallocString(UINT);
  75. void ReserveStorage(UINT);
  76. NOTHROW WCHAR * GetStringPointer(void);
  77. NOTHROW void ReleaseStringPointer(void);
  78. NOTHROW operator const WCHAR *(void) const;
  79. // const BSTR GetBSTR(void) const;
  80. NOTHROW WCHAR operator[](UINT) const;
  81. NOTHROW WCHAR & operator[](UINT);
  82. //
  83. // Sub-string extraction
  84. //
  85. NOTHROW void Left(CPascalString &, UINT) const;
  86. NOTHROW void Right(CPascalString &, UINT) const;
  87. NOTHROW void Mid(CPascalString &, UINT) const;
  88. NOTHROW void Mid(CPascalString &, UINT, UINT) const;
  89. //
  90. // Locate
  91. //
  92. NOTHROW BOOL Find(WCHAR, UINT, UINT &) const;
  93. NOTHROW BOOL FindOneOf(const CPascalString&, UINT, UINT &) const;
  94. NOTHROW BOOL FindExcept(const CPascalString &, UINT, UINT &) const;
  95. NOTHROW BOOL FindSubString(const CPascalString &, UINT, UINT &) const;
  96. NOTHROW BOOL ReverseFind(WCHAR, UINT, UINT &) const;
  97. NOTHROW BOOL ReverseFindOneOf(const CPascalString &, UINT, UINT &) const;
  98. NOTHROW BOOL ReverseFindExcept(const CPascalString &, UINT, UINT &) const;
  99. //
  100. // Clears the contents of a Pascal string.
  101. //
  102. NOTHROW void ClearString(void);
  103. //
  104. // Conversion API's for Pascal style strings.
  105. //
  106. enum ConvFlags
  107. {
  108. ConvNoFlags = 0, // No conversion options
  109. HexifyDefaultChars = 0x01, // Hexify chars that convert to the default char
  110. HexifyNonPrintingChars = 0x02,
  111. HexifyWhiteSpace = 0x04,
  112. ConvAddNull = 0x08,
  113. ConvAllFlags = 0xFF
  114. };
  115. void ConvertToCLString(CLString &, CodePage, BOOL fHex=FALSE) const;
  116. void ConvertToMBCSBlob(CLocCOWBlob &, CodePage, DWORD dwFlags = ConvNoFlags) const;
  117. NOTHROW void MakeUpper(void);
  118. NOTHROW void MakeLower(void);
  119. _bstr_t MakeBSTRT() const;
  120. void Serialize(CArchive &ar);
  121. void Load(CArchive &ar);
  122. void Store(CArchive &ar) const;
  123. static const char *szUnmappableChar;
  124. static char cHexLeaderChar;
  125. static void EscapeBackSlash(const CPascalString &srcStr,
  126. CPascalString &destStr);
  127. int ParseEscapeSequences(CPascalString &pasError);
  128. ~CPascalString();
  129. protected:
  130. NOTHROW BOOL IsEqualTo(const CPascalString &) const;
  131. NOTHROW void AppendBuffer(const WCHAR *, UINT);
  132. private:
  133. void FormatV(const WCHAR *, va_list arglist);
  134. CLocCOWBlob m_blbData;
  135. operator const CLocCOWBlob &(void) const;
  136. DEBUGONLY(static CCounter m_UsageCounter);
  137. DEBUGONLY(static CCounter m_StorageCounter);
  138. };
  139. typedef CArray<CPascalString, CPascalString &> CPasStringArray;
  140. //
  141. // Comparison helper functions. These should all have the
  142. // CPascalString as the SECOND arguement.
  143. //
  144. NOTHROW int LTAPIENTRY operator==(const WCHAR *, const CPascalString &);
  145. NOTHROW int LTAPIENTRY operator!=(const WCHAR *, const CPascalString &);
  146. NOTHROW int LTAPIENTRY operator==(const _bstr_t &, const CPascalString &);
  147. NOTHROW int LTAPIENTRY operator!=(const _bstr_t, const CPascalString &);
  148. #if !defined(_DEBUG) || defined(IMPLEMENT)
  149. #include "passtr.inl"
  150. #endif
  151. #endif // PASSTR_H