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.

347 lines
6.3 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. bstring.hxx
  5. Abstract:
  6. This module defines the new BSTRING hierarchy:
  7. BSTRING
  8. BDSTRING
  9. BSTRING provides all of the desired methods on a string.
  10. BDSTRING provides an implementation of a BSTRING with a
  11. dynamic heap based buffer.
  12. BSTRING is an abstract classes who's methods depend on the
  13. implementation of two pure virtual methods: 'Resize' and 'NewBuf'.
  14. A derived class must make use of the protected 'PutString' methods
  15. in order to supply BSTRING with its string buffer. Use of
  16. 'PutString' is constrained as follows:
  17. 1. Supplying just a PSTR to 'PutString' implies that
  18. the PSTR is null-terminated.
  19. 2. Supplying a PSTR and length to 'PutString' implies that
  20. the PSTR points to a buffer of characters that is at
  21. least one longer than the given length.
  22. All implementations of 'Resize' and 'NewBuf' must:
  23. 1. Allocate an extra character for the NULL.
  24. 2. NULL-terminate the buffer allocated.
  25. 3. Always succeed if size <= current buffer size.
  26. 4. Always work as soon as the derived class is initialized (i.e.
  27. BSTRING::Initialize method need not be called.).
  28. 5. Supply the buffer to BSTRING via 'PutString'.
  29. Additionally 'Resize' must:
  30. 1. Preserve the contents of the current buffer.
  31. All of the comparison operators supplied by BSTRING are
  32. case insensitive.
  33. Author:
  34. Norbert P. Kusters (norbertk) 6-Aug-92
  35. --*/
  36. #include "wstring.hxx"
  37. #include "mbstr.hxx"
  38. #if !defined(_BSTRING_DEFN_)
  39. #define _BSTRING_DEFN_
  40. DECLARE_CLASS( BSTRING );
  41. class ULIB_EXPORT BSTRING : public OBJECT {
  42. public:
  43. NONVIRTUAL
  44. BOOLEAN
  45. Initialize(
  46. IN PCSTR InitialString,
  47. IN CHNUM StringLength DEFAULT TO_END
  48. );
  49. NONVIRTUAL
  50. BOOLEAN
  51. Initialize(
  52. );
  53. NONVIRTUAL
  54. CHNUM
  55. QueryChCount(
  56. ) CONST;
  57. NONVIRTUAL
  58. VOID
  59. DeleteChAt(
  60. IN CHNUM Position,
  61. IN CHNUM Length DEFAULT 1
  62. );
  63. NONVIRTUAL
  64. PSTR
  65. QuerySTR(
  66. IN CHNUM Position DEFAULT 0,
  67. IN CHNUM Length DEFAULT TO_END,
  68. OUT PSTR Buffer DEFAULT NULL,
  69. IN CHNUM BufferLength DEFAULT 0,
  70. IN BOOLEAN ForceNull DEFAULT TRUE
  71. ) CONST;
  72. NONVIRTUAL
  73. BOOLEAN
  74. ReplaceWithChars(
  75. IN CHNUM AtPosition,
  76. IN CHNUM AtLength,
  77. IN CHAR Character,
  78. IN CHNUM FromLength
  79. );
  80. NONVIRTUAL
  81. CHNUM
  82. NextChar(
  83. IN CHNUM AtPosition DEFAULT 0
  84. );
  85. NONVIRTUAL
  86. CHNUM
  87. Strchr(
  88. IN CHAR Char,
  89. IN CHNUM StartPosition DEFAULT 0
  90. ) CONST;
  91. VIRTUAL
  92. BOOLEAN
  93. Resize(
  94. IN CHNUM NewStringLength
  95. ) PURE;
  96. VIRTUAL
  97. BOOLEAN
  98. NewBuf(
  99. IN CHNUM NewStringLength
  100. ) PURE;
  101. protected:
  102. DECLARE_CONSTRUCTOR( BSTRING );
  103. NONVIRTUAL
  104. VOID
  105. Construct(
  106. );
  107. NONVIRTUAL
  108. VOID
  109. PutString(
  110. IN OUT PSTR String,
  111. IN CHNUM Length
  112. );
  113. private:
  114. PSTR _s; // Beginning of string.
  115. CHNUM _l; // Strlen of string.
  116. };
  117. INLINE
  118. VOID
  119. BSTRING::PutString(
  120. IN OUT PSTR String,
  121. IN CHNUM Length
  122. )
  123. /*++
  124. Routine Description:
  125. This routine initializes this string with the given buffer
  126. and string length.
  127. Arguments:
  128. String - Supplies the buffer to initialize the string with.
  129. Length - Supplies the length of the string.
  130. Return Value:
  131. None.
  132. --*/
  133. {
  134. _s = String;
  135. _l = Length;
  136. _s[_l] = 0;
  137. }
  138. INLINE
  139. BOOLEAN
  140. BSTRING::Initialize(
  141. )
  142. /*++
  143. Routine Description:
  144. This routine initializes this string to an empty null-terminated
  145. string.
  146. Arguments:
  147. None.
  148. Return Value:
  149. FALSE - Failure.
  150. TRUE - Success.
  151. --*/
  152. {
  153. return Resize(0);
  154. }
  155. INLINE
  156. CHNUM
  157. BSTRING::QueryChCount(
  158. ) CONST
  159. /*++
  160. Routine Description:
  161. This routine returns the number of characters in the string.
  162. Arguments:
  163. None.
  164. Return Value:
  165. The number of characters in this string.
  166. --*/
  167. {
  168. return _l;
  169. }
  170. INLINE
  171. NONVIRTUAL
  172. CHNUM
  173. BSTRING::NextChar(
  174. IN CHNUM AtPosition
  175. )
  176. /*++
  177. Routine Description:
  178. This routine returns the position of the next occurance of
  179. the given position.
  180. Arguments:
  181. AtPosition - Supplies the current position.
  182. Return Value:
  183. The position of the next character.
  184. --*/
  185. {
  186. PSTR p;
  187. DebugAssert(AtPosition <= _l);
  188. p = MBSTR::CharNext(_s + AtPosition);
  189. return (CHNUM)(p - _s);
  190. }
  191. INLINE
  192. CHNUM
  193. BSTRING::Strchr(
  194. IN CHAR Char,
  195. IN CHNUM StartPosition
  196. ) CONST
  197. /*++
  198. Routine Description:
  199. This routine returns the position of the first occurance of
  200. the given character.
  201. Arguments:
  202. Char - Supplies the character to find.
  203. Return Value:
  204. The position of the given character or INVALID_CHNUM.
  205. --*/
  206. {
  207. PSTR p;
  208. DebugAssert(StartPosition <= _l);
  209. p = MBSTR::Strchr(_s + StartPosition, Char);
  210. return p ? (CHNUM)(p - _s) : INVALID_CHNUM;
  211. }
  212. DECLARE_CLASS( BDSTRING );
  213. class ULIB_EXPORT BDSTRING : public BSTRING {
  214. public:
  215. DECLARE_CONSTRUCTOR( BDSTRING );
  216. VIRTUAL
  217. ~BDSTRING(
  218. );
  219. VIRTUAL
  220. BOOLEAN
  221. Resize(
  222. IN CHNUM NewStringLength
  223. );
  224. VIRTUAL
  225. BOOLEAN
  226. NewBuf(
  227. IN CHNUM NewStringLength
  228. );
  229. private:
  230. VOID
  231. Construct(
  232. );
  233. PSTR _buf; // String buffer.
  234. CHNUM _length; // Number of characters in buffer.
  235. };
  236. #endif // _BSTRING_DEFN_