widestring.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786
  1. /*
  2. ** Command & Conquer Renegade(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. /***********************************************************************************************
  19. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  20. ***********************************************************************************************
  21. * *
  22. * Project Name : WWSaveLoad *
  23. * *
  24. * $Archive:: /Commando/Code/wwlib/widestring.h $*
  25. * *
  26. * Author:: Patrick Smith *
  27. * *
  28. * $Modtime:: 2/06/02 4:59p $*
  29. * *
  30. * $Revision:: 22 $*
  31. * *
  32. *---------------------------------------------------------------------------------------------*
  33. * Functions: *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #if defined(_MSC_VER)
  36. #pragma once
  37. #endif
  38. #ifndef __WIDESTRING_H
  39. #define __WIDESTRING_H
  40. #include <string.h>
  41. #include <stdarg.h>
  42. #include "always.h"
  43. #include "wwdebug.h"
  44. #include "win.h"
  45. #include "wwstring.h"
  46. #include "trim.h"
  47. #include <wchar.h>
  48. #ifdef _UNIX
  49. #include "osdep.h"
  50. #endif
  51. //////////////////////////////////////////////////////////////////////
  52. //
  53. // WideStringClass
  54. //
  55. // This is a UNICODE (double-byte) version of StringClass. All
  56. // operations are performed on wide character strings.
  57. //
  58. //////////////////////////////////////////////////////////////////////
  59. class WideStringClass
  60. {
  61. public:
  62. ////////////////////////////////////////////////////////////
  63. // Public constructors/destructors
  64. ////////////////////////////////////////////////////////////
  65. WideStringClass (int initial_len = 0, bool hint_temporary = false);
  66. WideStringClass (const WideStringClass &string, bool hint_temporary = false);
  67. WideStringClass (const WCHAR *string, bool hint_temporary = false);
  68. WideStringClass (WCHAR ch, bool hint_temporary = false);
  69. WideStringClass (const char *string, bool hint_temporary = false);
  70. ~WideStringClass (void);
  71. ////////////////////////////////////////////////////////////
  72. // Public operators
  73. ////////////////////////////////////////////////////////////
  74. bool operator== (const WCHAR *rvalue) const;
  75. bool operator!= (const WCHAR *rvalue) const;
  76. inline const WideStringClass &operator= (const WideStringClass &string);
  77. inline const WideStringClass &operator= (const WCHAR *string);
  78. inline const WideStringClass &operator= (WCHAR ch);
  79. inline const WideStringClass &operator= (const char *string);
  80. const WideStringClass &operator+= (const WideStringClass &string);
  81. const WideStringClass &operator+= (const WCHAR *string);
  82. const WideStringClass &operator+= (WCHAR ch);
  83. friend WideStringClass operator+ (const WideStringClass &string1, const WideStringClass &string2);
  84. friend WideStringClass operator+ (const WCHAR *string1, const WideStringClass &string2);
  85. friend WideStringClass operator+ (const WideStringClass &string1, const WCHAR *string2);
  86. bool operator < (const WCHAR *string) const;
  87. bool operator <= (const WCHAR *string) const;
  88. bool operator > (const WCHAR *string) const;
  89. bool operator >= (const WCHAR *string) const;
  90. WCHAR operator[] (int index) const;
  91. WCHAR& operator[] (int index);
  92. operator const WCHAR * (void) const;
  93. ////////////////////////////////////////////////////////////
  94. // Public methods
  95. ////////////////////////////////////////////////////////////
  96. int Compare (const WCHAR *string) const;
  97. int Compare_No_Case (const WCHAR *string) const;
  98. inline int Get_Length (void) const;
  99. bool Is_Empty (void) const;
  100. void Erase (int start_index, int char_count);
  101. int _cdecl Format (const WCHAR *format, ...);
  102. int _cdecl Format_Args (const WCHAR *format, const va_list & arg_list );
  103. bool Convert_From (const char *text);
  104. bool Convert_To (StringClass &string);
  105. bool Convert_To (StringClass &string) const;
  106. // Trim leading and trailing whitespace (chars <= 32)
  107. void Trim(void);
  108. // Check if the string is composed of ANSI range characters. (0-255)
  109. bool Is_ANSI(void);
  110. WCHAR * Get_Buffer (int new_length);
  111. WCHAR * Peek_Buffer (void);
  112. ////////////////////////////////////////////////////////////
  113. // Static methods
  114. ////////////////////////////////////////////////////////////
  115. static void Release_Resources (void);
  116. private:
  117. ////////////////////////////////////////////////////////////
  118. // Private structures
  119. ////////////////////////////////////////////////////////////
  120. typedef struct _HEADER
  121. {
  122. int allocated_length;
  123. int length;
  124. } HEADER;
  125. ////////////////////////////////////////////////////////////
  126. // Private constants
  127. ////////////////////////////////////////////////////////////
  128. enum
  129. {
  130. MAX_TEMP_STRING = 4,
  131. MAX_TEMP_LEN = 256,
  132. MAX_TEMP_BYTES = (MAX_TEMP_LEN * sizeof (WCHAR)) + sizeof (HEADER),
  133. };
  134. ////////////////////////////////////////////////////////////
  135. // Private methods
  136. ////////////////////////////////////////////////////////////
  137. void Get_String (int length, bool is_temp);
  138. WCHAR * Allocate_Buffer (int length);
  139. void Resize (int size);
  140. void Uninitialised_Grow (int length);
  141. void Free_String (void);
  142. inline void Store_Length (int length);
  143. inline void Store_Allocated_Length (int allocated_length);
  144. inline HEADER * Get_Header (void) const;
  145. int Get_Allocated_Length (void) const;
  146. void Set_Buffer_And_Allocated_Length (WCHAR *buffer, int length);
  147. ////////////////////////////////////////////////////////////
  148. // Private member data
  149. ////////////////////////////////////////////////////////////
  150. WCHAR * m_Buffer;
  151. ////////////////////////////////////////////////////////////
  152. // Static member data
  153. ////////////////////////////////////////////////////////////
  154. static char m_TempString1[MAX_TEMP_BYTES];
  155. static char m_TempString2[MAX_TEMP_BYTES];
  156. static char m_TempString3[MAX_TEMP_BYTES];
  157. static char m_TempString4[MAX_TEMP_BYTES];
  158. static WCHAR * m_FreeTempPtr[MAX_TEMP_STRING];
  159. static WCHAR * m_ResTempPtr[MAX_TEMP_STRING];
  160. static int m_UsedTempStringCount;
  161. static FastCriticalSectionClass m_TempMutex;
  162. static WCHAR m_NullChar;
  163. static WCHAR * m_EmptyString;
  164. };
  165. ///////////////////////////////////////////////////////////////////
  166. // WideStringClass
  167. ///////////////////////////////////////////////////////////////////
  168. inline
  169. WideStringClass::WideStringClass (int initial_len, bool hint_temporary)
  170. : m_Buffer (m_EmptyString)
  171. {
  172. Get_String (initial_len, hint_temporary);
  173. m_Buffer[0] = m_NullChar;
  174. return ;
  175. }
  176. ///////////////////////////////////////////////////////////////////
  177. // WideStringClass
  178. ///////////////////////////////////////////////////////////////////
  179. inline
  180. WideStringClass::WideStringClass (WCHAR ch, bool hint_temporary)
  181. : m_Buffer (m_EmptyString)
  182. {
  183. Get_String (2, hint_temporary);
  184. (*this) = ch;
  185. return ;
  186. }
  187. ///////////////////////////////////////////////////////////////////
  188. // WideStringClass
  189. ///////////////////////////////////////////////////////////////////
  190. inline
  191. WideStringClass::WideStringClass (const WideStringClass &string, bool hint_temporary)
  192. : m_Buffer (m_EmptyString)
  193. {
  194. if (hint_temporary || (string.Get_Length()>1)) {
  195. Get_String(string.Get_Length()+1, hint_temporary);
  196. }
  197. (*this) = string;
  198. return ;
  199. }
  200. ///////////////////////////////////////////////////////////////////
  201. // WideStringClass
  202. ///////////////////////////////////////////////////////////////////
  203. inline
  204. WideStringClass::WideStringClass (const WCHAR *string, bool hint_temporary)
  205. : m_Buffer (m_EmptyString)
  206. {
  207. int len=string ? wcslen(string) : 0;
  208. if (hint_temporary || len>0) {
  209. Get_String (len+1, hint_temporary);
  210. }
  211. (*this) = string;
  212. return ;
  213. }
  214. ///////////////////////////////////////////////////////////////////
  215. // WideStringClass
  216. ///////////////////////////////////////////////////////////////////
  217. inline
  218. WideStringClass::WideStringClass (const char *string, bool hint_temporary)
  219. : m_Buffer (m_EmptyString)
  220. {
  221. if (hint_temporary || (string && strlen(string)>0)) {
  222. Get_String (strlen(string) + 1, hint_temporary);
  223. }
  224. (*this) = string;
  225. return ;
  226. }
  227. ///////////////////////////////////////////////////////////////////
  228. // ~WideStringClass
  229. ///////////////////////////////////////////////////////////////////
  230. inline
  231. WideStringClass::~WideStringClass (void)
  232. {
  233. Free_String ();
  234. return ;
  235. }
  236. ///////////////////////////////////////////////////////////////////
  237. // Is_Empty
  238. ///////////////////////////////////////////////////////////////////
  239. inline bool
  240. WideStringClass::Is_Empty (void) const
  241. {
  242. return (m_Buffer[0] == m_NullChar);
  243. }
  244. ///////////////////////////////////////////////////////////////////
  245. // Compare
  246. ///////////////////////////////////////////////////////////////////
  247. inline int
  248. WideStringClass::Compare (const WCHAR *string) const
  249. {
  250. if (string) {
  251. return wcscmp (m_Buffer, string);
  252. }
  253. return -1;
  254. }
  255. ///////////////////////////////////////////////////////////////////
  256. // Compare_No_Case
  257. ///////////////////////////////////////////////////////////////////
  258. inline int
  259. WideStringClass::Compare_No_Case (const WCHAR *string) const
  260. {
  261. if (string) {
  262. return _wcsicmp (m_Buffer, string);
  263. }
  264. return -1;
  265. }
  266. ///////////////////////////////////////////////////////////////////
  267. // operator[]
  268. ///////////////////////////////////////////////////////////////////
  269. inline WCHAR
  270. WideStringClass::operator[] (int index) const
  271. {
  272. WWASSERT (index >= 0 && index < Get_Length ());
  273. return m_Buffer[index];
  274. }
  275. inline WCHAR&
  276. WideStringClass::operator[] (int index)
  277. {
  278. WWASSERT (index >= 0 && index < Get_Length ());
  279. return m_Buffer[index];
  280. }
  281. ///////////////////////////////////////////////////////////////////
  282. // operator const WCHAR *
  283. ///////////////////////////////////////////////////////////////////
  284. inline
  285. WideStringClass::operator const WCHAR * (void) const
  286. {
  287. return m_Buffer;
  288. }
  289. ///////////////////////////////////////////////////////////////////
  290. // operator==
  291. ///////////////////////////////////////////////////////////////////
  292. inline bool
  293. WideStringClass::operator== (const WCHAR *rvalue) const
  294. {
  295. return (Compare (rvalue) == 0);
  296. }
  297. ///////////////////////////////////////////////////////////////////
  298. // operator!=
  299. ///////////////////////////////////////////////////////////////////
  300. inline bool
  301. WideStringClass::operator!= (const WCHAR *rvalue) const
  302. {
  303. return (Compare (rvalue) != 0);
  304. }
  305. ///////////////////////////////////////////////////////////////////
  306. // operator=
  307. ///////////////////////////////////////////////////////////////////
  308. inline const WideStringClass &
  309. WideStringClass::operator= (const WideStringClass &string)
  310. {
  311. return operator= ((const WCHAR *)string);
  312. }
  313. ///////////////////////////////////////////////////////////////////
  314. // operator <
  315. ///////////////////////////////////////////////////////////////////
  316. inline bool
  317. WideStringClass::operator < (const WCHAR *string) const
  318. {
  319. if (string) {
  320. return (wcscmp (m_Buffer, string) < 0);
  321. }
  322. return false;
  323. }
  324. ///////////////////////////////////////////////////////////////////
  325. // operator <=
  326. ///////////////////////////////////////////////////////////////////
  327. inline bool
  328. WideStringClass::operator <= (const WCHAR *string) const
  329. {
  330. if (string) {
  331. return (wcscmp (m_Buffer, string) <= 0);
  332. }
  333. return false;
  334. }
  335. ///////////////////////////////////////////////////////////////////
  336. // operator >
  337. ///////////////////////////////////////////////////////////////////
  338. inline bool
  339. WideStringClass::operator > (const WCHAR *string) const
  340. {
  341. if (string) {
  342. return (wcscmp (m_Buffer, string) > 0);
  343. }
  344. return true;
  345. }
  346. ///////////////////////////////////////////////////////////////////
  347. // operator >=
  348. ///////////////////////////////////////////////////////////////////
  349. inline bool
  350. WideStringClass::operator >= (const WCHAR *string) const
  351. {
  352. if (string) {
  353. return (wcscmp (m_Buffer, string) >= 0);
  354. }
  355. return true;
  356. }
  357. ///////////////////////////////////////////////////////////////////
  358. // Erase
  359. ///////////////////////////////////////////////////////////////////
  360. inline void
  361. WideStringClass::Erase (int start_index, int char_count)
  362. {
  363. int len = Get_Length ();
  364. if (start_index < len) {
  365. if (start_index + char_count > len) {
  366. char_count = len - start_index;
  367. }
  368. ::memmove ( &m_Buffer[start_index],
  369. &m_Buffer[start_index + char_count],
  370. (len - (start_index + char_count) + 1) * sizeof (WCHAR));
  371. Store_Length( wcslen(m_Buffer) );
  372. }
  373. return ;
  374. }
  375. ///////////////////////////////////////////////////////////////////
  376. // Trim leading and trailing whitespace (chars <= 32)
  377. ///////////////////////////////////////////////////////////////////
  378. inline void WideStringClass::Trim(void)
  379. {
  380. wcstrim(m_Buffer);
  381. int len = wcslen(m_Buffer);
  382. Store_Length(len);
  383. }
  384. ///////////////////////////////////////////////////////////////////
  385. // operator=
  386. ///////////////////////////////////////////////////////////////////
  387. inline const WideStringClass &
  388. WideStringClass::operator= (const WCHAR *string)
  389. {
  390. if (string) {
  391. int len = wcslen (string);
  392. Uninitialised_Grow (len + 1);
  393. Store_Length (len);
  394. ::memcpy (m_Buffer, string, (len + 1) * sizeof (WCHAR));
  395. }
  396. return (*this);
  397. }
  398. ///////////////////////////////////////////////////////////////////
  399. // operator=
  400. ///////////////////////////////////////////////////////////////////
  401. inline const WideStringClass &
  402. WideStringClass::operator= (const char *string)
  403. {
  404. Convert_From(string);
  405. return (*this);
  406. }
  407. ///////////////////////////////////////////////////////////////////
  408. // operator=
  409. ///////////////////////////////////////////////////////////////////
  410. inline const WideStringClass &
  411. WideStringClass::operator= (WCHAR ch)
  412. {
  413. Uninitialised_Grow (2);
  414. m_Buffer[0] = ch;
  415. m_Buffer[1] = m_NullChar;
  416. Store_Length (1);
  417. return (*this);
  418. }
  419. ///////////////////////////////////////////////////////////////////
  420. // operator+=
  421. ///////////////////////////////////////////////////////////////////
  422. inline const WideStringClass &
  423. WideStringClass::operator+= (const WCHAR *string)
  424. {
  425. if (string) {
  426. int cur_len = Get_Length ();
  427. int src_len = wcslen (string);
  428. int new_len = cur_len + src_len;
  429. //
  430. // Make sure our buffer is large enough to hold the new string
  431. //
  432. Resize (new_len + 1);
  433. Store_Length (new_len);
  434. //
  435. // Copy the new string onto our the end of our existing buffer
  436. //
  437. ::memcpy (&m_Buffer[cur_len], string, (src_len + 1) * sizeof (WCHAR));
  438. }
  439. return (*this);
  440. }
  441. ///////////////////////////////////////////////////////////////////
  442. // operator+=
  443. ///////////////////////////////////////////////////////////////////
  444. inline const WideStringClass &
  445. WideStringClass::operator+= (WCHAR ch)
  446. {
  447. int cur_len = Get_Length ();
  448. Resize (cur_len + 2);
  449. m_Buffer[cur_len] = ch;
  450. m_Buffer[cur_len + 1] = m_NullChar;
  451. if (ch != m_NullChar) {
  452. Store_Length (cur_len + 1);
  453. }
  454. return (*this);
  455. }
  456. ///////////////////////////////////////////////////////////////////
  457. // Get_Buffer
  458. ///////////////////////////////////////////////////////////////////
  459. inline WCHAR *
  460. WideStringClass::Get_Buffer (int new_length)
  461. {
  462. Uninitialised_Grow (new_length);
  463. return m_Buffer;
  464. }
  465. ///////////////////////////////////////////////////////////////////
  466. // Peek_Buffer
  467. ///////////////////////////////////////////////////////////////////
  468. inline WCHAR *
  469. WideStringClass::Peek_Buffer (void)
  470. {
  471. return m_Buffer;
  472. }
  473. ///////////////////////////////////////////////////////////////////
  474. // operator+=
  475. ///////////////////////////////////////////////////////////////////
  476. inline const WideStringClass &
  477. WideStringClass::operator+= (const WideStringClass &string)
  478. {
  479. int src_len = string.Get_Length();
  480. if (src_len > 0) {
  481. int cur_len = Get_Length ();
  482. int new_len = cur_len + src_len;
  483. //
  484. // Make sure our buffer is large enough to hold the new string
  485. //
  486. Resize (new_len + 1);
  487. Store_Length (new_len);
  488. //
  489. // Copy the new string onto our the end of our existing buffer
  490. //
  491. ::memcpy (&m_Buffer[cur_len], (const WCHAR *)string, (src_len + 1) * sizeof (WCHAR));
  492. }
  493. return (*this);
  494. }
  495. ///////////////////////////////////////////////////////////////////
  496. // operator+=
  497. ///////////////////////////////////////////////////////////////////
  498. inline WideStringClass
  499. operator+ (const WideStringClass &string1, const WideStringClass &string2)
  500. {
  501. WideStringClass new_string(string1, true);
  502. new_string += string2;
  503. return new_string;
  504. }
  505. ///////////////////////////////////////////////////////////////////
  506. // operator+=
  507. ///////////////////////////////////////////////////////////////////
  508. inline WideStringClass
  509. operator+ (const WCHAR *string1, const WideStringClass &string2)
  510. {
  511. WideStringClass new_string(string1, true);
  512. new_string += string2;
  513. return new_string;
  514. }
  515. ///////////////////////////////////////////////////////////////////
  516. // operator+=
  517. ///////////////////////////////////////////////////////////////////
  518. inline WideStringClass
  519. operator+ (const WideStringClass &string1, const WCHAR *string2)
  520. {
  521. WideStringClass new_string(string1, true);
  522. new_string += string2;
  523. return new_string;
  524. }
  525. ///////////////////////////////////////////////////////////////////
  526. // Get_Allocated_Length
  527. //
  528. // Return allocated size of the string buffer
  529. ///////////////////////////////////////////////////////////////////
  530. inline int
  531. WideStringClass::Get_Allocated_Length (void) const
  532. {
  533. int allocated_length = 0;
  534. //
  535. // Read the allocated length from the header
  536. //
  537. if (m_Buffer != m_EmptyString) {
  538. HEADER *header = Get_Header ();
  539. allocated_length = header->allocated_length;
  540. }
  541. return allocated_length;
  542. }
  543. ///////////////////////////////////////////////////////////////////
  544. // Get_Length
  545. //
  546. // Return text legth. If length is not known calculate it, otherwise
  547. // just return the previously stored value (strlen tends to take
  548. // quite a lot cpu time if a lot of string combining operations are
  549. // performed.
  550. ///////////////////////////////////////////////////////////////////
  551. inline int
  552. WideStringClass::Get_Length (void) const
  553. {
  554. int length = 0;
  555. if (m_Buffer != m_EmptyString) {
  556. //
  557. // Read the length from the header
  558. //
  559. HEADER *header = Get_Header ();
  560. length = header->length;
  561. //
  562. // Hmmm, a zero length was stored in the header,
  563. // we better manually get the string length.
  564. //
  565. if (length == 0) {
  566. length = wcslen (m_Buffer);
  567. ((WideStringClass *)this)->Store_Length (length);
  568. }
  569. }
  570. return length;
  571. }
  572. ///////////////////////////////////////////////////////////////////
  573. // Set_Buffer_And_Allocated_Length
  574. //
  575. // Set buffer pointer and init size variable. Length is set to 0
  576. // as the contents of the new buffer are not necessarily defined.
  577. ///////////////////////////////////////////////////////////////////
  578. inline void
  579. WideStringClass::Set_Buffer_And_Allocated_Length (WCHAR *buffer, int length)
  580. {
  581. Free_String ();
  582. m_Buffer = buffer;
  583. //
  584. // Update the header (if necessary)
  585. //
  586. if (m_Buffer != m_EmptyString) {
  587. Store_Allocated_Length (length);
  588. Store_Length (0);
  589. } else {
  590. WWASSERT (length == 0);
  591. }
  592. return ;
  593. }
  594. ///////////////////////////////////////////////////////////////////
  595. // Allocate_Buffer
  596. ///////////////////////////////////////////////////////////////////
  597. inline WCHAR *
  598. WideStringClass::Allocate_Buffer (int length)
  599. {
  600. //
  601. // Allocate a buffer that is 'length' characters long, plus the
  602. // bytes required to hold the header.
  603. //
  604. char *buffer = new char[(sizeof (WCHAR) * length) + sizeof (WideStringClass::_HEADER)];
  605. //
  606. // Fill in the fields of the header
  607. //
  608. HEADER *header = reinterpret_cast<HEADER *>(buffer);
  609. header->length = 0;
  610. header->allocated_length = length;
  611. //
  612. // Return the buffer as if it was a WCHAR pointer
  613. //
  614. return reinterpret_cast<WCHAR *>(buffer + sizeof (WideStringClass::_HEADER));
  615. }
  616. ///////////////////////////////////////////////////////////////////
  617. // Get_Header
  618. ///////////////////////////////////////////////////////////////////
  619. inline WideStringClass::HEADER *
  620. WideStringClass::Get_Header (void) const
  621. {
  622. return reinterpret_cast<HEADER *>(((char *)m_Buffer) - sizeof (WideStringClass::_HEADER));
  623. }
  624. ///////////////////////////////////////////////////////////////////
  625. // Store_Allocated_Length
  626. ///////////////////////////////////////////////////////////////////
  627. inline void
  628. WideStringClass::Store_Allocated_Length (int allocated_length)
  629. {
  630. if (m_Buffer != m_EmptyString) {
  631. HEADER *header = Get_Header ();
  632. header->allocated_length = allocated_length;
  633. } else {
  634. WWASSERT (allocated_length == 0);
  635. }
  636. return ;
  637. }
  638. ///////////////////////////////////////////////////////////////////
  639. // Store_Length
  640. //
  641. // Set length... The caller of this (private) function better
  642. // be sure that the len is correct.
  643. ///////////////////////////////////////////////////////////////////
  644. inline void
  645. WideStringClass::Store_Length (int length)
  646. {
  647. if (m_Buffer != m_EmptyString) {
  648. HEADER *header = Get_Header ();
  649. header->length = length;
  650. } else {
  651. WWASSERT (length == 0);
  652. }
  653. return ;
  654. }
  655. ///////////////////////////////////////////////////////////////////
  656. // Convert_To
  657. ///////////////////////////////////////////////////////////////////
  658. inline bool
  659. WideStringClass::Convert_To (StringClass &string)
  660. {
  661. return (string.Copy_Wide (m_Buffer));
  662. }
  663. inline bool
  664. WideStringClass::Convert_To (StringClass &string) const
  665. {
  666. return (string.Copy_Wide (m_Buffer));
  667. }
  668. #endif //__WIDESTRING_H