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.

201 lines
5.4 KiB

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