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.

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