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.

607 lines
22 KiB

  1. // This is copied from the Microsoft Foundation Classes C++ library.
  2. // Copyright (C) Microsoft Corporation, 1992 - 1999
  3. // All rights reserved.
  4. //
  5. // This has been modified from the original MFC version to provide
  6. // two classes: CStrW manipulates and stores only wide char strings,
  7. // and CStr uses TCHARs.
  8. //
  9. #ifndef __STR_H__
  10. #define __STR_H__
  11. #include <wchar.h>
  12. #include <tchar.h>
  13. #define STRAPI __stdcall
  14. struct _STR_DOUBLE { BYTE doubleBits[sizeof(double)]; };
  15. BOOL STRAPI IsValidString(LPCSTR lpsz, int nLength);
  16. BOOL STRAPI IsValidString(LPCWSTR lpsz, int nLength);
  17. BOOL STRAPI IsValidAddressz(const void* lp, UINT nBytes, BOOL bReadWrite=TRUE);
  18. int STRAPI StrLoadString(HINSTANCE hInst, UINT nID, LPTSTR lpszBuf);
  19. int STRAPI StrLoadStringW(HINSTANCE hInst, UINT nID, LPWSTR lpszBuf);
  20. class CStr
  21. {
  22. public:
  23. // Constructors
  24. CStr();
  25. CStr(const CStr& stringSrc);
  26. CStr(TCHAR ch, int nRepeat = 1);
  27. CStr(LPCSTR lpsz);
  28. CStr(LPCWSTR lpsz);
  29. CStr(LPCTSTR lpch, int nLength);
  30. CStr(const unsigned char* psz);
  31. // Attributes & Operations
  32. // as an array of characters
  33. int GetLength() const;
  34. BOOL IsEmpty() const;
  35. void Empty(); // free up the data
  36. TCHAR GetAt(int nIndex) const; // 0 based
  37. TCHAR operator[](int nIndex) const; // same as GetAt
  38. void SetAt(int nIndex, TCHAR ch);
  39. operator LPCTSTR() const; // as a C string
  40. // overloaded assignment
  41. const CStr& operator=(const CStr& stringSrc);
  42. const CStr& operator=(TCHAR ch);
  43. #ifdef UNICODE
  44. const CStr& operator=(char ch);
  45. #endif
  46. const CStr& operator=(LPCSTR lpsz);
  47. const CStr& operator=(LPCWSTR lpsz);
  48. const CStr& operator=(const unsigned char* psz);
  49. // string concatenation
  50. const CStr& operator+=(const CStr& string);
  51. const CStr& operator+=(TCHAR ch);
  52. #ifdef UNICODE
  53. const CStr& operator+=(char ch);
  54. #endif
  55. const CStr& operator+=(LPCTSTR lpsz);
  56. friend CStr STRAPI operator+(const CStr& string1,
  57. const CStr& string2);
  58. friend CStr STRAPI operator+(const CStr& string, TCHAR ch);
  59. friend CStr STRAPI operator+(TCHAR ch, const CStr& string);
  60. #ifdef UNICODE
  61. friend CStr STRAPI operator+(const CStr& string, char ch);
  62. friend CStr STRAPI operator+(char ch, const CStr& string);
  63. #endif
  64. friend CStr STRAPI operator+(const CStr& string, LPCTSTR lpsz);
  65. friend CStr STRAPI operator+(LPCTSTR lpsz, const CStr& string);
  66. // string comparison
  67. int Compare(LPCTSTR lpsz) const; // straight character
  68. int CompareNoCase(LPCTSTR lpsz) const; // ignore case
  69. int Collate(LPCTSTR lpsz) const; // NLS aware
  70. // simple sub-string extraction
  71. CStr Mid(int nFirst, int nCount) const;
  72. CStr Mid(int nFirst) const;
  73. CStr Left(int nCount) const;
  74. CStr Right(int nCount) const;
  75. CStr SpanIncluding(LPCTSTR lpszCharSet) const;
  76. CStr SpanExcluding(LPCTSTR lpszCharSet) const;
  77. // upper/lower/reverse conversion
  78. void MakeUpper();
  79. void MakeLower();
  80. void MakeReverse();
  81. // trimming whitespace (either side)
  82. void TrimRight();
  83. void TrimLeft();
  84. // searching (return starting index, or -1 if not found)
  85. // look for a single character match
  86. int Find(TCHAR ch) const; // like "C" strchr
  87. int ReverseFind(TCHAR ch) const;
  88. int FindOneOf(LPCTSTR lpszCharSet) const;
  89. // look for a specific sub-string
  90. int Find(LPCTSTR lpszSub) const; // like "C" strstr
  91. // simple formatting
  92. void Format(LPCTSTR lpszFormat, ...);
  93. // Windows support
  94. BOOL LoadString(HINSTANCE hInst, UINT nID); // load from string resource
  95. // 255 chars max
  96. #ifndef UNICODE
  97. // ANSI <-> OEM support (convert string in place)
  98. void AnsiToOem();
  99. void OemToAnsi();
  100. #endif
  101. BSTR AllocSysString();
  102. BSTR SetSysString(BSTR* pbstr);
  103. // Access to string implementation buffer as "C" character array
  104. LPTSTR GetBuffer(int nMinBufLength);
  105. void ReleaseBuffer(int nNewLength = -1);
  106. LPTSTR GetBufferSetLength(int nNewLength);
  107. void FreeExtra();
  108. // Implementation
  109. public:
  110. ~CStr();
  111. int GetAllocLength() const;
  112. protected:
  113. // lengths/sizes in characters
  114. // (note: an extra character is always allocated)
  115. LPTSTR m_pchData; // actual string (zero terminated)
  116. int m_nDataLength; // does not include terminating 0
  117. int m_nAllocLength; // does not include terminating 0
  118. // implementation helpers
  119. void Init();
  120. void AllocCopy(CStr& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
  121. BOOL AllocBuffer(int nLen);
  122. void AssignCopy(int nSrcLen, LPCTSTR lpszSrcData);
  123. void ConcatCopy(int nSrc1Len, LPCTSTR lpszSrc1Data, int nSrc2Len, LPCTSTR lpszSrc2Data);
  124. void ConcatInPlace(int nSrcLen, LPCTSTR lpszSrcData);
  125. static void SafeDelete(LPTSTR& lpch);
  126. static int SafeStrlen(LPCTSTR lpsz);
  127. };
  128. // Compare helpers
  129. bool STRAPI operator==(const CStr& s1, const CStr& s2);
  130. bool STRAPI operator==(const CStr& s1, LPCTSTR s2);
  131. bool STRAPI operator==(LPCTSTR s1, const CStr& s2);
  132. bool STRAPI operator!=(const CStr& s1, const CStr& s2);
  133. bool STRAPI operator!=(const CStr& s1, LPCTSTR s2);
  134. bool STRAPI operator!=(LPCTSTR s1, const CStr& s2);
  135. bool STRAPI operator<(const CStr& s1, const CStr& s2);
  136. bool STRAPI operator<(const CStr& s1, LPCTSTR s2);
  137. bool STRAPI operator<(LPCTSTR s1, const CStr& s2);
  138. bool STRAPI operator>(const CStr& s1, const CStr& s2);
  139. bool STRAPI operator>(const CStr& s1, LPCTSTR s2);
  140. bool STRAPI operator>(LPCTSTR s1, const CStr& s2);
  141. bool STRAPI operator<=(const CStr& s1, const CStr& s2);
  142. bool STRAPI operator<=(const CStr& s1, LPCTSTR s2);
  143. bool STRAPI operator<=(LPCTSTR s1, const CStr& s2);
  144. bool STRAPI operator>=(const CStr& s1, const CStr& s2);
  145. bool STRAPI operator>=(const CStr& s1, LPCTSTR s2);
  146. bool STRAPI operator>=(LPCTSTR s1, const CStr& s2);
  147. // conversion helpers
  148. int mmc_wcstombsz(char* mbstr, const wchar_t* wcstr, size_t count);
  149. int mmc_mbstowcsz(wchar_t* wcstr, const char* mbstr, size_t count);
  150. // Globals
  151. extern const CStr strEmptyStringT;
  152. extern TCHAR strChNilT;
  153. // Compiler doesn't inline for DBG
  154. /////////////////////////////////////////////////////////////////////////////
  155. // Inline function declarations
  156. inline int CStr::SafeStrlen(LPCTSTR lpsz)
  157. { return (int)((lpsz == NULL) ? NULL : _tcslen(lpsz)); }
  158. inline CStr::CStr(const unsigned char* lpsz)
  159. { Init(); *this = (LPCSTR)lpsz; }
  160. inline const CStr& CStr::operator=(const unsigned char* lpsz)
  161. { *this = (LPCSTR)lpsz; return *this; }
  162. #ifdef _UNICODE
  163. inline const CStr& CStr::operator+=(char ch)
  164. { *this += (TCHAR)ch; return *this; }
  165. inline const CStr& CStr::operator=(char ch)
  166. { *this = (TCHAR)ch; return *this; }
  167. inline CStr STRAPI operator+(const CStr& string, char ch)
  168. { return string + (TCHAR)ch; }
  169. inline CStr STRAPI operator+(char ch, const CStr& string)
  170. { return (TCHAR)ch + string; }
  171. #endif
  172. inline int CStr::GetLength() const
  173. { return m_nDataLength; }
  174. inline int CStr::GetAllocLength() const
  175. { return m_nAllocLength; }
  176. inline BOOL CStr::IsEmpty() const
  177. { return m_nDataLength == 0; }
  178. inline CStr::operator LPCTSTR() const
  179. { return (LPCTSTR)m_pchData; }
  180. // String support (windows specific)
  181. inline int CStr::Compare(LPCTSTR lpsz) const
  182. { return _tcscmp(m_pchData, lpsz); } // MBCS/Unicode aware
  183. inline int CStr::CompareNoCase(LPCTSTR lpsz) const
  184. { return _tcsicmp(m_pchData, lpsz); } // MBCS/Unicode aware
  185. // CStr::Collate is often slower than Compare but is MBSC/Unicode
  186. // aware as well as locale-sensitive with respect to sort order.
  187. inline int CStr::Collate(LPCTSTR lpsz) const
  188. { return _tcscoll(m_pchData, lpsz); } // locale sensitive
  189. inline void CStr::MakeUpper()
  190. { ::CharUpper(m_pchData); }
  191. inline void CStr::MakeLower()
  192. { ::CharLower(m_pchData); }
  193. inline void CStr::MakeReverse()
  194. { _tcsrev(m_pchData); }
  195. inline TCHAR CStr::GetAt(int nIndex) const
  196. {
  197. dspAssert(nIndex >= 0);
  198. dspAssert(nIndex < m_nDataLength);
  199. return m_pchData[nIndex];
  200. }
  201. inline TCHAR CStr::operator[](int nIndex) const
  202. {
  203. // same as GetAt
  204. dspAssert(nIndex >= 0);
  205. dspAssert(nIndex < m_nDataLength);
  206. return m_pchData[nIndex];
  207. }
  208. inline void CStr::SetAt(int nIndex, TCHAR ch)
  209. {
  210. dspAssert(nIndex >= 0);
  211. dspAssert(nIndex < m_nDataLength);
  212. dspAssert(ch != 0);
  213. m_pchData[nIndex] = ch;
  214. }
  215. inline bool STRAPI operator==(const CStr& s1, const CStr& s2)
  216. { return s1.Compare(s2) == 0; }
  217. inline bool STRAPI operator==(const CStr& s1, LPCTSTR s2)
  218. { return s1.Compare(s2) == 0; }
  219. inline bool STRAPI operator==(LPCTSTR s1, const CStr& s2)
  220. { return s2.Compare(s1) == 0; }
  221. inline bool STRAPI operator!=(const CStr& s1, const CStr& s2)
  222. { return s1.Compare(s2) != 0; }
  223. inline bool STRAPI operator!=(const CStr& s1, LPCTSTR s2)
  224. { return s1.Compare(s2) != 0; }
  225. inline bool STRAPI operator!=(LPCTSTR s1, const CStr& s2)
  226. { return s2.Compare(s1) != 0; }
  227. inline bool STRAPI operator<(const CStr& s1, const CStr& s2)
  228. { return s1.Compare(s2) < 0; }
  229. inline bool STRAPI operator<(const CStr& s1, LPCTSTR s2)
  230. { return s1.Compare(s2) < 0; }
  231. inline bool STRAPI operator<(LPCTSTR s1, const CStr& s2)
  232. { return s2.Compare(s1) > 0; }
  233. inline bool STRAPI operator>(const CStr& s1, const CStr& s2)
  234. { return s1.Compare(s2) > 0; }
  235. inline bool STRAPI operator>(const CStr& s1, LPCTSTR s2)
  236. { return s1.Compare(s2) > 0; }
  237. inline bool STRAPI operator>(LPCTSTR s1, const CStr& s2)
  238. { return s2.Compare(s1) < 0; }
  239. inline bool STRAPI operator<=(const CStr& s1, const CStr& s2)
  240. { return s1.Compare(s2) <= 0; }
  241. inline bool STRAPI operator<=(const CStr& s1, LPCTSTR s2)
  242. { return s1.Compare(s2) <= 0; }
  243. inline bool STRAPI operator<=(LPCTSTR s1, const CStr& s2)
  244. { return s2.Compare(s1) >= 0; }
  245. inline bool STRAPI operator>=(const CStr& s1, const CStr& s2)
  246. { return s1.Compare(s2) >= 0; }
  247. inline bool STRAPI operator>=(const CStr& s1, LPCTSTR s2)
  248. { return s1.Compare(s2) >= 0; }
  249. inline bool STRAPI operator>=(LPCTSTR s1, const CStr& s2)
  250. { return s2.Compare(s1) <= 0; }
  251. #ifndef UNICODE
  252. inline void CStr::AnsiToOem()
  253. { ::AnsiToOem(m_pchData, m_pchData); }
  254. inline void CStr::OemToAnsi()
  255. { ::OemToAnsi(m_pchData, m_pchData); }
  256. #endif // UNICODE
  257. // General Exception for memory
  258. class MemoryException
  259. {
  260. public:
  261. MemoryException(){}
  262. void DisplayMessage()
  263. {
  264. ::MessageBox(NULL, _T("Memory Exception"), _T("System Out of Memory"), MB_OK|MB_ICONSTOP);
  265. }
  266. };
  267. // General Exception for memory
  268. class ResourceException
  269. {
  270. public:
  271. ResourceException()
  272. {
  273. ::MessageBox(NULL, _T("Resource Exception"), _T("Unable to Load Resource"), MB_OK|MB_ICONSTOP);
  274. }
  275. };
  276. class CStrW
  277. {
  278. public:
  279. // Constructors
  280. CStrW();
  281. CStrW(const CStrW& stringSrc);
  282. CStrW(WCHAR ch, int nRepeat = 1);
  283. CStrW(LPCSTR lpsz);
  284. CStrW(LPCWSTR lpsz);
  285. CStrW(LPCWSTR lpch, int nLength);
  286. CStrW(const unsigned char* psz);
  287. // Attributes & Operations
  288. // as an array of characters
  289. int GetLength() const;
  290. BOOL IsEmpty() const;
  291. void Empty(); // free up the data
  292. WCHAR GetAt(int nIndex) const; // 0 based
  293. WCHAR operator[](int nIndex) const; // same as GetAt
  294. void SetAt(int nIndex, WCHAR ch);
  295. operator LPCWSTR() const; // as a C string
  296. operator PWSTR(); // as a C string
  297. // overloaded assignment
  298. const CStrW& operator=(const CStrW& stringSrc);
  299. const CStrW& operator=(WCHAR ch);
  300. #ifdef UNICODE
  301. const CStrW& operator=(char ch);
  302. #endif
  303. const CStrW& operator=(LPCSTR lpsz);
  304. const CStrW& operator=(LPCWSTR lpsz);
  305. const CStrW& operator=(const unsigned char* psz);
  306. const CStrW& operator=(UNICODE_STRING unistr);
  307. const CStrW& operator=(UNICODE_STRING * punistr);
  308. // string concatenation
  309. const CStrW& operator+=(const CStrW& string);
  310. const CStrW& operator+=(WCHAR ch);
  311. #ifdef UNICODE
  312. const CStrW& operator+=(char ch);
  313. #endif
  314. const CStrW& operator+=(LPCWSTR lpsz);
  315. friend CStrW STRAPI operator+(const CStrW& string1,
  316. const CStrW& string2);
  317. friend CStrW STRAPI operator+(const CStrW& string, WCHAR ch);
  318. friend CStrW STRAPI operator+(WCHAR ch, const CStrW& string);
  319. #ifdef UNICODE
  320. friend CStrW STRAPI operator+(const CStrW& string, char ch);
  321. friend CStrW STRAPI operator+(char ch, const CStrW& string);
  322. #endif
  323. friend CStrW STRAPI operator+(const CStrW& string, LPCWSTR lpsz);
  324. friend CStrW STRAPI operator+(LPCWSTR lpsz, const CStrW& string);
  325. // string comparison
  326. int Compare(LPCWSTR lpsz) const; // straight character
  327. int CompareNoCase(LPCWSTR lpsz) const; // ignore case
  328. int Collate(LPCWSTR lpsz) const; // NLS aware
  329. // simple sub-string extraction
  330. CStrW Mid(int nFirst, int nCount) const;
  331. CStrW Mid(int nFirst) const;
  332. CStrW Left(int nCount) const;
  333. CStrW Right(int nCount) const;
  334. CStrW SpanIncluding(LPCWSTR lpszCharSet) const;
  335. CStrW SpanExcluding(LPCWSTR lpszCharSet) const;
  336. // upper/lower/reverse conversion
  337. void MakeUpper();
  338. void MakeLower();
  339. void MakeReverse();
  340. // trimming whitespace (either side)
  341. void TrimRight();
  342. void TrimLeft();
  343. // searching (return starting index, or -1 if not found)
  344. // look for a single character match
  345. int Find(WCHAR ch) const; // like "C" strchr
  346. int ReverseFind(WCHAR ch) const;
  347. int FindOneOf(LPCWSTR lpszCharSet) const;
  348. // look for a specific sub-string
  349. int Find(LPCWSTR lpszSub) const; // like "C" strstr
  350. // simple formatting
  351. void Format(LPCWSTR lpszFormat, ...);
  352. // formatting for localization (uses FormatMessage API)
  353. // format using FormatMessage API on passed string
  354. void FormatMessage(PCWSTR pwzFormat, ...);
  355. // format using FormatMessage API on referenced string resource
  356. void FormatMessage(HINSTANCE hInst, UINT nFormatID, ...);
  357. // Windows support
  358. BOOL LoadString(HINSTANCE hInst, UINT nID); // load from string resource
  359. // 255 chars max
  360. BSTR AllocSysString();
  361. BSTR SetSysString(BSTR* pbstr);
  362. // Access to string implementation buffer as "C" character array
  363. PWSTR GetBuffer(int nMinBufLength);
  364. void ReleaseBuffer(int nNewLength = -1);
  365. PWSTR GetBufferSetLength(int nNewLength);
  366. void FreeExtra();
  367. // Implementation
  368. public:
  369. ~CStrW();
  370. int GetAllocLength() const;
  371. protected:
  372. // lengths/sizes in characters
  373. // (note: an extra character is always allocated)
  374. PWSTR m_pchData; // actual string (zero terminated)
  375. int m_nDataLength; // does not include terminating 0
  376. int m_nAllocLength; // does not include terminating 0
  377. // implementation helpers
  378. void Init();
  379. void AllocCopy(CStrW& dest, int nCopyLen, int nCopyIndex, int nExtraLen) const;
  380. BOOL AllocBuffer(int nLen);
  381. void AssignCopy(int nSrcLen, LPCWSTR lpszSrcData);
  382. void ConcatCopy(int nSrc1Len, LPCWSTR lpszSrc1Data, int nSrc2Len, LPCWSTR lpszSrc2Data);
  383. void ConcatInPlace(int nSrcLen, LPCWSTR lpszSrcData);
  384. static void SafeDelete(PWSTR& lpch);
  385. static int SafeStrlen(LPCWSTR lpsz);
  386. };
  387. // Compare helpers
  388. bool STRAPI operator==(const CStrW& s1, const CStrW& s2);
  389. bool STRAPI operator==(const CStrW& s1, LPCWSTR s2);
  390. bool STRAPI operator==(LPCWSTR s1, const CStrW& s2);
  391. bool STRAPI operator!=(const CStrW& s1, const CStrW& s2);
  392. bool STRAPI operator!=(const CStrW& s1, LPCWSTR s2);
  393. bool STRAPI operator!=(LPCWSTR s1, const CStrW& s2);
  394. bool STRAPI operator<(const CStrW& s1, const CStrW& s2);
  395. bool STRAPI operator<(const CStrW& s1, LPCWSTR s2);
  396. bool STRAPI operator<(LPCWSTR s1, const CStrW& s2);
  397. bool STRAPI operator>(const CStrW& s1, const CStrW& s2);
  398. bool STRAPI operator>(const CStrW& s1, LPCWSTR s2);
  399. bool STRAPI operator>(LPCWSTR s1, const CStrW& s2);
  400. bool STRAPI operator<=(const CStrW& s1, const CStrW& s2);
  401. bool STRAPI operator<=(const CStrW& s1, LPCWSTR s2);
  402. bool STRAPI operator<=(LPCWSTR s1, const CStrW& s2);
  403. bool STRAPI operator>=(const CStrW& s1, const CStrW& s2);
  404. bool STRAPI operator>=(const CStrW& s1, LPCWSTR s2);
  405. bool STRAPI operator>=(LPCWSTR s1, const CStrW& s2);
  406. // conversion helpers
  407. int mmc_wcstombsz(char* mbstr, const wchar_t* wcstr, size_t count);
  408. int mmc_mbstowcsz(wchar_t* wcstr, const char* mbstr, size_t count);
  409. // Globals
  410. extern const CStrW strEmptyStringW;
  411. extern WCHAR strChNilW;
  412. // Compiler doesn't inline for DBG
  413. /////////////////////////////////////////////////////////////////////////////
  414. // Inline function declarations
  415. inline int CStrW::SafeStrlen(LPCWSTR lpsz)
  416. { return (int)((lpsz == NULL) ? NULL : wcslen(lpsz)); }
  417. inline CStrW::CStrW(const unsigned char* lpsz)
  418. { Init(); *this = (LPCSTR)lpsz; }
  419. inline const CStrW& CStrW::operator=(const unsigned char* lpsz)
  420. { *this = (LPCSTR)lpsz; return *this; }
  421. #ifdef _UNICODE
  422. inline const CStrW& CStrW::operator+=(char ch)
  423. { *this += (WCHAR)ch; return *this; }
  424. inline const CStrW& CStrW::operator=(char ch)
  425. { *this = (WCHAR)ch; return *this; }
  426. inline CStrW STRAPI operator+(const CStrW& string, char ch)
  427. { return string + (WCHAR)ch; }
  428. inline CStrW STRAPI operator+(char ch, const CStrW& string)
  429. { return (WCHAR)ch + string; }
  430. #endif
  431. inline int CStrW::GetLength() const
  432. { return m_nDataLength; }
  433. inline int CStrW::GetAllocLength() const
  434. { return m_nAllocLength; }
  435. inline BOOL CStrW::IsEmpty() const
  436. { return m_nDataLength == 0; }
  437. inline CStrW::operator LPCWSTR() const
  438. { return (LPCWSTR)m_pchData; }
  439. inline CStrW::operator PWSTR()
  440. { return m_pchData; }
  441. // String support (windows specific)
  442. inline int CStrW::Compare(LPCWSTR lpsz) const
  443. { return wcscmp(m_pchData, lpsz); } // MBCS/Unicode aware
  444. inline int CStrW::CompareNoCase(LPCWSTR lpsz) const
  445. { return _wcsicmp(m_pchData, lpsz); } // MBCS/Unicode aware
  446. // CStrW::Collate is often slower than Compare but is MBSC/Unicode
  447. // aware as well as locale-sensitive with respect to sort order.
  448. inline int CStrW::Collate(LPCWSTR lpsz) const
  449. { return wcscoll(m_pchData, lpsz); } // locale sensitive
  450. inline void CStrW::MakeUpper()
  451. { ::CharUpperW(m_pchData); }
  452. inline void CStrW::MakeLower()
  453. { ::CharLowerW(m_pchData); }
  454. inline void CStrW::MakeReverse()
  455. { wcsrev(m_pchData); }
  456. inline WCHAR CStrW::GetAt(int nIndex) const
  457. {
  458. dspAssert(nIndex >= 0);
  459. dspAssert(nIndex < m_nDataLength);
  460. return m_pchData[nIndex];
  461. }
  462. inline WCHAR CStrW::operator[](int nIndex) const
  463. {
  464. // same as GetAt
  465. dspAssert(nIndex >= 0);
  466. dspAssert(nIndex < m_nDataLength);
  467. return m_pchData[nIndex];
  468. }
  469. inline void CStrW::SetAt(int nIndex, WCHAR ch)
  470. {
  471. dspAssert(nIndex >= 0);
  472. dspAssert(nIndex < m_nDataLength);
  473. dspAssert(ch != 0);
  474. m_pchData[nIndex] = ch;
  475. }
  476. inline bool STRAPI operator==(const CStrW& s1, const CStrW& s2)
  477. { return s1.Compare(s2) == 0; }
  478. inline bool STRAPI operator==(const CStrW& s1, LPCWSTR s2)
  479. { return s1.Compare(s2) == 0; }
  480. inline bool STRAPI operator==(LPCWSTR s1, const CStrW& s2)
  481. { return s2.Compare(s1) == 0; }
  482. inline bool STRAPI operator!=(const CStrW& s1, const CStrW& s2)
  483. { return s1.Compare(s2) != 0; }
  484. inline bool STRAPI operator!=(const CStrW& s1, LPCWSTR s2)
  485. { return s1.Compare(s2) != 0; }
  486. inline bool STRAPI operator!=(LPCWSTR s1, const CStrW& s2)
  487. { return s2.Compare(s1) != 0; }
  488. inline bool STRAPI operator<(const CStrW& s1, const CStrW& s2)
  489. { return s1.Compare(s2) < 0; }
  490. inline bool STRAPI operator<(const CStrW& s1, LPCWSTR s2)
  491. { return s1.Compare(s2) < 0; }
  492. inline bool STRAPI operator<(LPCWSTR s1, const CStrW& s2)
  493. { return s2.Compare(s1) > 0; }
  494. inline bool STRAPI operator>(const CStrW& s1, const CStrW& s2)
  495. { return s1.Compare(s2) > 0; }
  496. inline bool STRAPI operator>(const CStrW& s1, LPCWSTR s2)
  497. { return s1.Compare(s2) > 0; }
  498. inline bool STRAPI operator>(LPCWSTR s1, const CStrW& s2)
  499. { return s2.Compare(s1) < 0; }
  500. inline bool STRAPI operator<=(const CStrW& s1, const CStrW& s2)
  501. { return s1.Compare(s2) <= 0; }
  502. inline bool STRAPI operator<=(const CStrW& s1, LPCWSTR s2)
  503. { return s1.Compare(s2) <= 0; }
  504. inline bool STRAPI operator<=(LPCWSTR s1, const CStrW& s2)
  505. { return s2.Compare(s1) >= 0; }
  506. inline bool STRAPI operator>=(const CStrW& s1, const CStrW& s2)
  507. { return s1.Compare(s2) >= 0; }
  508. inline bool STRAPI operator>=(const CStrW& s1, LPCWSTR s2)
  509. { return s1.Compare(s2) >= 0; }
  510. inline bool STRAPI operator>=(LPCWSTR s1, const CStrW& s2)
  511. { return s2.Compare(s1) <= 0; }
  512. //
  513. // Added by JonN 4/16/98
  514. //
  515. class CStrListItem
  516. {
  517. public:
  518. CStr str;
  519. CStrListItem* pnext;
  520. };
  521. void FreeCStrList( IN OUT CStrListItem** ppList );
  522. void CStrListAdd( IN OUT CStrListItem** ppList, IN LPCTSTR lpsz );
  523. bool CStrListContains( IN CStrListItem** ppList, IN LPCTSTR lpsz );
  524. int CountCStrList( IN CStrListItem** ppList );
  525. #endif // __STR_H__
  526. /////////////////////////////////////////////////////////////////////////////