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.

464 lines
12 KiB

  1. /*++
  2. Copyright (c) 1991 Microsoft Corporation
  3. Module Name:
  4. GENERIC_STRING
  5. Abstract:
  6. This module contains the definition for the GENERIC_STRING class.
  7. Author:
  8. Ramon J. San Andres (ramonsa) 03-May-91
  9. Environment:
  10. ULIB, User Mode
  11. Notes:
  12. A GENERIC_STRING is the base class for all string classes. This
  13. base class provides a basic wide-character interface.
  14. A string is a finite, ordered sequence of wide characters. Note
  15. that a GENERIC_STRING is NOT necessarily null-terminated.
  16. Individual characters within a string are indexed by a number of
  17. type CHNUM (CHaracter NUMber). This index is zero-based.
  18. There are three special symbols that are widely used in the ULIB
  19. strings world:
  20. INVALID_CHAR This symbol represents an invalid wide character.
  21. INVALID_CHNUM This symbol represents an invalid CHNUM index within
  22. a GENERIC_STRING.
  23. TO_END This symbol means "up to the end of the string", and
  24. is used a lot as a default value in those methods
  25. that accept a length argument.
  26. --*/
  27. //
  28. // This class is no longer supported.
  29. //
  30. #include "wstring.hxx"
  31. #define _GENERIC_STRING_
  32. #if !defined (_GENERIC_STRING_)
  33. #define _GENERIC_STRING_
  34. //
  35. // Comparison flags
  36. //
  37. #define COMPARE_IGNORECASE ( 1 )
  38. #define COMPARE_IGNOREDIACRITIC ( 2 )
  39. #define COMPARE_IGNORESYMBOLS ( 4 )
  40. //
  41. // The type of the index used to access individual characters within
  42. // a generic string.
  43. //
  44. DEFINE_TYPE( ULONG, CHNUM );
  45. //
  46. // Magic constants
  47. //
  48. #define INVALID_CHAR ((WCHAR)(-1))
  49. #define INVALID_CHNUM ((CHNUM)(-1))
  50. #define TO_END INVALID_CHNUM
  51. DECLARE_CLASS( GENERIC_STRING );
  52. class GENERIC_STRING : public OBJECT {
  53. public:
  54. DECLARE_CAST_MEMBER_FUNCTION( GENERIC_STRING );
  55. VIRTUAL
  56. ~GENERIC_STRING(
  57. );
  58. VIRTUAL
  59. PBYTE
  60. GetInternalBuffer (
  61. IN CHNUM Position DEFAULT 0
  62. ) CONST PURE;
  63. VIRTUAL
  64. BOOLEAN
  65. IsChAt (
  66. IN WCHAR Char,
  67. IN CHNUM Position DEFAULT 0
  68. ) CONST PURE;
  69. VIRTUAL
  70. BOOLEAN
  71. MakeNumber (
  72. OUT PLONG Number,
  73. IN CHNUM Position DEFAULT 0,
  74. IN CHNUM Length DEFAULT TO_END
  75. ) CONST PURE;
  76. VIRTUAL
  77. ULONG
  78. QueryByteCount (
  79. IN CHNUM Position DEFAULT 0,
  80. IN CHNUM Length DEFAULT TO_END
  81. ) CONST PURE;
  82. VIRTUAL
  83. WCHAR
  84. QueryChAt(
  85. IN CHNUM Position DEFAULT 0
  86. ) CONST PURE;
  87. VIRTUAL
  88. CHNUM
  89. QueryChCount (
  90. ) CONST PURE;
  91. VIRTUAL
  92. PGENERIC_STRING
  93. QueryGenericString (
  94. IN CHNUM Position DEFAULT 0,
  95. IN CHNUM Length DEFAULT TO_END
  96. ) CONST PURE;
  97. VIRTUAL
  98. PSTR
  99. QuerySTR(
  100. IN CHNUM Position DEFAULT 0,
  101. IN CHNUM Length DEFAULT TO_END,
  102. IN OUT PSTR Buffer DEFAULT NULL,
  103. IN ULONG BufferSize DEFAULT 0
  104. ) CONST PURE;
  105. VIRTUAL
  106. PWSTR
  107. QueryWSTR (
  108. IN CHNUM Position DEFAULT 0,
  109. IN CHNUM Length DEFAULT TO_END,
  110. IN OUT PWSTR Buffer DEFAULT NULL,
  111. IN ULONG BufferSize DEFAULT 0,
  112. IN BOOLEAN ForceNull DEFAULT TRUE
  113. ) CONST PURE;
  114. VIRTUAL
  115. BOOLEAN
  116. Replace (
  117. IN PCGENERIC_STRING String2,
  118. IN CHNUM Position DEFAULT 0,
  119. IN CHNUM Length DEFAULT TO_END,
  120. IN CHNUM Position2 DEFAULT 0,
  121. IN CHNUM Length2 DEFAULT TO_END
  122. ) PURE;
  123. VIRTUAL
  124. BOOLEAN
  125. SetChAt (
  126. IN WCHAR Char,
  127. IN CHNUM Position DEFAULT 0,
  128. IN CHNUM Length DEFAULT TO_END
  129. ) PURE;
  130. VIRTUAL
  131. CHNUM
  132. Strchr (
  133. IN WCHAR Char,
  134. IN CHNUM Position DEFAULT 0,
  135. IN CHNUM Length DEFAULT TO_END
  136. ) CONST PURE;
  137. VIRTUAL
  138. LONG
  139. Strcmp (
  140. IN PCGENERIC_STRING GenericString
  141. ) CONST PURE;
  142. VIRTUAL
  143. CHNUM
  144. Strcspn (
  145. IN PCGENERIC_STRING GenericString,
  146. IN CHNUM Position DEFAULT 0,
  147. IN CHNUM Length DEFAULT TO_END
  148. ) CONST PURE;
  149. VIRTUAL
  150. LONG
  151. Stricmp (
  152. IN PCGENERIC_STRING GenericString
  153. ) CONST PURE;
  154. VIRTUAL
  155. LONG
  156. StringCompare (
  157. IN CHNUM Position1,
  158. IN CHNUM Length1 ,
  159. IN PCGENERIC_STRING GenericString2,
  160. IN CHNUM Position2,
  161. IN CHNUM Length2,
  162. IN USHORT CompareFlags DEFAULT COMPARE_IGNORECASE
  163. ) CONST PURE;
  164. VIRTUAL
  165. CHNUM
  166. StrLen (
  167. ) CONST PURE;
  168. VIRTUAL
  169. CHNUM
  170. Strrchr (
  171. IN WCHAR Char,
  172. IN CHNUM Position DEFAULT 0,
  173. IN CHNUM Length DEFAULT TO_END
  174. ) CONST PURE;
  175. VIRTUAL
  176. CHNUM
  177. Strspn (
  178. IN PCGENERIC_STRING GenericString,
  179. IN CHNUM Position DEFAULT 0,
  180. IN CHNUM Length DEFAULT TO_END
  181. ) CONST PURE;
  182. VIRTUAL
  183. CHNUM
  184. Strstr (
  185. IN PCGENERIC_STRING GenericString,
  186. IN CHNUM Position DEFAULT 0,
  187. IN CHNUM Length DEFAULT TO_END
  188. ) CONST PURE;
  189. NONVIRTUAL
  190. BOOLEAN
  191. operator == (
  192. IN RCGENERIC_STRING String
  193. ) CONST;
  194. NONVIRTUAL
  195. BOOLEAN
  196. operator != (
  197. IN RCGENERIC_STRING String
  198. ) CONST;
  199. NONVIRTUAL
  200. BOOLEAN
  201. operator < (
  202. IN RCGENERIC_STRING String
  203. ) CONST;
  204. NONVIRTUAL
  205. BOOLEAN
  206. operator > (
  207. IN RCGENERIC_STRING String
  208. ) CONST;
  209. NONVIRTUAL
  210. BOOLEAN
  211. operator <= (
  212. IN RCGENERIC_STRING String
  213. ) CONST;
  214. NONVIRTUAL
  215. BOOLEAN
  216. operator >= (
  217. IN RCGENERIC_STRING String
  218. ) CONST;
  219. protected:
  220. DECLARE_CONSTRUCTOR( GENERIC_STRING );
  221. NONVIRTUAL
  222. BOOLEAN
  223. Initialize (
  224. );
  225. private:
  226. VOID
  227. Construct (
  228. );
  229. };
  230. INLINE
  231. BOOLEAN
  232. GENERIC_STRING::operator == (
  233. IN RCGENERIC_STRING String
  234. ) CONST
  235. /*++
  236. Routine Description:
  237. Compares this string with another.
  238. Arguments:
  239. String - Supplies a reference to the string to compare.
  240. Return Value:
  241. TRUE - if String is equal to this string
  242. FALSE - if not.
  243. --*/
  244. {
  245. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) == 0);
  246. }
  247. INLINE
  248. BOOLEAN
  249. GENERIC_STRING::operator != (
  250. IN RCGENERIC_STRING String
  251. ) CONST
  252. /*++
  253. Routine Description:
  254. Compares this string with another.
  255. Arguments:
  256. String - Supplies a reference to the string to compare.
  257. Return Value:
  258. TRUE - if String is equal to this string
  259. FALSE - if not.
  260. --*/
  261. {
  262. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) != 0);
  263. }
  264. INLINE
  265. BOOLEAN
  266. GENERIC_STRING::operator < (
  267. IN RCGENERIC_STRING String
  268. ) CONST
  269. /*++
  270. Routine Description:
  271. Compares this string with another.
  272. Arguments:
  273. String - Supplies a reference to the string to compare.
  274. Return Value:
  275. TRUE - if String is less then this string
  276. FALSE - if not.
  277. --*/
  278. {
  279. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) < 0);
  280. }
  281. INLINE
  282. BOOLEAN
  283. GENERIC_STRING::operator > (
  284. IN RCGENERIC_STRING String
  285. ) CONST
  286. /*++
  287. Routine Description:
  288. Compares this string with another.
  289. Arguments:
  290. String - Supplies a reference to the string to compare.
  291. Return Value:
  292. TRUE - if String is greater then this string
  293. FALSE - if not.
  294. --*/
  295. {
  296. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) > 0);
  297. }
  298. INLINE
  299. BOOLEAN
  300. GENERIC_STRING::operator <= (
  301. IN RCGENERIC_STRING String
  302. ) CONST
  303. /*++
  304. Routine Description:
  305. Compares this string with another.
  306. Arguments:
  307. String - Supplies a reference to the string to compare.
  308. Return Value:
  309. TRUE - if String is less then or equal this string
  310. FALSE - if not.
  311. --*/
  312. {
  313. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) <= 0);
  314. }
  315. INLINE
  316. NONVIRTUAL
  317. BOOLEAN
  318. GENERIC_STRING::operator >= (
  319. IN RCGENERIC_STRING String
  320. ) CONST
  321. /*++
  322. Routine Description:
  323. Compares this string with another.
  324. Arguments:
  325. String - Supplies a reference to the string to compare.
  326. Return Value:
  327. TRUE - if String is greater then or equal this string
  328. FALSE - if not.
  329. --*/
  330. {
  331. return (StringCompare( 0, QueryChCount(), (PCGENERIC_STRING)&String, 0, String.QueryChCount(), COMPARE_IGNORECASE ) >= 0);
  332. }
  333. #endif // _GENERIC_STRING_