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.

121 lines
3.8 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 <strutils.h>
  14. class WString
  15. {
  16. wchar_t *m_pString;
  17. void DeleteString(wchar_t *pStr);
  18. public:
  19. enum { leading = 0x1, trailing = 0x2 };
  20. WString(wchar_t *pSrc, BOOL bAcquire = FALSE);
  21. WString(DWORD dwResourceID, HMODULE hMod); // creates from resource string
  22. WString(const wchar_t *pSrc);
  23. WString(const char *pSrc);
  24. // inline WString() { m_pString = g_szNullString; }
  25. WString();
  26. inline WString(const WString &Src) { m_pString = 0; *this = Src; }
  27. WString& operator =(const WString &);
  28. WString& operator =(LPCWSTR);
  29. inline ~WString() { DeleteString(m_pString); }
  30. inline int Length() const { return wcslen(m_pString); }
  31. WString& operator +=(const WString &Other);
  32. WString& operator +=(const wchar_t *);
  33. WString& operator +=(wchar_t);
  34. inline operator const wchar_t *() const { return m_pString; }
  35. inline operator wchar_t *() { return m_pString; }
  36. wchar_t operator[](int nIndex) const;
  37. LPSTR GetLPSTR() const;
  38. inline BOOL Equal(const wchar_t *pTarget) const
  39. { return wcscmp(m_pString, pTarget) == 0; }
  40. inline BOOL EqualNoCase(const wchar_t *pTarget) const
  41. { return wbem_wcsicmp(m_pString, pTarget) == 0; }
  42. inline BOOL operator< (LPCWSTR wszTarget) const
  43. { return wcscmp(m_pString, wszTarget) < 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. LPWSTR UnbindPtr();
  51. inline void BindPtr(LPWSTR ptr) { DeleteString(m_pString); m_pString = ptr; }
  52. void Empty();
  53. WString& StripWs(int nType);
  54. // Strip whitespace, use with a combination
  55. // of leading | trailing
  56. WString& TruncAtRToken(wchar_t Token);
  57. // Truncates the string at the token starting from the
  58. // right end. The token itself is also wiped out.
  59. WString& TruncAtLToken(wchar_t Token);
  60. WString& StripToToken(wchar_t Token, BOOL bIncludeToken);
  61. // Strips leading chars until the token is encountered.
  62. // If bIncludeTok==TRUE, strips the token too.
  63. wchar_t *GetLToken(wchar_t wcToken) const;
  64. // Gets the first occurrence of wcToken in the string or NULL
  65. WString operator()(int, int) const;
  66. // Returns a new WString based on the slice
  67. BOOL ExtractToken(const wchar_t * pDelimiters, WString &Extract);
  68. // Extracts the leading chars up to the token delimiter,
  69. // Removing the token from *this, and assigning the extracted
  70. // part to <Extract>.
  71. BOOL ExtractToken(wchar_t Delimiter, WString &Extract);
  72. // Extracts the leading chars up to the token delimiter,
  73. // Removing the token from *this, and assigning the extracted
  74. // part to <Extract>.
  75. BOOL WildcardTest(const wchar_t *pTestStr) const;
  76. // Tests *this against the wildcard string. If a match,
  77. // returns TRUE, else FALSE.
  78. void Unquote();
  79. // Removes leading/trailing quotes, if any.
  80. // Leaves escaped quotes intact.
  81. WString EscapeQuotes() const;
  82. };
  83. class WSiless
  84. {
  85. public:
  86. inline bool operator()(const WString& ws1, const WString& ws2) const
  87. {return wbem_wcsicmp(ws1, ws2) < 0;}
  88. };
  89. #endif