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.

1241 lines
23 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. wstring.hxx
  5. Abstract:
  6. This module defines the new WSTRING hierarchy:
  7. WSTRING
  8. FSTRING
  9. DSTRING
  10. WSTRING provides all of the desired methods on a string.
  11. FSTRING provides an implementation of a WSTRING with fixed
  12. size, user provided buffer.
  13. DSTRING provides an implementation of a WSTRING with a
  14. dynamic heap based buffer.
  15. WSTRING is an abstract classes who's methods depend on the
  16. implementation of two pure virtual methods: 'Resize' and 'NewBuf'.
  17. A derived class must make use of the protected 'PutString' methods
  18. in order to supply WSTRING with its string buffer. Use of
  19. 'PutString' is constrained as follows:
  20. 1. Supplying just a PWSTR to 'PutString' implies that
  21. the PWSTR is null-terminated.
  22. 2. Supplying a PWSTR and length to 'PutString' implies that
  23. the PWSTR points to a buffer of characters that is at
  24. least one longer than the given length.
  25. All implementations of 'Resize' and 'NewBuf' must:
  26. 1. Allocate an extra character for the NULL.
  27. 2. NULL-terminate the buffer allocated.
  28. 3. Always succeed if size <= current buffer size.
  29. 4. Always work as soon as the derived class is initialized (i.e.
  30. WSTRING::Initialize method need not be called.).
  31. 5. Supply the buffer to WSTRING via 'PutString'.
  32. Additionally 'Resize' must:
  33. 1. Preserve the contents of the current buffer.
  34. All of the comparison operators supplied by WSTRING are
  35. case insensitive.
  36. Author:
  37. Norbert P. Kusters (norbertk) 6-Aug-92
  38. --*/
  39. #if !defined(_WSTRING_DEFN_)
  40. #define _WSTRING_DEFN_
  41. //
  42. // The type of the index used to access individual characters within
  43. // a generic string.
  44. //
  45. DEFINE_TYPE( ULONG, CHNUM );
  46. //
  47. // Magic constants
  48. //
  49. #define INVALID_CHAR ((WCHAR)-1)
  50. #define INVALID_CHNUM ((CHNUM)-1)
  51. #define TO_END INVALID_CHNUM
  52. //
  53. // Prefixes used in various names.
  54. // (This should really be in path.hxx.)
  55. //
  56. #define GUID_VOLNAME_PREFIX L"Volume{"
  57. #define DOS_GUIDNAME_PREFIX L"\\\\?\\"
  58. #define NT_NAME_PREFIX L"\\??\\"
  59. DECLARE_CLASS( WSTRING );
  60. class ULIB_EXPORT WSTRING : public OBJECT {
  61. public:
  62. NONVIRTUAL
  63. BOOLEAN
  64. Initialize(
  65. IN PCWSTRING InitialString,
  66. IN CHNUM Position DEFAULT 0,
  67. IN CHNUM Length DEFAULT TO_END
  68. );
  69. NONVIRTUAL
  70. BOOLEAN
  71. Initialize(
  72. IN PCWSTR InitialString,
  73. IN CHNUM StringLength DEFAULT TO_END
  74. );
  75. NONVIRTUAL
  76. BOOLEAN
  77. Initialize(
  78. IN PCSTR InitialString,
  79. IN CHNUM StringLength DEFAULT TO_END
  80. );
  81. NONVIRTUAL
  82. BOOLEAN
  83. Initialize(
  84. );
  85. NONVIRTUAL
  86. BOOLEAN
  87. Initialize(
  88. IN LONG Number
  89. );
  90. NONVIRTUAL
  91. PWSTRING
  92. QueryString(
  93. IN CHNUM Position DEFAULT 0,
  94. IN CHNUM Length DEFAULT TO_END
  95. ) CONST;
  96. NONVIRTUAL
  97. BOOLEAN
  98. QueryNumber(
  99. OUT PLONG Number,
  100. IN CHNUM Position DEFAULT 0,
  101. IN CHNUM Length DEFAULT TO_END
  102. ) CONST;
  103. NONVIRTUAL
  104. CHNUM
  105. QueryChCount(
  106. ) CONST;
  107. #ifdef FE_SB
  108. NONVIRTUAL
  109. CHNUM
  110. QueryByteCount(
  111. ) CONST;
  112. #endif
  113. NONVIRTUAL
  114. CHNUM
  115. SyncLength(
  116. );
  117. NONVIRTUAL
  118. WCHAR
  119. QueryChAt(
  120. IN CHNUM Position
  121. ) CONST;
  122. NONVIRTUAL
  123. WCHAR
  124. SetChAt(
  125. IN WCHAR Char,
  126. IN CHNUM Position
  127. );
  128. NONVIRTUAL
  129. VOID
  130. DeleteChAt(
  131. IN CHNUM Position,
  132. IN CHNUM Length DEFAULT 1
  133. );
  134. NONVIRTUAL
  135. BOOLEAN
  136. InsertString(
  137. IN CHNUM AtPosition,
  138. IN PCWSTRING String,
  139. IN CHNUM FromPosition DEFAULT 0,
  140. IN CHNUM FromLength DEFAULT TO_END
  141. );
  142. NONVIRTUAL
  143. BOOLEAN
  144. Replace(
  145. IN CHNUM AtPosition,
  146. IN CHNUM AtLength,
  147. IN PCWSTRING String,
  148. IN CHNUM FromPosition DEFAULT 0,
  149. IN CHNUM FromLength DEFAULT TO_END
  150. );
  151. NONVIRTUAL
  152. BOOLEAN
  153. ReplaceWithChars(
  154. IN CHNUM AtPosition,
  155. IN CHNUM AtLength,
  156. IN WCHAR Character,
  157. IN CHNUM FromLength
  158. );
  159. NONVIRTUAL
  160. PCWSTR
  161. GetWSTR(
  162. ) CONST;
  163. NONVIRTUAL
  164. PWSTR
  165. QueryWSTR(
  166. IN CHNUM Position DEFAULT 0,
  167. IN CHNUM Length DEFAULT TO_END,
  168. OUT PWSTR Buffer DEFAULT NULL,
  169. IN CHNUM BufferLength DEFAULT 0,
  170. IN BOOLEAN ForceNull DEFAULT TRUE
  171. ) CONST;
  172. NONVIRTUAL
  173. PSTR
  174. QuerySTR(
  175. IN CHNUM Position DEFAULT 0,
  176. IN CHNUM Length DEFAULT TO_END,
  177. OUT PSTR Buffer DEFAULT NULL,
  178. IN CHNUM BufferLength DEFAULT 0,
  179. IN BOOLEAN ForceNull DEFAULT TRUE
  180. ) CONST;
  181. NONVIRTUAL
  182. LONG
  183. Strcmp(
  184. IN PCWSTRING String
  185. ) CONST;
  186. STATIC
  187. INT
  188. Strcmp(
  189. IN PWSTR String1,
  190. IN PWSTR String2
  191. ) ;
  192. STATIC
  193. INT
  194. Stricmp(
  195. IN PWSTR String1,
  196. IN PWSTR String2
  197. ) ;
  198. NONVIRTUAL
  199. LONG
  200. Strcmp(
  201. IN PCWSTRING String,
  202. IN CHNUM LeftPosition
  203. ) CONST;
  204. NONVIRTUAL
  205. LONG
  206. Strcmp(
  207. IN PCWSTRING String,
  208. IN CHNUM LeftPosition,
  209. IN CHNUM LeftLength,
  210. IN CHNUM RightPosition DEFAULT 0,
  211. IN CHNUM RightLength DEFAULT TO_END
  212. ) CONST;
  213. NONVIRTUAL
  214. LONG
  215. Stricmp(
  216. IN PCWSTRING String
  217. ) CONST;
  218. NONVIRTUAL
  219. LONG
  220. Stricmp(
  221. IN PCWSTRING String,
  222. IN CHNUM LeftPosition
  223. ) CONST;
  224. NONVIRTUAL
  225. LONG
  226. Stricmp(
  227. IN PCWSTRING String,
  228. IN CHNUM LeftPosition,
  229. IN CHNUM LeftLength,
  230. IN CHNUM RightPosition DEFAULT 0,
  231. IN CHNUM RightLength DEFAULT TO_END
  232. ) CONST;
  233. STATIC
  234. INT
  235. Strcmps(
  236. IN PWSTR p1,
  237. IN PWSTR p2
  238. );
  239. STATIC
  240. INT
  241. Strcmpis(
  242. IN PWSTR p1,
  243. IN PWSTR p2
  244. );
  245. STATIC
  246. PWSTR
  247. SkipWhite(
  248. IN PWSTR p
  249. );
  250. NONVIRTUAL
  251. BOOLEAN
  252. Strcat(
  253. IN PCWSTRING String
  254. );
  255. NONVIRTUAL
  256. PWSTRING
  257. Strupr(
  258. );
  259. NONVIRTUAL
  260. PWSTRING
  261. Strupr(
  262. IN CHNUM StartPosition,
  263. IN CHNUM Length DEFAULT TO_END
  264. );
  265. NONVIRTUAL
  266. PWSTRING
  267. Strlwr(
  268. );
  269. NONVIRTUAL
  270. PWSTRING
  271. Strlwr(
  272. IN CHNUM StartPosition,
  273. IN CHNUM Length DEFAULT TO_END
  274. );
  275. NONVIRTUAL
  276. CHNUM
  277. Strchr(
  278. IN WCHAR Char,
  279. IN CHNUM StartPosition DEFAULT 0
  280. ) CONST;
  281. NONVIRTUAL
  282. CHNUM
  283. Strrchr(
  284. IN WCHAR Char,
  285. IN CHNUM StartPosition DEFAULT 0
  286. ) CONST;
  287. NONVIRTUAL
  288. CHNUM
  289. Strstr(
  290. IN PCWSTRING String
  291. ) CONST;
  292. NONVIRTUAL
  293. CHNUM
  294. Strspn(
  295. IN PCWSTRING String,
  296. IN CHNUM StartPosition DEFAULT 0
  297. ) CONST;
  298. NONVIRTUAL
  299. CHNUM
  300. Strcspn(
  301. IN PCWSTRING String,
  302. IN CHNUM StartPosition DEFAULT 0
  303. ) CONST;
  304. NONVIRTUAL
  305. BOOLEAN
  306. operator==(
  307. IN RCWSTRING String
  308. ) CONST;
  309. NONVIRTUAL
  310. BOOLEAN
  311. operator!=(
  312. IN RCWSTRING String
  313. ) CONST;
  314. NONVIRTUAL
  315. BOOLEAN
  316. operator<(
  317. IN RCWSTRING String
  318. ) CONST;
  319. NONVIRTUAL
  320. BOOLEAN
  321. operator>(
  322. IN RCWSTRING String
  323. ) CONST;
  324. NONVIRTUAL
  325. BOOLEAN
  326. operator<=(
  327. IN RCWSTRING String
  328. ) CONST;
  329. NONVIRTUAL
  330. BOOLEAN
  331. operator>=(
  332. IN RCWSTRING String
  333. ) CONST;
  334. VIRTUAL
  335. BOOLEAN
  336. Resize(
  337. IN CHNUM NewStringLength
  338. ) PURE;
  339. VIRTUAL
  340. BOOLEAN
  341. NewBuf(
  342. IN CHNUM NewStringLength
  343. ) PURE;
  344. NONVIRTUAL
  345. CHNUM
  346. Truncate(
  347. IN CHNUM Position DEFAULT 0
  348. );
  349. STATIC
  350. VOID
  351. SetAnsiConversions(
  352. );
  353. STATIC
  354. VOID
  355. SetOemConversions(
  356. );
  357. STATIC
  358. VOID
  359. SetConsoleConversions(
  360. );
  361. #if defined FE_SB
  362. STATIC
  363. VOID
  364. ResetConversions(
  365. );
  366. #endif
  367. protected:
  368. DECLARE_CONSTRUCTOR( WSTRING );
  369. NONVIRTUAL
  370. VOID
  371. Construct(
  372. );
  373. NONVIRTUAL
  374. VOID
  375. PutString(
  376. IN OUT PWSTR String
  377. );
  378. NONVIRTUAL
  379. VOID
  380. PutString(
  381. IN OUT PWSTR String,
  382. IN CHNUM Length
  383. );
  384. private:
  385. STATIC BOOLEAN _UseAnsiConversions;
  386. STATIC BOOLEAN _UseConsoleConversions;
  387. #if defined FE_SB
  388. STATIC BOOLEAN _UseAnsiConversionsPrev;
  389. STATIC BOOLEAN _UseConsoleConversionsPrev;
  390. #endif
  391. #if defined FE_SB
  392. STATIC
  393. INT
  394. CheckSpace(
  395. IN PWSTR p
  396. );
  397. #endif
  398. STATIC
  399. BOOLEAN
  400. ConvertOemToUnicodeN(
  401. PWSTR UnicodeString,
  402. ULONG MaxBytesInUnicodeString,
  403. PULONG BytesInUnicodeString,
  404. PCHAR OemString,
  405. ULONG BytesInOemString
  406. );
  407. STATIC
  408. BOOLEAN
  409. ConvertUnicodeToOemN(
  410. PCHAR OemString,
  411. ULONG MaxBytesInOemString,
  412. PULONG BytesInOemString,
  413. PWSTR UnicodeString,
  414. ULONG BytesInUnicodeString
  415. );
  416. PWSTR _s; // Beginning of string.
  417. CHNUM _l; // Strlen of string.
  418. };
  419. INLINE
  420. VOID
  421. WSTRING::PutString(
  422. IN OUT PWSTR String
  423. )
  424. /*++
  425. Routine Description:
  426. This routine initializes this string with the given null
  427. terminated buffer.
  428. Arguments:
  429. String - Supplies the buffer to initialize the string with.
  430. Return Value:
  431. None.
  432. --*/
  433. {
  434. _s = String;
  435. _l = wcslen(_s);
  436. }
  437. INLINE
  438. VOID
  439. WSTRING::PutString(
  440. IN OUT PWSTR String,
  441. IN CHNUM Length
  442. )
  443. /*++
  444. Routine Description:
  445. This routine initializes this string with the given buffer
  446. and string length.
  447. Arguments:
  448. String - Supplies the buffer to initialize the string with.
  449. Length - Supplies the length of the string.
  450. Return Value:
  451. None.
  452. --*/
  453. {
  454. _s = String;
  455. _l = Length;
  456. _s[_l] = 0;
  457. }
  458. INLINE
  459. BOOLEAN
  460. WSTRING::Initialize(
  461. )
  462. /*++
  463. Routine Description:
  464. This routine initializes this string to an empty null-terminated
  465. string.
  466. Arguments:
  467. None.
  468. Return Value:
  469. FALSE - Failure.
  470. TRUE - Success.
  471. --*/
  472. {
  473. return Resize(0);
  474. }
  475. INLINE
  476. CHNUM
  477. WSTRING::QueryChCount(
  478. ) CONST
  479. /*++
  480. Routine Description:
  481. This routine returns the number of characters in the string.
  482. Arguments:
  483. None.
  484. Return Value:
  485. The number of characters in this string.
  486. --*/
  487. {
  488. return _l;
  489. }
  490. INLINE
  491. CHNUM
  492. WSTRING::SyncLength(
  493. )
  494. /*++
  495. Routine Description:
  496. This routine recalculates the correct length of the string.
  497. Arguments:
  498. None.
  499. Return Value:
  500. The recomputed length of the string.
  501. --*/
  502. {
  503. return _l = wcslen(_s);
  504. }
  505. INLINE
  506. WCHAR
  507. WSTRING::QueryChAt(
  508. IN CHNUM Position
  509. ) CONST
  510. /*++
  511. Routine Description:
  512. This routine returns the character at the given position.
  513. The position is a zero-based index into the string.
  514. The position must be in the range of the string.
  515. Arguments:
  516. Position - Supplies an index into the string.
  517. Return Value:
  518. The character at the given position.
  519. --*/
  520. {
  521. return (Position < _l) ? _s[Position] : INVALID_CHAR;
  522. }
  523. INLINE
  524. WCHAR
  525. WSTRING::SetChAt(
  526. IN WCHAR Char,
  527. IN CHNUM Position
  528. )
  529. /*++
  530. Routine Description:
  531. This routine sets the given character at the given position in
  532. the string.
  533. Arguments:
  534. Char - Supplies the character to set into the string.
  535. Position - Supplies the position at which to set the character.
  536. Return Value:
  537. The character that was set.
  538. --*/
  539. {
  540. DebugAssert(Position < _l);
  541. return _s[Position] = Char;
  542. }
  543. INLINE
  544. PCWSTR
  545. WSTRING::GetWSTR(
  546. ) CONST
  547. /*++
  548. Routine Description:
  549. This routine returns this string internal buffer.
  550. Arguments:
  551. None.
  552. Return Value:
  553. A pointer to the strings buffer.
  554. --*/
  555. {
  556. return _s;
  557. }
  558. INLINE
  559. LONG
  560. WSTRING::Strcmp(
  561. IN PCWSTRING String
  562. ) CONST
  563. /*++
  564. Routine Description:
  565. This routine compares two strings.
  566. Arguments:
  567. String - Supplies the string to compare to.
  568. Return Value:
  569. < 0 - This string is less than the given string.
  570. 0 - This string is equal to the given string.
  571. > 0 - This string is greater than the given string.
  572. --*/
  573. {
  574. return wcscmp(_s, String->_s);
  575. }
  576. INLINE
  577. INT
  578. WSTRING::Strcmp(
  579. IN PWSTR String1,
  580. IN PWSTR String2
  581. )
  582. {
  583. return wcscmp( String1, String2 );
  584. }
  585. INLINE
  586. INT
  587. WSTRING::Stricmp(
  588. IN PWSTR String1,
  589. IN PWSTR String2
  590. )
  591. {
  592. return _wcsicmp( String1, String2 );
  593. }
  594. INLINE
  595. LONG
  596. WSTRING::Strcmp(
  597. IN PCWSTRING String,
  598. IN CHNUM LeftPosition
  599. ) CONST
  600. /*++
  601. Routine Description:
  602. This routine compares two strings. It starts comparing the
  603. current string at the given position.
  604. Arguments:
  605. String - Supplies the string to compare to.
  606. LeftPosition - Supplies the starting position to start comparison
  607. on the current string.
  608. Return Value:
  609. < 0 - This string is less than the given string.
  610. 0 - This string is equal to the given string.
  611. > 0 - This string is greater than the given string.
  612. --*/
  613. {
  614. return wcscmp(_s + LeftPosition, String->_s);
  615. }
  616. INLINE
  617. LONG
  618. WSTRING::Stricmp(
  619. IN PCWSTRING String
  620. ) CONST
  621. /*++
  622. Routine Description:
  623. This routine compares two strings insensitive of case.
  624. Arguments:
  625. String - Supplies the string to compare to.
  626. Return Value:
  627. < 0 - This string is less than the given string.
  628. 0 - This string is equal to the given string.
  629. > 0 - This string is greater than the given string.
  630. --*/
  631. {
  632. return _wcsicmp(_s, String->_s);
  633. }
  634. INLINE
  635. LONG
  636. WSTRING::Stricmp(
  637. IN PCWSTRING String,
  638. IN CHNUM LeftPosition
  639. ) CONST
  640. /*++
  641. Routine Description:
  642. This routine compares two strings insensitive of case.
  643. Arguments:
  644. String - Supplies the string to compare to.
  645. LeftPosition - Supplies the position in this string to start
  646. comparison.
  647. Return Value:
  648. < 0 - This string is less than the given string.
  649. 0 - This string is equal to the given string.
  650. > 0 - This string is greater than the given string.
  651. --*/
  652. {
  653. return _wcsicmp(_s + LeftPosition, String->_s);
  654. }
  655. INLINE
  656. PWSTRING
  657. WSTRING::Strupr(
  658. )
  659. /*++
  660. Routine Description:
  661. This routine uppercases this string.
  662. Arguments:
  663. None.
  664. Return Value:
  665. None.
  666. --*/
  667. {
  668. _wcsupr(_s);
  669. return this;
  670. }
  671. INLINE
  672. PWSTRING
  673. WSTRING::Strlwr(
  674. )
  675. /*++
  676. Routine Description:
  677. This routine lowercases this string.
  678. Arguments:
  679. None.
  680. Return Value:
  681. None.
  682. --*/
  683. {
  684. _wcslwr(_s);
  685. return this;
  686. }
  687. INLINE
  688. CHNUM
  689. WSTRING::Strchr(
  690. IN WCHAR Char,
  691. IN CHNUM StartPosition
  692. ) CONST
  693. /*++
  694. Routine Description:
  695. This routine returns the position of the first occurance of
  696. the given character.
  697. Arguments:
  698. Char - Supplies the character to find.
  699. Return Value:
  700. The position of the given character or INVALID_CHNUM.
  701. --*/
  702. {
  703. PWSTR p;
  704. DebugAssert(StartPosition <= _l);
  705. p = wcschr(_s + StartPosition, Char);
  706. return p ? (CHNUM)(p - _s) : INVALID_CHNUM;
  707. }
  708. INLINE
  709. CHNUM
  710. WSTRING::Strrchr(
  711. IN WCHAR Char,
  712. IN CHNUM StartPosition
  713. ) CONST
  714. /*++
  715. Routine Description:
  716. This routine returns the position of the last occurance of
  717. the given character.
  718. Arguments:
  719. Char - Supplies the character to find.
  720. Return Value:
  721. The position of the given character or INVALID_CHNUM.
  722. --*/
  723. {
  724. PWSTR p;
  725. p = wcsrchr(_s + StartPosition, Char);
  726. return p ? (CHNUM)(p - _s) : INVALID_CHNUM;
  727. }
  728. INLINE
  729. CHNUM
  730. WSTRING::Strstr(
  731. IN PCWSTRING String
  732. ) CONST
  733. /*++
  734. Routine Description:
  735. This routine finds the given string withing this string.
  736. Arguments:
  737. String - Supplies the string to find.
  738. Return Value:
  739. The position of the given string in this string or INVALID_CHNUM.
  740. --*/
  741. {
  742. PWSTR p;
  743. p = wcsstr(_s, String->_s);
  744. return p ? (CHNUM)(p - _s) : INVALID_CHNUM;
  745. }
  746. INLINE
  747. CHNUM
  748. WSTRING::Strspn(
  749. IN PCWSTRING String,
  750. IN CHNUM StartPosition
  751. ) CONST
  752. /*++
  753. Routine Description:
  754. This routine returns the position of the first character in this
  755. string that does not belong to the set of characters in the given
  756. string.
  757. Arguments:
  758. String - Supplies the list of characters to search for.
  759. Return Value:
  760. The position of the first character found that does not belong
  761. to the given string.
  762. --*/
  763. {
  764. CHNUM r;
  765. DebugAssert(StartPosition <= _l);
  766. r = wcsspn(_s + StartPosition, String->_s) + StartPosition;
  767. return r < _l ? r : INVALID_CHNUM;
  768. }
  769. INLINE
  770. CHNUM
  771. WSTRING::Strcspn(
  772. IN PCWSTRING String,
  773. IN CHNUM StartPosition
  774. ) CONST
  775. /*++
  776. Routine Description:
  777. This routine returns the position of the first character in this
  778. string that belongs to the set of characters in the given
  779. string.
  780. Arguments:
  781. String - Supplies the list of characters to search for.
  782. Return Value:
  783. Returns the position of the first character in this string
  784. belonging to the given string or INVALID_CHNUM.
  785. --*/
  786. {
  787. CHNUM r;
  788. DebugAssert(StartPosition <= _l);
  789. r = wcscspn(_s + StartPosition, String->_s) + StartPosition;
  790. return r < _l ? r : INVALID_CHNUM;
  791. }
  792. INLINE
  793. BOOLEAN
  794. WSTRING::operator==(
  795. IN RCWSTRING String
  796. ) CONST
  797. {
  798. return Stricmp(&String) == 0;
  799. }
  800. INLINE
  801. BOOLEAN
  802. WSTRING::operator!=(
  803. IN RCWSTRING String
  804. ) CONST
  805. {
  806. return Stricmp(&String) != 0;
  807. }
  808. INLINE
  809. BOOLEAN
  810. WSTRING::operator<(
  811. IN RCWSTRING String
  812. ) CONST
  813. {
  814. return Stricmp(&String) < 0;
  815. }
  816. INLINE
  817. BOOLEAN
  818. WSTRING::operator>(
  819. IN RCWSTRING String
  820. ) CONST
  821. {
  822. return Stricmp(&String) > 0;
  823. }
  824. INLINE
  825. BOOLEAN
  826. WSTRING::operator<=(
  827. IN RCWSTRING String
  828. ) CONST
  829. {
  830. return Stricmp(&String) <= 0;
  831. }
  832. INLINE
  833. BOOLEAN
  834. WSTRING::operator>=(
  835. IN RCWSTRING String
  836. ) CONST
  837. {
  838. return Stricmp(&String) >= 0;
  839. }
  840. INLINE
  841. CHNUM
  842. WSTRING::Truncate(
  843. IN CHNUM Position
  844. )
  845. {
  846. DebugAssert(Position <= _l);
  847. Resize(Position);
  848. return _l;
  849. }
  850. DECLARE_CLASS( FSTRING );
  851. class ULIB_EXPORT FSTRING : public WSTRING {
  852. public:
  853. DECLARE_CONSTRUCTOR( FSTRING );
  854. NONVIRTUAL
  855. PWSTRING
  856. Initialize(
  857. IN OUT PWSTR InitialString,
  858. IN CHNUM BufferLength DEFAULT TO_END
  859. );
  860. VIRTUAL
  861. BOOLEAN
  862. Resize(
  863. IN CHNUM NewStringLength
  864. );
  865. VIRTUAL
  866. BOOLEAN
  867. NewBuf(
  868. IN CHNUM NewStringLength
  869. );
  870. private:
  871. CHNUM _buffer_length;
  872. };
  873. INLINE
  874. PWSTRING
  875. FSTRING::Initialize(
  876. IN OUT PWSTR InitialString,
  877. IN CHNUM BufferLength
  878. )
  879. /*++
  880. Routine Description:
  881. This routine initializes this class with a null-terminated
  882. unicode string. This routine does not make a copy of the string
  883. but uses it as is.
  884. Arguments:
  885. NullTerminatedString - Supplies a null-terminated unicode string.
  886. BufferLength - Supplies the buffer length.
  887. Return Value:
  888. A pointer to this class.
  889. --*/
  890. {
  891. PutString(InitialString);
  892. _buffer_length = ((BufferLength == TO_END) ?
  893. (QueryChCount() + 1) : BufferLength);
  894. return this;
  895. }
  896. DECLARE_CLASS( DSTRING );
  897. class ULIB_EXPORT DSTRING : public WSTRING {
  898. public:
  899. DECLARE_CONSTRUCTOR( DSTRING );
  900. VIRTUAL
  901. ~DSTRING(
  902. );
  903. VIRTUAL
  904. BOOLEAN
  905. Resize(
  906. IN CHNUM NewStringLength
  907. );
  908. VIRTUAL
  909. BOOLEAN
  910. NewBuf(
  911. IN CHNUM NewStringLength
  912. );
  913. private:
  914. VOID
  915. Construct(
  916. );
  917. PWSTR _buf; // String buffer.
  918. CHNUM _length; // Number of characters in buffer.
  919. };
  920. #endif // _WSTRING_DEFN_