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.

123 lines
3.9 KiB

  1. /*++
  2. Copyright (C) 1996-2001 Microsoft Corporation
  3. Module Name:
  4. WSTRING.H
  5. Abstract:
  6. Utility string class
  7. History:
  8. a-raymcc 30-May-96 Created.
  9. a-dcrews 16-Mar-99 Added out-of-memory exception handling
  10. --*/
  11. #ifndef _WSTRING_H_
  12. #define _WSTRING_H_
  13. #include "corepol.h"
  14. #include <strutils.h>
  15. class POLARITY WString
  16. {
  17. private:
  18. wchar_t *m_pString;
  19. void DeleteString(wchar_t *pStr);
  20. public:
  21. enum { leading = 0x1, trailing = 0x2 };
  22. WString(wchar_t *pSrc, BOOL bAcquire = FALSE);
  23. WString(DWORD dwResourceID, HMODULE hMod); // creates from resource string
  24. WString(const wchar_t *pSrc);
  25. WString(const char *pSrc);
  26. // inline WString() { m_pString = g_szNullString; }
  27. WString();
  28. inline WString(const WString &Src) { m_pString = 0; *this = Src; }
  29. WString& operator =(const WString &);
  30. WString& operator =(LPCWSTR);
  31. inline ~WString() { DeleteString(m_pString); }
  32. inline int Length() const { return wcslen(m_pString); }
  33. WString& operator +=(const WString &Other);
  34. WString& operator +=(const wchar_t *);
  35. WString& operator +=(wchar_t);
  36. inline operator const wchar_t *() const { return m_pString; }
  37. inline operator wchar_t *() { return m_pString; }
  38. wchar_t operator[](int nIndex) const;
  39. LPSTR GetLPSTR() const;
  40. inline BOOL Equal(const wchar_t *pTarget) const
  41. { return wcscmp(m_pString, pTarget) == 0; }
  42. inline BOOL EqualNoCase(const wchar_t *pTarget) const
  43. { return wbem_wcsicmp(m_pString, pTarget) == 0; }
  44. inline BOOL operator< (LPCWSTR wszTarget) const
  45. { return wcscmp(m_pString, wszTarget) < 0; }
  46. inline BOOL operator> (LPCWSTR wszTarget) const
  47. { return wcscmp(m_pString, wszTarget) > 0; }
  48. inline BOOL operator<= (LPCWSTR wszTarget) const
  49. { return wcscmp(m_pString, wszTarget) <= 0; }
  50. inline BOOL operator>= (LPCWSTR wszTarget) const
  51. { return wcscmp(m_pString, wszTarget) >= 0; }
  52. LPWSTR UnbindPtr();
  53. inline void BindPtr(LPWSTR ptr) { DeleteString(m_pString); m_pString = ptr; }
  54. void Empty();
  55. WString& StripWs(int nType);
  56. // Strip whitespace, use with a combination
  57. // of leading | trailing
  58. WString& TruncAtRToken(wchar_t Token);
  59. // Truncates the string at the token starting from the
  60. // right end. The token itself is also wiped out.
  61. WString& TruncAtLToken(wchar_t Token);
  62. WString& StripToToken(wchar_t Token, BOOL bIncludeToken);
  63. // Strips leading chars until the token is encountered.
  64. // If bIncludeTok==TRUE, strips the token too.
  65. wchar_t *GetLToken(wchar_t wcToken) const;
  66. // Gets the first occurrence of wcToken in the string or NULL
  67. WString operator()(int, int) const;
  68. // Returns a new WString based on the slice
  69. BOOL ExtractToken(const wchar_t * pDelimiters, WString &Extract);
  70. // Extracts the leading chars up to the token delimiter,
  71. // Removing the token from *this, and assigning the extracted
  72. // part to <Extract>.
  73. BOOL ExtractToken(wchar_t Delimiter, WString &Extract);
  74. // Extracts the leading chars up to the token delimiter,
  75. // Removing the token from *this, and assigning the extracted
  76. // part to <Extract>.
  77. BOOL WildcardTest(const wchar_t *pTestStr) const;
  78. // Tests *this against the wildcard string. If a match,
  79. // returns TRUE, else FALSE.
  80. void Unquote();
  81. // Removes leading/trailing quotes, if any.
  82. // Leaves escaped quotes intact.
  83. WString EscapeQuotes() const;
  84. };
  85. class WSiless
  86. {
  87. public:
  88. inline bool operator()(const WString& ws1, const WString& ws2) const
  89. {return wbem_wcsicmp(ws1, ws2) < 0;}
  90. };
  91. #endif