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.

252 lines
7.7 KiB

  1. //
  2. // IISCString.h
  3. //
  4. //////////////////////////////////////////////////////////////////////////////
  5. #if !defined(IISCSTRING_H)
  6. #define IISCSTRING_H
  7. #if _MSC_VER >= 1000
  8. #pragma once
  9. #endif // _MSC_VER >= 1000
  10. //////////////////////////////////////////////////////////////////////////////
  11. #pragma warning(disable:4786) // Disable warning for names > 256
  12. #pragma warning(disable:4275) // Disable warning for non dll-interface class used as a base class
  13. #include <string>
  14. #include <cstring>
  15. #include "common.h"
  16. //////////////////////////////////////////////////////////////////////////////
  17. namespace IIS
  18. {
  19. class _EXPORT CString : public std::basic_string<TCHAR>
  20. {
  21. public:
  22. // Constructors
  23. CString();
  24. CString(const CString& strInput);
  25. CString(const std::basic_string<TCHAR>& strInput);
  26. CString(TCHAR ch, int nRepeat = 1);
  27. #ifdef _UNICODE
  28. CString(LPCSTR lpsz);
  29. #endif
  30. #ifndef _UNICODE
  31. CString(LPCWSTR lpsz);
  32. #endif
  33. CString(LPCTSTR p);
  34. CString(LPCTSTR lpch, int nLength);
  35. CString(const unsigned char * psz);
  36. CString(const CComBSTR& bstr);
  37. ~CString();
  38. int GetLength() const;
  39. bool IsEmpty() const;
  40. void Empty();
  41. TCHAR GetAt(int nIndex) const;
  42. TCHAR operator[](int nIndex) const;
  43. void SetAt(int nIndex, TCHAR ch);
  44. operator LPCTSTR() const; // as a C string
  45. const CString& operator=(const CString& stringSrc);
  46. const CString& operator=(TCHAR ch);
  47. const CString& operator=(LPCTSTR p);
  48. #ifdef _UNICODE
  49. const CString& operator=(char ch);
  50. const CString& operator=(LPCSTR lpsz);
  51. const CString& operator=(const unsigned char* psz);
  52. #endif
  53. #ifndef _UNICODE
  54. const CString& operator=(WCHAR ch);
  55. const CString& operator=(LPCWSTR lpsz);
  56. #endif
  57. // string concatenation
  58. const CString& operator+=(const CString& string);
  59. const CString& operator+=(TCHAR ch);
  60. #ifdef _UNICODE
  61. const CString& operator+=(char ch);
  62. #endif
  63. const CString& operator+=(LPCTSTR lpsz);
  64. friend CString __stdcall operator+(const CString& string1, const CString& string2);
  65. friend CString __stdcall operator+(const CString& string, TCHAR ch);
  66. friend CString __stdcall operator+(TCHAR ch, const CString& string);
  67. #ifdef _UNICODE
  68. friend CString __stdcall operator+(const CString& string, char ch);
  69. friend CString __stdcall operator+(char ch, const CString& string);
  70. #endif
  71. friend CString __stdcall operator+(const CString& string, LPCTSTR lpsz);
  72. friend CString __stdcall operator+(LPCTSTR lpsz, const CString& string);
  73. int Compare(LPCTSTR lpsz) const; // straight character
  74. int CompareNoCase(LPCTSTR lpsz) const; // ignore case
  75. int Collate(LPCTSTR lpsz) const; // NLS aware
  76. // simple sub-string extraction
  77. CString Mid(int nFirst, int nCount) const;
  78. CString Mid(int nFirst) const;
  79. CString Left(int nCount) const;
  80. CString Right(int nCount) const;
  81. CString SpanIncluding(LPCTSTR lpszCharSet) const;
  82. CString SpanExcluding(LPCTSTR lpszCharSet) const;
  83. // upper/lower/reverse conversion
  84. void MakeUpper();
  85. void MakeLower();
  86. void MakeReverse();
  87. // trimming whitespace (either side)
  88. void TrimRight();
  89. void TrimLeft();
  90. // advanced manipulation
  91. // replace occurrences of chOld with chNew
  92. int Replace(TCHAR chOld, TCHAR chNew);
  93. // replace occurrences of substring lpszOld with lpszNew;
  94. // empty lpszNew removes instances of lpszOld
  95. int Replace(LPCTSTR lpszOld, LPCTSTR lpszNew);
  96. // remove occurrences of chRemove
  97. int Remove(TCHAR chRemove);
  98. // insert character at zero-based index; concatenates
  99. // if index is past end of string
  100. int Insert(int nIndex, TCHAR ch);
  101. // insert substring at zero-based index; concatenates
  102. // if index is past end of string
  103. int Insert(int nIndex, LPCTSTR pstr);
  104. // delete nCount characters starting at zero-based index
  105. int Delete(int nIndex, int nCount = 1);
  106. // searching (return starting index, or -1 if not found)
  107. // look for a single character match
  108. int Find(TCHAR ch) const; // like "C" strchr
  109. int ReverseFind(TCHAR ch) const;
  110. int FindOneOf(LPCTSTR lpszCharSet) const;
  111. // look for a specific sub-string
  112. int Find(LPCTSTR lpszSub) const; // like "C" strstr
  113. // Concatentation for non strings
  114. // const CString& Append(int n)
  115. // {
  116. // TCHAR szBuffer[10];
  117. // wsprintf(szBuffer,_T("%d"),n);
  118. // ConcatInPlace(SafeStrlen(szBuffer), szBuffer);
  119. // return *this;
  120. // }
  121. // simple formatting
  122. void __cdecl FormatV(LPCTSTR lpszFormat, va_list argList);
  123. void __cdecl Format(LPCTSTR lpszFormat, ...);
  124. void __cdecl Format(HINSTANCE hInst, UINT nFormatID, ...);
  125. // formatting for localization (uses FormatMessage API)
  126. BOOL __cdecl FormatMessage(LPCTSTR lpszFormat, ...);
  127. BOOL __cdecl FormatMessage(HINSTANCE hInst, UINT nFormatID, ...);
  128. // Windows support
  129. BOOL LoadString(HINSTANCE hInstance, UINT nID);
  130. #ifndef _UNICODE
  131. // ANSI <-> OEM support (convert string in place)
  132. void AnsiToOem();
  133. void OemToAnsi();
  134. #endif
  135. #ifndef _ATL_NO_COM
  136. // OLE BSTR support (use for OLE automation)
  137. BSTR AllocSysString() const;
  138. BSTR SetSysString(BSTR* pbstr) const;
  139. #endif //!_ATL_NO_COM
  140. };
  141. //////////////////////////////////////////////////////////////////////////////
  142. inline bool operator==(const CString& s1, const CString& s2)
  143. { return s1.compare(s2) == 0; }
  144. inline bool operator==(const CString& s1, const TCHAR * s2)
  145. { return s1.compare(s2) == 0; }
  146. inline bool operator==(const TCHAR * s1, const CString& s2)
  147. { return s2.compare(s1) == 0; }
  148. inline bool operator!=(const CString& s1, const CString& s2)
  149. { return s1.compare(s2) != 0; }
  150. inline bool operator!=(const CString& s1, const TCHAR * s2)
  151. { return s1.compare(s2) != 0; }
  152. inline bool operator!=(const TCHAR * s1, const CString& s2)
  153. { return s2.compare(s1) != 0; }
  154. inline bool operator<(const CString& s1, const CString& s2)
  155. { return s1.compare(s2) < 0; }
  156. inline bool operator<(const CString& s1, const TCHAR * s2)
  157. { return s1.compare(s2) < 0; }
  158. inline bool operator<(const TCHAR * s1, const CString& s2)
  159. { return s2.compare(s1) > 0; }
  160. inline bool operator>(const CString& s1, const CString& s2)
  161. { return s1.compare(s2) > 0; }
  162. inline bool operator>(const CString& s1, const TCHAR * s2)
  163. { return s1.compare(s2) > 0; }
  164. inline bool operator>(const TCHAR * s1, const CString& s2)
  165. { return s2.compare(s1) < 0; }
  166. inline bool operator<=(const CString& s1, const CString& s2)
  167. { return s1.compare(s2) <= 0; }
  168. inline bool operator<=(const CString& s1, const TCHAR * s2)
  169. { return s1.compare(s2) <= 0; }
  170. inline bool operator<=(const TCHAR * s1, const CString& s2)
  171. { return s2.compare(s1) >= 0; }
  172. inline bool operator>=(const CString& s1, const CString& s2)
  173. { return s1.compare(s2) >= 0; }
  174. inline bool operator>=(const CString& s1, const TCHAR * s2)
  175. { return s1.compare(s2) >= 0; }
  176. inline bool operator>=(const TCHAR * s1, const CString& s2)
  177. { return s2.compare(s1) <= 0; }
  178. inline CString __stdcall operator+(const CString& string1, const CString& string2)
  179. {
  180. CString s = string1;
  181. s += string2;
  182. return s;
  183. }
  184. inline CString __stdcall operator+(const CString& string, LPCTSTR lpsz)
  185. {
  186. ATLASSERT(lpsz == NULL);
  187. CString s = string;
  188. s += lpsz;
  189. return s;
  190. }
  191. inline CString __stdcall operator+(LPCTSTR lpsz, const CString& string)
  192. {
  193. ATLASSERT(lpsz == NULL);
  194. CString s = lpsz;;
  195. s += string;
  196. return s;
  197. }
  198. inline CString __stdcall operator+(const CString& string, TCHAR c)
  199. {
  200. CString s = string;
  201. s += c;
  202. return s;
  203. }
  204. inline CString __stdcall operator+(TCHAR c, const CString& string)
  205. {
  206. CString s;
  207. s += c;
  208. s += string;
  209. return s;
  210. }
  211. }; // namespace IIS
  212. #pragma warning(default:4786) // Enable warning for names > 256
  213. #pragma warning(default:4275)
  214. #endif // !defined(IISCSTRING_H)