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.

236 lines
5.0 KiB

  1. //+-------------------------------------------------------------------------
  2. //
  3. // Microsoft Windows
  4. //
  5. // Copyright (c) 1998-1998 Microsoft Corporation
  6. //
  7. // File: str.h
  8. //
  9. //--------------------------------------------------------------------------
  10. //
  11. // string.h
  12. //
  13. #include <objbase.h>
  14. #ifndef __BRSTRING_H__
  15. #define __BRSTRING_H__
  16. class Archive;
  17. class String
  18. {
  19. friend String operator+( const String& str1, const String& str2 );
  20. friend String operator+( const String& str1, LPCSTR lpszStr );
  21. friend String operator+( LPCSTR lpszStr, const String& str1 );
  22. friend String operator+( const String& str1, char ch );
  23. friend String operator+( char ch, const String& str1 );
  24. public:
  25. String();
  26. String( LPCSTR lpszStr );
  27. String( const String& str );
  28. String( LPCWSTR pszWstr );
  29. ~String();
  30. //BOOL LoadString( UINT nID, HINSTANCE hInstance );
  31. BOOL IsEmpty() const
  32. {
  33. return ( m_wLength == 0 );
  34. };
  35. WORD GetLength() const
  36. {
  37. return m_wLength;
  38. };
  39. int Compare( const String& str ) const
  40. {
  41. if (m_pBuf && str.m_pBuf)
  42. {
  43. return _wcsicmp( m_pBuf, str.m_pBuf );
  44. }
  45. else if (!m_pBuf && !str.m_pBuf)
  46. {
  47. return 0;
  48. }
  49. else if (!m_pBuf)
  50. {
  51. return -1;
  52. }
  53. else
  54. {
  55. return 1;
  56. }
  57. };
  58. int Compare( LPCWSTR lpwzStr ) const
  59. {
  60. if (m_pBuf && lpwzStr)
  61. {
  62. return _wcsicmp( m_pBuf, lpwzStr );
  63. }
  64. else if (!m_pBuf && !lpwzStr)
  65. {
  66. return 0;
  67. }
  68. else if (!m_pBuf)
  69. {
  70. return -1;
  71. }
  72. else
  73. {
  74. return 1;
  75. }
  76. };
  77. void Concat( const String& str );
  78. void Concat( LPCWSTR lpwzStr );
  79. void Concat( WCHAR wch );
  80. void TrimTrailingSpaces();
  81. WCHAR GetAt( UINT nIndex ) const
  82. {
  83. if( nIndex >= m_wLength )
  84. {
  85. return L'\0';
  86. }
  87. return m_pBuf[nIndex];
  88. };
  89. void SetAt( UINT nIndex, char ch )
  90. {
  91. if( nIndex < m_wLength )
  92. {
  93. m_pBuf[nIndex] = ch;
  94. }
  95. };
  96. HRESULT ReadWCS( LPSTREAM pStream, DWORD cSize );
  97. //HRESULT WriteWCS( LPSTREAM pStream );
  98. // operators
  99. const String& operator+=( const String& str ) // concatenation
  100. {
  101. Concat( str );
  102. return *this;
  103. };
  104. const String& operator+=( LPCSTR lpszStr ) // concatenation
  105. {
  106. Concat( lpszStr );
  107. return *this;
  108. };
  109. const String& operator+=( char ch ) // concatenation
  110. {
  111. Concat( ch );
  112. return *this;
  113. };
  114. String& operator=( const String& str );
  115. String& operator=( LPCSTR pszStr );
  116. String& operator=( LPCWSTR pszWstr );
  117. operator const WCHAR*() const
  118. {
  119. return m_pBuf;
  120. }
  121. private:
  122. WORD figureblocksize( WORD slen )
  123. {
  124. ++slen; // for '\0'
  125. slen = static_cast<WORD>( slen / sm_wBlockSize );
  126. return static_cast<WORD>( ( slen + 1 ) * sm_wBlockSize );
  127. };
  128. private:
  129. WORD m_wLength;
  130. WORD m_wAllocated;
  131. WCHAR* m_pBuf;
  132. static WORD sm_wBlockSize; // size blocks are allocated in for strings
  133. };
  134. inline BOOL operator==( const String& s1, const String& s2 )
  135. {
  136. return ( s1.Compare( s2 ) == 0 );
  137. }
  138. inline BOOL operator==( const WCHAR* s1, const String& s2 )
  139. {
  140. return ( s2.Compare( s1 ) == 0 );
  141. }
  142. inline BOOL operator==( const String& s1, const WCHAR* s2 )
  143. {
  144. return ( s1.Compare( s2 ) == 0 );
  145. }
  146. inline BOOL operator!=( const String& s1, const String& s2 )
  147. {
  148. return ( s1.Compare( s2 ) != 0 );
  149. }
  150. inline BOOL operator!=( const WCHAR* s1, const String& s2 )
  151. {
  152. return ( s2.Compare( s1 ) != 0 );
  153. }
  154. inline BOOL operator!=( const String& s1, const WCHAR* s2 )
  155. {
  156. return ( s1.Compare( s2 ) != 0 );
  157. }
  158. inline BOOL operator<( const String& s1, const String& s2 )
  159. {
  160. return ( s1.Compare( s2 ) < 0 );
  161. }
  162. inline BOOL operator<( const WCHAR* s1, const String& s2 )
  163. {
  164. return ( s2.Compare( s1 ) > 0 );
  165. }
  166. inline BOOL operator<( const String& s1, const WCHAR* s2 )
  167. {
  168. return ( s1.Compare( s2 ) < 0 );
  169. }
  170. inline BOOL operator>( const String& s1, const String& s2 )
  171. {
  172. return ( s1.Compare( s2 ) > 0 );
  173. }
  174. inline BOOL operator>( const WCHAR* s1, const String& s2 )
  175. {
  176. return ( s2.Compare( s1 ) < 0 );
  177. }
  178. inline BOOL operator>( const String& s1, const WCHAR* s2 )
  179. {
  180. return ( s1.Compare( s2 ) > 0 );
  181. }
  182. inline BOOL operator<=( const String& s1, const String& s2 )
  183. {
  184. return ( s1.Compare( s2 ) <= 0 );
  185. }
  186. inline BOOL operator<=( const WCHAR* s1, const String& s2 )
  187. {
  188. return ( s2.Compare( s1 ) >= 0 );
  189. }
  190. inline BOOL operator<=( const String& s1, const WCHAR* s2 )
  191. {
  192. return ( s1.Compare( s2 ) <= 0 );
  193. }
  194. inline BOOL operator>=( const String& s1, const String& s2 )
  195. {
  196. return ( s1.Compare( s2 ) >= 0 );
  197. }
  198. inline BOOL operator>=( const WCHAR* s1, const String& s2 )
  199. {
  200. return ( s2.Compare( s1 ) <= 0 );
  201. }
  202. inline BOOL operator>=( const String& s1, const WCHAR* s2 )
  203. {
  204. return ( s1.Compare( s2 ) >= 0 );
  205. }
  206. #endif // __BRSTRING_H__