AcString.h 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476
  1. //
  2. //////////////////////////////////////////////////////////////////////////////
  3. //
  4. // Copyright 2015 Autodesk, Inc. All rights reserved.
  5. //
  6. // Use of this software is subject to the terms of the Autodesk license
  7. // agreement provided at the time of installation or download, or which
  8. // otherwise accompanies this software in either electronic or hard copy form.
  9. //
  10. //////////////////////////////////////////////////////////////////////////////
  11. #ifndef _Ac_String_h_
  12. #define _Ac_String_h_
  13. #include "acbasedefs.h"
  14. #include "adesk.h"
  15. #include "AcHeapOpers.h"
  16. #include "AdAChar.h"
  17. #pragma pack (push, 1)
  18. class AcDbHandle;
  19. // Notes:
  20. // 1. All "char" arguments are assumed to be ansi codes in the current
  21. // code page, unless otherwise specified to be utf-8.
  22. //
  23. // 2. In places where a single (ansi) char value is passed, the value
  24. // cannot be a leading byte of a double-byte char, except
  25. // where noted.
  26. //
  27. // 3. All wchar_t arguments are assumed to be "widechar" Unicode values.
  28. //
  29. // 4. Many methods and operators taking ansi (const char *) arguments may
  30. // be phased out in the future. Clients should use Unicode strings.
  31. //
  32. class AcString : public AcHeapOperators
  33. {
  34. public:
  35. //
  36. // Constructors and destructor
  37. //
  38. // Default ctor, initializes to empty string.
  39. ACBASE_PORT AcString();
  40. // Initialize with a single character.
  41. // ch : input (ansi) character
  42. ACBASE_PORT AcString(char ch);
  43. // Initialize with a single Unicode character
  44. // wch : input character
  45. ACBASE_PORT AcString(wchar_t wch);
  46. // Initialize from an ansi or utf-8 string.
  47. // psz : input pointer to source string.
  48. ACBASE_PORT AcString(const char *psz, bool bUtf8 = false);
  49. // Initialize from a Unicode string
  50. // wpsz : input pointer to source string
  51. ACBASE_PORT AcString(const wchar_t *pwsz);
  52. // Copy constructor
  53. // acs : input reference to an existing AcString object
  54. ACBASE_PORT AcString(const AcString & acs);
  55. // Values for the nCtorFlags arg of the following constructor
  56. enum {
  57. kAppRes = 0x0001, // use app's default resource dll
  58. kSigned = 0x0002, // format the arg as signed int
  59. kUnSigned = 0x0003, // format the arg as unsigned int
  60. kHex = 0x0004 // format the arg as hex
  61. };
  62. // Multi-purpose constructor, takes an unsigned argument and
  63. // uses it either to load a resource string or to create a
  64. // numerical string (base 10 or hex).
  65. //
  66. // nCtorFlags : input flags, indicating type of construction
  67. // nArg : input argument value, interpreted according to flags
  68. ACBASE_PORT AcString(int nCtorFlags, unsigned nArg);
  69. // Formats an AcDbHandle value in hex, as in: "a2f".
  70. // h : input reference to an acdb handle value
  71. ACBASE_PORT AcString(const AcDbHandle &h);
  72. #if defined(_WINBASE_) || defined(_ADESK_MAC_)
  73. // Loads a resource string from the specified dll handle.
  74. // hDll : input windows handle to a loaded resource dll
  75. // nId : input int id of the resource string to load
  76. ACBASE_PORT AcString(HINSTANCE hDll, unsigned nId);
  77. #endif
  78. // Destructor: frees up memory.
  79. ACBASE_PORT ~AcString();
  80. //
  81. // Querying methods
  82. //
  83. // Get a pointer to the current string (code page based). This
  84. // pointer is only valid until the AcString object is next modified!
  85. ACBASE_PORT const char * ansiPtr() const;
  86. // Deprecated. Please use ansiPtr() or utf8Ptr() instead
  87. const char * kszPtr() const;
  88. // Get a pointer to the current string as Unicode UTF-8. This
  89. // pointer is only valid until the AcString object is modified!
  90. ACBASE_PORT const char * utf8Ptr() const;
  91. // Get a pointer to the current string (in Unicode). This pointer
  92. // is only valid until this AcString object is next modified!
  93. ACBASE_PORT const wchar_t * kwszPtr() const;
  94. // Get a pointer to the current string as a TCHAR pointer.
  95. // Pointer is only valid until this AcString is next modified.
  96. #ifdef UNICODE
  97. const wchar_t * constPtr() const;
  98. const wchar_t * kTCharPtr() const;
  99. #else
  100. const char * constPtr() const;
  101. const char * kTCharPtr() const;
  102. #endif
  103. // Get a pointer to the current string in ACHARs.
  104. const ACHAR * kACharPtr() const;
  105. // Get a pointer to the current string (in Unicode). Pointer
  106. // is valid only until this AcString is next modified.
  107. operator const wchar_t * () const;
  108. // Test whether the current string value is empty. I.e.,
  109. // logical length is zero.
  110. ACBASE_PORT bool isEmpty() const;
  111. // Return logical length of (i.e. number of characters in) the string.
  112. //
  113. ACBASE_PORT unsigned length() const;
  114. // Return length of the current string, in TCHAR units.
  115. // Deprecated. Please use length() instead
  116. unsigned tcharLength() const;
  117. // Returns true if all chars are in the ascii range: 0x20..0x7f
  118. ACBASE_PORT bool isAscii() const;
  119. //
  120. // Parsing methods.
  121. //
  122. enum {
  123. // Enum value allowing caller to specify how to handle errors
  124. // (invalid chars or overflow) during string parsing.
  125. kParseZero = 0, // return zero on errors
  126. kParseMinus1 = 0x01, // return -1 or ffff
  127. kParseAssert = 0x02, // pop an assert in debug build
  128. kParseExcept = 0x04, // throw an int exception
  129. kParseNoEmpty = 0x08, // treat empty string as error
  130. kParseDefault = (kParseAssert | kParseZero)
  131. };
  132. // Parse the current string as decimal, return a signed int
  133. // nFlags : input bits specifying how to do the parsing
  134. ACBASE_PORT int asDeci(int nFlags = kParseDefault) const;
  135. // Parse the current string as hexadecimal, return a signed int
  136. // nFlags : input bits specifying how to do the parsing
  137. ACBASE_PORT int asHex (int nFlags = kParseDefault) const;
  138. // Parse the current string as decimal, return an unsigned int
  139. // nFlags : input bits specifying how to do the parsing
  140. ACBASE_PORT unsigned int asUDeci(int nFlags = kParseDefault) const;
  141. // Parse the current string as hexadecimal, return an unsigned int
  142. // nFlags : input bits specifying how to do the parsing
  143. ACBASE_PORT unsigned int asUHex (int nFlags = kParseDefault) const;
  144. // Parse the current string as decimal, return a signed int64
  145. // nFlags : input bits specifying how to do the parsing
  146. ACBASE_PORT __int64 asDeci64(int nFlags = kParseDefault) const;
  147. // Parse the current string as hexadecimal, return a signed int64
  148. // nFlags : input bits specifying how to do the parsing
  149. ACBASE_PORT __int64 asHex64 (int nFlags = kParseDefault) const;
  150. // Parse the current string as decimal, return an unsigned int64
  151. // nFlags : input bits specifying how to do the parsing
  152. ACBASE_PORT Adesk::UInt64 asUDeci64(int nFlags = kParseDefault) const;
  153. // Parse the current string as hexadecimal, return an unsigned int64
  154. // nFlags : input bits specifying how to do the parsing
  155. ACBASE_PORT Adesk::UInt64 asUHex64 (int nFlags = kParseDefault) const;
  156. // Parse the current string as hexadecimal. Return the handle.
  157. // nFlags : input bits specifying how to do the parsing
  158. ACBASE_PORT AcDbHandle asAcDbHandle(int nFlags = kParseDefault) const;
  159. //
  160. // Find char/string/one of a string of chars, from front or back
  161. // Return the position (index) at which the character or substring
  162. // was found.
  163. //
  164. // The find methods which start at the end of the string return
  165. // an index relative to the front of the string.
  166. // Find a single char in the string.
  167. // ch : input char to search for
  168. int find(ACHAR ch) const;
  169. // Find a substring in the string
  170. // psz : input string to search for
  171. ACBASE_PORT int find(const ACHAR *psz) const;
  172. // Find an AcString in the string.
  173. // acs : input string object to search for
  174. ACBASE_PORT int find(const AcString & acs) const;
  175. // Find any of a group of chars in the string.
  176. // psz : input pointer to string of chars to search for
  177. ACBASE_PORT int findOneOf(const ACHAR *psz) const;
  178. // Find last occurrence of a char in the string
  179. // ch : input char to search for
  180. int findRev(ACHAR ch) const;
  181. // Find last occurrence of any of a group of chars in the string
  182. // psz : input pointer to string of chars to search for
  183. ACBASE_PORT int findRev(const ACHAR *psz) const;
  184. // Find last occurrence of a group of chars in the string
  185. // psz : input ptr to the string of chars to search for
  186. ACBASE_PORT int findOneOfRev(const ACHAR *psz) const;
  187. // Find last occurrence of a string in the string
  188. // acs : input reference to the string to search for
  189. ACBASE_PORT int findRev(const AcString & acs) const;
  190. //
  191. // Extraction methods
  192. // Note: mid() and substr() are the same thing - we define both
  193. // for compatibility with CString and std::string
  194. //
  195. // The input index arguments are byte indices into the string.
  196. // Get a substring from the string. (same as substr() method)
  197. // nStart : input index (in bytes) from the start of the string
  198. // nNumChars : input number of chars (not bytes) to retrieve.
  199. // if nNumChars is -1, then return the rest of the string
  200. AcString mid(int nStart, int nNumChars) const;
  201. // Get a substring from the start of string.
  202. // nNumChars : input number of chars (not bytes) to retrieve.
  203. // if nNumChars is -1, then return the rest of the string
  204. AcString substr(int numChars) const;
  205. // Get a substring from the string. (same as mid() method)
  206. // nStart : input index (in bytes) from the start of the string
  207. // nNumChars : input number of chars (not bytes) to retrieve.
  208. // if nNumChars is -1, then return the rest of the string
  209. ACBASE_PORT AcString substr(int nStart, int nNumChars) const;
  210. // Get a substring from the end of string.
  211. // nNumChars : input number of chars (not bytes) to retrieve.
  212. ACBASE_PORT AcString substrRev(int numChars) const;
  213. //
  214. // Assignment operators and methods
  215. //
  216. // assign a char to the string
  217. // ch : input (ansi) char to assign
  218. AcString & assign(char ch);
  219. // assign a Unicode char to the string
  220. // wch : input char to assign
  221. AcString & assign(wchar_t wch);
  222. // assign a string of (ansi) chars to the string
  223. // psz : input pointer to the string of chars to assign
  224. ACBASE_PORT AcString & assign(const char *psz);
  225. // assign a string of Unicode chars to the string
  226. // pwsz : input pointer to the string of chars to assign
  227. ACBASE_PORT AcString & assign(const wchar_t *pwsz);
  228. // assign an AcString object to the string
  229. // acs : input reference to the AcString
  230. ACBASE_PORT AcString & assign(const AcString & acs);
  231. // assign an AcDbHandle object to the string (format it as hex)
  232. // h : input reference to the AcDbHandle object
  233. ACBASE_PORT AcString & assign(const AcDbHandle & h);
  234. // assign a char to the string
  235. // ch : input (ansi) char to assign
  236. AcString & operator = (char ch);
  237. // assign a Unicode char to the string
  238. // wch : input char to assign
  239. AcString & operator = (wchar_t wch);
  240. // assign a string of (ansi) chars to the string
  241. // psz : input pointer to the string of chars to assign
  242. AcString & operator = (const char *psz);
  243. // assign a string of Unicode chars to the string
  244. // pwsz : input pointer to the string of chars to assign
  245. AcString & operator = (const wchar_t *pwsz);
  246. // assign an AcString object to the string
  247. // acs : input reference to the AcString
  248. AcString & operator = (const AcString & acs);
  249. // assign an AcDbHandle object to the string (format it as hex)
  250. // h : input reference to the AcDbHandle object
  251. AcString & operator = (const AcDbHandle & h);
  252. // Set the string to be empty.
  253. ACBASE_PORT AcString & setEmpty();
  254. // Set the string from a resource string
  255. // nId : input id of the string resource in the current mfc resource dll
  256. ACBASE_PORT bool loadString(unsigned nId);
  257. #if defined(_WINBASE_) || defined(_ADESK_MAC_)
  258. // Set the string from a resource string
  259. // hDll : input windows handle to a loaded resource dll
  260. // nId : input id of the string resource in the specified resource dll
  261. ACBASE_PORT bool loadString(HINSTANCE hDll, unsigned nId);
  262. #endif
  263. // Format the string using "printf" rules.
  264. // pszFmt : input pointer to the printf format string
  265. ACBASE_PORT void format (const ACHAR *pszFmt, ...);
  266. // Format the string using "printf" rules
  267. // pszFmt : input pointer to the printf format string
  268. // args : input variable args list, containing values to be formatted
  269. ACBASE_PORT void formatV(const ACHAR *pszFmt, va_list args);
  270. //
  271. // Modifying operators and methods
  272. //
  273. // append an ansi char to the end of the string
  274. // ch : input (ansi) char to append
  275. AcString & operator += (char ch);
  276. // append a Unicode char to the end of the string
  277. // wch : input char to append
  278. AcString & operator += (wchar_t wch);
  279. // append a char string to the end of the string
  280. // psz : input pointer to the (ansi) char string
  281. AcString & operator += (const char * psz);
  282. // append a Unicode string to the end of the string
  283. // pwsz : input pointer to the Unicode string
  284. AcString & operator += (const wchar_t * pwsz);
  285. // append an AcString object to the end of the string
  286. // acs : input reference to the AcString
  287. AcString & operator += (const AcString & acs);
  288. // append an ansi char to the end of the string
  289. // ch : input char to append
  290. AcString & append(char ch);
  291. // append a Unicode char to the end of the string
  292. // wch : input char to append
  293. AcString & append(wchar_t wch);
  294. // append a char string to the end of the string
  295. // psz : input pointer to the (ansi) char string
  296. ACBASE_PORT AcString & append(const char *psz);
  297. // append a Unicode string to the end of the string
  298. // pwsz : input pointer to the Unicode string
  299. ACBASE_PORT AcString & append(const wchar_t *pwsz);
  300. // append an AcString object to the end of the string
  301. // acs : input reference to the AcString
  302. ACBASE_PORT AcString & append(const AcString & acs);
  303. // Catenation operators and methods These are like append,
  304. // but they do not modify the current string. They return a
  305. // new combined string.
  306. // Copy the string and append a char to it
  307. // ch : input (ansi) char to append to the string copy
  308. AcString operator + (char ch) const;
  309. // Copy the string and append a Unicode char to it
  310. // ch : input char to append to the string copy
  311. AcString operator + (wchar_t wch) const;
  312. // Copy the string and append a string of chars to it
  313. // psz : input pointer to the (ansi) string to append
  314. AcString operator + (const char * psz) const;
  315. // Copy the string and append a string of Unicode chars to it
  316. // pwsz : input pointer to the string to append
  317. AcString operator + (const wchar_t * pwsz) const;
  318. // Copy the string and append an AcString to it
  319. // pwsz : input reference to the AcString to append
  320. AcString operator + (const AcString & acs) const;
  321. // Copy the string and append a char to it
  322. // ch : input (ansi) char to append to the string copy
  323. AcString concat(char ch) const;
  324. // Copy the string and append a Unicode char to it
  325. // ch : input char to append to the string copy
  326. AcString concat(wchar_t wch) const;
  327. // Copy the string and append a string of chars to it
  328. // psz : input pointer to the (ansi) string to append
  329. ACBASE_PORT AcString concat(const char * psz) const;
  330. // Copy the string and append a string of Unicode chars to it
  331. // pwsz : input pointer to the string to append
  332. ACBASE_PORT AcString concat(const wchar_t * pwsz) const;
  333. // Copy the string and append an AcString to it
  334. // pwsz : input reference to the AcString to append
  335. ACBASE_PORT AcString concat(const AcString & acs) const;
  336. // These copy the current string and then insert the char or
  337. // string in front of it. They're used by the global "+" operators.
  338. // Copy the string and insert a char in front of it
  339. // ch : input char to insert
  340. AcString precat(ACHAR ch) const;
  341. // Copy the string and insert a string of chars in front of it
  342. // psz : input pointer to the string of (ansi) chars to insert
  343. ACBASE_PORT AcString precat(const char * psz) const;
  344. // Copy the string and insert a string of chars in front of it
  345. // psz : input pointer to the string of chars to insert
  346. ACBASE_PORT AcString precat(const wchar_t * psz) const;
  347. //
  348. // Comparison operators and methods
  349. // The int return value is -1, 0 or 1, indicating <, == or >
  350. //
  351. // Compare the string to a single Unicode char
  352. // wch : input char to compare to
  353. int compare(wchar_t wch) const;
  354. // Compare the string to a string of (ansi) chars
  355. // psz : input pointer to the string of chars to compare to
  356. ACBASE_PORT int compare(const char *psz) const;
  357. // Compare the string to a string of Unicode chars
  358. // pwsz : input pointer to the string of chars to compare to
  359. ACBASE_PORT int compare(const wchar_t *pwsz) const;
  360. // Compare the string to a string of Unicode chars
  361. // acs : input reference of the other AcString to compare to
  362. ACBASE_PORT int compare(const AcString & acs) const;
  363. // Compare the string case-independently to a Unicode char
  364. // wch : input char to compare to
  365. int compareNoCase(wchar_t wch) const;
  366. // Compare the string case-independently to a string of chars
  367. // psz : input pointer to the string of (ansi) chars to compare to
  368. ACBASE_PORT int compareNoCase(const char *psz) const;
  369. // Compare the string case-independently to a string of Unicode chars
  370. // pwsz : input pointer to the string of chars to compare to
  371. ACBASE_PORT int compareNoCase(const wchar_t *pwsz) const;
  372. // Compare the string case-independently to another AcString
  373. // acs : input reference to the other AcString
  374. ACBASE_PORT int compareNoCase(const AcString & acs) const;
  375. // Compare the string for equality with a Unicode char
  376. // wch : input char to compare to
  377. bool operator == (wchar_t wch) const;
  378. // Compare the string for equality with a string of chars
  379. // psz : input pointer to the string of (ansi) chars
  380. bool operator == (const char *psz) const;
  381. // Compare the string for equality with a string of Unicode chars
  382. // pwsz : input pointer to the string of chars
  383. bool operator == (const wchar_t *pwsz) const;
  384. // Compare the string for equality with another AcString
  385. // acs : input reference to the other AcString
  386. bool operator == (const AcString & acs) const;
  387. // Compare the string for non-equality with a Unicode char
  388. // wch : input char to compare to
  389. bool operator != (wchar_t wch) const;
  390. // Compare the string for non-equality with a string of chars
  391. // psz : input pointer to the string of (ansi) chars
  392. bool operator != (const char *psz) const;
  393. // Compare the string for non-equality with a string of Unicode chars
  394. // pwsz : input pointer to the string of chars
  395. bool operator != (const wchar_t *pwsz) const;
  396. // Compare the string for non-equality with another AcString
  397. // acs : input reference to the other AcString
  398. bool operator != (const AcString & acs) const;
  399. // Compare the string for greater than a Unicode char
  400. // wch : input char to compare to
  401. bool operator > (wchar_t wch) const;
  402. // Compare the string for greater than a string of chars
  403. // psz : input pointer to the string of (ansi) chars to compare to
  404. bool operator > (const char *psz) const;
  405. // Compare the string for greater than a string of Unicode chars
  406. // pwsz : input pointer to the string of chars to compare to
  407. bool operator > (const wchar_t *pwsz) const;
  408. // Compare the string for greater than another AcString
  409. // acs : input reference to the other AcString
  410. bool operator > (const AcString & acs) const;
  411. // Compare the string for greater than or equal to a Unicode char
  412. // wch : input char to compare to
  413. bool operator >= (wchar_t wch) const;
  414. // Compare the string for greater than or equal to a string of chars
  415. // psz : input pointer to the string of (ansi) chars
  416. bool operator >= (const char *psz) const;
  417. // Compare the string for greater than/equal to a string of Unicode chars
  418. // pwsz : input pointer to the string of chars
  419. bool operator >= (const wchar_t *pwsz) const;
  420. // Compare the string for greater than or equal to another AcString
  421. // acs : input reference to the other AcString
  422. bool operator >= (const AcString & acs) const;
  423. // Compare the string for less than a Unicode char
  424. // wch : input char to compare to
  425. bool operator < (wchar_t wch) const;
  426. // Compare the string for less than a string of chars
  427. // psz : input pointer to the string of (ansi) chars to compare to
  428. bool operator < (const char *psz) const;
  429. // Compare the string for less than a string of Unicode chars
  430. // pwsz : input pointer to the string of chars to compare to
  431. bool operator < (const wchar_t *pwsz) const;
  432. // Compare the string for less than another AcString
  433. // acs : input reference to the other AcString
  434. bool operator < (const AcString & acs) const;
  435. // Compare the string for less than or equal to a char
  436. // ch : input (ansi) char to compare to
  437. bool operator <= (char ch) const;
  438. // Compare the string for less than or equal to a Unicode char
  439. // wch : input char to compare to
  440. bool operator <= (wchar_t wch) const;
  441. // Compare the string for less than or equal to a string of chars
  442. // psz : input pointer to the string of (ansi) chars
  443. bool operator <= (const char *psz) const;
  444. // Compare the string for less than/equal to a string of Unicode chars
  445. // pwsz : input pointer to the string of chars
  446. bool operator <= (const wchar_t *pwsz) const;
  447. // Compare the string for less or equal to than another AcString
  448. // acs : input reference to the other AcString
  449. bool operator <= (const AcString & acs) const;
  450. // The match() methods return how many chars (not bytes) match
  451. // between two strings. Not fully implemented yet (non-ascii
  452. // chars not supported yet).
  453. // Return the number of chars that match a string of chars
  454. // psz : input pointer to the string of (ansi) chars
  455. ACBASE_PORT int match(const char *psz) const;
  456. // Return the number of chars matching a string of Unicode chars
  457. // pwsz : input pointer to the string of chars
  458. ACBASE_PORT int match(const wchar_t *pwsz) const;
  459. // Return the number of chars matching another AcString
  460. // acs : input reference to the other AcString
  461. ACBASE_PORT int match(const AcString & acs) const;
  462. // Return number of chars case-independently matching a string of chars
  463. // psz : input pointer to the string of (ansi) chars
  464. ACBASE_PORT int matchNoCase(const char *psz) const;
  465. // Return number of chars case-indep'ly matching a string of Unicode chars
  466. // pwsz : input pointer to the string of chars
  467. ACBASE_PORT int matchNoCase(const wchar_t *pwsz) const;
  468. // Return number of chars case-indep'ly matching another AcString
  469. // acs : input reference to the other AcString
  470. ACBASE_PORT int matchNoCase(const AcString & acs) const;
  471. #if defined(_AFX) || defined (_ADESK_MAC_) || defined(__ATLSTR_H__)
  472. //
  473. // MFC CString-using methods. The CStringA class is the ansi
  474. // code page based CString, while CStringW is Unicode based.
  475. // CString maps to one or the other depending on whether the
  476. // UNICODE preprocessor symbol is defined.
  477. //
  478. // Construct an AcString from a CStringW
  479. // csw : input reference to the CStringW
  480. AcString(const CStringW &csw);
  481. // Initialize this AcString from a CStringW
  482. // csw : input reference to the CStringW
  483. AcString & operator = (const CStringW &csw);
  484. // Append a CStringW to this AcString
  485. // csa : input reference to the CStringW
  486. AcString & operator += (const CStringW &csw);
  487. // Compare this string to a CStringW
  488. // csw : input reference to the CStringW
  489. int compare(const CStringW & csw) const;
  490. // Compare this string case independently to a CStringW
  491. // csw : input reference to the CStringW
  492. int compareNoCase(const CStringW & csw) const;
  493. // Compare for equality with a CStringW
  494. // csw : input reference to the CStringW
  495. bool operator == (const CStringW & ) const;
  496. // Compare for non-equality with a CStringW
  497. // csw : input reference to the CStringW
  498. bool operator != (const CStringW & ) const;
  499. // Compare for less than a CStringW
  500. // csw : input reference to the CStringW
  501. bool operator < (const CStringW & ) const;
  502. // Compare for less than or equal to a CStringW
  503. // csw : input reference to the CStringW
  504. bool operator <= (const CStringW & ) const;
  505. // Compare for greater than a CStringW
  506. // csw : input reference to the CStringW
  507. bool operator > (const CStringW & ) const;
  508. // Compare for greater than or equal to a CStringW
  509. // csw : input reference to the CStringW
  510. bool operator >= (const CStringW & ) const;
  511. // Return number of chars matching a CStringW
  512. // csw : input reference to the CStringW
  513. int match(const CStringW & csw) const;
  514. // Return number of chars case-independently matching a CStringW
  515. // csw : input reference to the CStringW
  516. int matchNoCase(const CStringW & csw) const;
  517. // Note: unfortunately there is not now an assignment operator for
  518. // assigning AcStrings to CStrings, as in CString cs = AcString("x");
  519. #endif
  520. private:
  521. // size is 8 bytes in 32-bit build, 16 in 64-bit build.
  522. #if !defined(_WIN64) && !defined (_AC64)
  523. enum {
  524. #ifdef _ADESK_MAC_
  525. kObjSize = 14,
  526. #else
  527. kObjSize = 8,
  528. #endif
  529. kMbArrSize = 7,
  530. kUCArrSize = 3,
  531. kPadArrSize = 3
  532. };
  533. #else
  534. enum {
  535. #ifdef _ADESK_MAC_
  536. kObjSize = 30,
  537. #else
  538. kObjSize = 16,
  539. #endif
  540. kMbArrSize = 15,
  541. kUCArrSize = 7,
  542. kPadArrSize = 7
  543. };
  544. #endif
  545. void clearAll();
  546. struct PtrAndData;
  547. unsigned char mnFlags;
  548. union {
  549. struct {
  550. unsigned char mnPad2[kPadArrSize];
  551. union {
  552. wchar_t *mpwszData;
  553. char *mpszData;
  554. PtrAndData *mpPtrAndData;
  555. };
  556. }mptr;
  557. struct {
  558. unsigned char mnPad1;
  559. wchar_t mwszStr[kUCArrSize];
  560. }mchr;
  561. char mszStr[kMbArrSize];
  562. };
  563. friend class AcStringImp;
  564. };
  565. #ifdef AC_ACARRAY_H
  566. typedef
  567. AcArray< AcString, AcArrayObjectCopyReallocator< AcString > > AcStringArray;
  568. #endif
  569. #pragma pack (pop)
  570. //
  571. // Global operators
  572. //
  573. // Compare an AcString and a Unicode char for equality
  574. // wch : input char to compare
  575. // acs : input reference to the AcString
  576. bool operator == (wchar_t wch, const AcString & acs);
  577. // Compare an AcString and a string of chars char for equality
  578. // psz : input pointer to the string of chars
  579. // acs : input reference to the AcString
  580. bool operator == (const char *psz, const AcString & acs);
  581. // Compare an AcString and a string of Unicode chars for equality
  582. // pwsz : input char to the string of Unicode chars
  583. // acs : input reference to the AcString
  584. bool operator == (const wchar_t *pwsz, const AcString & acs);
  585. // Compare an AcString and a Unicode char for non-equality
  586. // wch : input char to compare
  587. // acs : input reference to the AcString
  588. bool operator != (wchar_t wch, const AcString & acs);
  589. // Compare an AcString and a string of chars char for non-equality
  590. // psz : input pointer to the string of chars
  591. // acs : input reference to the AcString
  592. bool operator != (const char *psz, const AcString & acs);
  593. // Compare an AcString and a string of Unicode chars for non-equality
  594. // pwsz : input char to the string of Unicode chars
  595. // acs : input reference to the AcString
  596. bool operator != (const wchar_t *pwsz, const AcString & acs);
  597. // Return whether a Unicode char is greater than an AcString
  598. // wch : input char to compare
  599. // acs : input reference to the AcString
  600. bool operator > (wchar_t wch, const AcString & acs);
  601. // Return whether a string of chars is greater than an AcString
  602. // psz : input pointer to the string of chars
  603. // acs : input reference to the AcString
  604. bool operator > (const char *psz, const AcString & acs);
  605. // Return whether a string of Unicode chars is greater than an AcString
  606. // pwsz : input pointer to the string of Unicode chars
  607. // acs : input reference to the AcString
  608. bool operator > (const wchar_t *pwsz, const AcString & acs);
  609. // Check for a Unicode char being greater than or equal to an AcString
  610. // wch : input char to compare
  611. // acs : input reference to the AcString
  612. bool operator >= (wchar_t wch, const AcString & acs);
  613. // Check for a string of chars being greater than or equal to an AcString
  614. // psz : input char to compare
  615. // acs : input reference to the AcString
  616. bool operator >= (const char *psz, const AcString & acs);
  617. // Check for a string of Unicode chars being greater than/equal to an AcString
  618. // pwsz : input char to compare
  619. // acs : input reference to the AcString
  620. bool operator >= (const wchar_t *pwsz, const AcString & acs);
  621. // Check for a Unicode char being less than an AcString
  622. // wch : input char to compare
  623. // acs : input reference to the AcString
  624. bool operator < (wchar_t wch, const AcString & acs);
  625. // Check for a string of chars being less than an AcString
  626. // psz : input char to compare
  627. // acs : input reference to the AcString
  628. bool operator < (const char *psz, const AcString & acs);
  629. // Check for a string of Unicode chars being less than an AcString
  630. // pwsz : input char to compare
  631. // acs : input reference to the AcString
  632. bool operator < (const wchar_t *pwsz, const AcString & acs);
  633. // Check for a Unicode char being less than or equal to an AcString
  634. // wch : input char to compare
  635. // acs : input reference to the AcString
  636. bool operator <= (wchar_t wch, const AcString & acs);
  637. // Check for a string of chars being less than or equal to an AcString
  638. // psz : input char to compare
  639. // acs : input reference to the AcString
  640. bool operator <= (const char *psz, const AcString & acs);
  641. // Check for a string of Unicode chars being less than/equal to an AcString
  642. // pwsz : input char to compare
  643. // acs : input reference to the AcString
  644. bool operator <= (const wchar_t *pwsz, const AcString & acs);
  645. // Copy an AcString and insert a Unicode char in front of it
  646. // wch : input char to insert
  647. AcString operator + (wchar_t wch, const AcString & acs);
  648. // Copy an AcString and insert a string of chars in front of it
  649. // psz : input pointer to the string of chars to insert
  650. AcString operator + (const char *psz, const AcString & acs);
  651. // Copy an AcString and insert a string of Unicode chars in front of it
  652. // pwsz : input pointer to the string of chars to insert
  653. AcString operator + (const wchar_t *pwsz, const AcString & acs);
  654. #if defined(_AFX) || defined(__ATLSTR_H__)
  655. // Compare a CStringW for equality with an AcString
  656. // csw : input reference to the CStringW
  657. // acs : input reference to the AcString
  658. bool operator == (const CStringW & csw, const AcString & acs);
  659. // Compare a CStringW for in-equality with an AcString
  660. // csw : input reference to the CStringW
  661. // acs : input reference to the AcString
  662. bool operator != (const CStringW & csw, const AcString & acs);
  663. // Compare a CStringW for greater than an AcString
  664. // csw : input reference to the CStringW
  665. // acs : input reference to the AcString
  666. bool operator > (const CStringW & csw, const AcString & acs);
  667. // Compare a CStringW for greater than or equal to an AcString
  668. // csw : input reference to the CStringW
  669. // acs : input reference to the AcString
  670. bool operator >= (const CStringW & csw, const AcString & acs);
  671. // Compare a CStringW for less than an AcString
  672. // csw : input reference to the CStringW
  673. // acs : input reference to the AcString
  674. bool operator < (const CStringW & csw, const AcString & acs);
  675. // Compare a CStringW for less than or equal to an AcString
  676. // csw : input reference to the CStringW
  677. // acs : input reference to the AcString
  678. bool operator <= (const CStringW & csw, const AcString & acs);
  679. #define DISABLE_CSTRING_PLUS_ACSTRING 1
  680. #ifndef DISABLE_CSTRING_PLUS_ACSTRING
  681. // For now, these are disabled to avoid ambiguities. If someone
  682. // says CString cs = CString("a") + "b", then the "b" could get
  683. // implicitly converted into an AcString or a CString, so it
  684. // won't compile.
  685. //
  686. AcString operator + (const CStringW & csw, const AcString & acs);
  687. #endif
  688. #endif
  689. // Accessing inlines
  690. //
  691. // Deprecated. Please use ansiPtr() or utf8Ptr()
  692. //
  693. inline const char * AcString::kszPtr() const
  694. {
  695. return this->ansiPtr();
  696. }
  697. inline AcString::operator const wchar_t *() const
  698. {
  699. return this->kwszPtr();
  700. }
  701. #ifdef UNICODE
  702. inline const wchar_t * AcString::constPtr() const
  703. {
  704. return this->kwszPtr();
  705. }
  706. inline const wchar_t * AcString::kTCharPtr() const
  707. {
  708. return this->kwszPtr();
  709. }
  710. // This method only supported for apps built in same way as acad.
  711. inline unsigned AcString::tcharLength() const
  712. {
  713. return this->length();
  714. }
  715. #elif _UNICODE
  716. #error "Unexpected _UNICODE definition"
  717. #else
  718. inline const char * AcString::constPtr() const
  719. {
  720. return this->kszPtr();
  721. }
  722. inline const char * AcString::kTCharPtr() const
  723. {
  724. return this->kszPtr();
  725. }
  726. #endif
  727. inline const ACHAR * AcString::kACharPtr() const
  728. {
  729. #if defined (_ADESK_WINDOWS_)
  730. return this->kwszPtr();
  731. #else
  732. return (const ACHAR*)this->kwszPtr();
  733. #endif
  734. }
  735. inline void AcString::clearAll()
  736. {
  737. this->mnFlags = 0;
  738. this->mchr.mnPad1 = 0;
  739. this->mchr.mwszStr[0] = 0;
  740. this->mptr.mpszData = nullptr;
  741. }
  742. // Searching inlines
  743. //
  744. inline int AcString::find(ACHAR ch) const
  745. {
  746. const ACHAR str[2] = {ch, '\0'};
  747. return this->findOneOf(str);
  748. }
  749. inline int AcString::findRev(ACHAR ch) const
  750. {
  751. const ACHAR str[2] = {ch, '\0'};
  752. return this->findOneOfRev(str);
  753. }
  754. // Extraction inlines
  755. //
  756. inline AcString AcString::mid(int nStart, int nNumChars) const
  757. {
  758. return this->substr(nStart, nNumChars);
  759. }
  760. inline AcString AcString::substr(int nNumChars) const
  761. {
  762. return this->substr(0, nNumChars);
  763. }
  764. // Assignment inlines
  765. //
  766. inline AcString & AcString::assign(char ch)
  767. {
  768. const char str[2] = {ch, '\0'};
  769. return this->assign(str);
  770. }
  771. inline AcString & AcString::assign(wchar_t wch)
  772. {
  773. const wchar_t wstr[2] = {wch, L'\0'};
  774. return this->assign(wstr);
  775. }
  776. inline AcString & AcString::operator = (char ch)
  777. {
  778. return this->assign(ch);
  779. }
  780. inline AcString & AcString::operator = (wchar_t wch)
  781. {
  782. return this->assign(wch);
  783. }
  784. inline AcString & AcString::operator = (const char *psz)
  785. {
  786. return this->assign(psz);
  787. }
  788. inline AcString & AcString::operator = (const wchar_t *pwsz)
  789. {
  790. return this->assign(pwsz);
  791. }
  792. inline AcString & AcString::operator = (const AcString & acs)
  793. {
  794. return this->assign(acs);
  795. }
  796. inline AcString & AcString::operator = (const AcDbHandle & h)
  797. {
  798. return this->assign(h);
  799. }
  800. // Modifying inlines
  801. //
  802. inline AcString & AcString::operator += (char ch)
  803. {
  804. return this->append(ch);
  805. }
  806. inline AcString & AcString::operator += (wchar_t wch)
  807. {
  808. return this->append(wch);
  809. }
  810. inline AcString & AcString::operator += (const char *psz)
  811. {
  812. return this->append(psz);
  813. }
  814. inline AcString & AcString::operator += (const wchar_t *pwsz)
  815. {
  816. return this->append(pwsz);
  817. }
  818. inline AcString & AcString::operator += (const AcString & acs)
  819. {
  820. return this->append(acs);
  821. }
  822. inline AcString & AcString::append(char ch)
  823. {
  824. const char str[2] = {ch, '\0'};
  825. return this->append(str);
  826. }
  827. inline AcString & AcString::append(wchar_t wch)
  828. {
  829. const wchar_t wstr[2] = {wch, L'\0'};
  830. return this->append(wstr);
  831. }
  832. // Concatenation inlines
  833. inline AcString AcString::operator + (char ch) const
  834. {
  835. return this->concat(ch);
  836. }
  837. inline AcString AcString::operator + (wchar_t wch) const
  838. {
  839. return this->concat(wch);
  840. }
  841. inline AcString AcString::operator + (const char * psz) const
  842. {
  843. return this->concat(psz);
  844. }
  845. inline AcString AcString::operator + (const wchar_t * pwsz) const
  846. {
  847. return this->concat(pwsz);
  848. }
  849. inline AcString AcString::operator + (const AcString & acs) const
  850. {
  851. return this->concat(acs);
  852. }
  853. inline AcString AcString::concat(char ch) const
  854. {
  855. const char str[2] = {ch, '\0'};
  856. return this->concat(str);
  857. }
  858. inline AcString AcString::concat(wchar_t wch) const
  859. {
  860. const wchar_t wstr[2] = {wch, L'\0'};
  861. return this->concat(wstr);
  862. }
  863. inline AcString AcString::precat(ACHAR ch) const
  864. {
  865. const ACHAR str[2] = {ch, '\0'};
  866. return this->precat(str);
  867. }
  868. // Comparison inlines
  869. //
  870. inline int AcString::compare(wchar_t wch) const
  871. {
  872. const wchar_t wstr[2] = {wch, L'\0'};
  873. return this->compare(wstr);
  874. }
  875. inline int AcString::compareNoCase(wchar_t wch) const
  876. {
  877. const wchar_t wstr[2] = {wch, L'\0'};
  878. return this->compareNoCase(wstr);
  879. }
  880. inline bool AcString::operator == (wchar_t wch) const
  881. {
  882. return this->compare(wch) == 0;
  883. }
  884. inline bool AcString::operator == (const char *psz) const
  885. {
  886. return this->compare(psz) == 0;
  887. }
  888. inline bool AcString::operator == (const wchar_t *pwsz) const
  889. {
  890. return this->compare(pwsz) == 0;
  891. }
  892. inline bool AcString::operator == (const AcString & acs) const
  893. {
  894. return this->compare(acs) == 0;
  895. }
  896. inline bool AcString::operator != (wchar_t wch) const
  897. {
  898. return this->compare(wch) != 0;
  899. }
  900. inline bool AcString::operator != (const char *psz) const
  901. {
  902. return this->compare(psz) != 0;
  903. }
  904. inline bool AcString::operator != (const wchar_t *pwsz) const
  905. {
  906. return this->compare(pwsz) != 0;
  907. }
  908. inline bool AcString::operator != (const AcString & acs) const
  909. {
  910. return this->compare(acs) != 0;
  911. }
  912. inline bool AcString::operator > (wchar_t wch) const
  913. {
  914. return this->compare(wch) > 0;
  915. }
  916. inline bool AcString::operator > (const char *psz) const
  917. {
  918. return this->compare(psz) > 0;
  919. }
  920. inline bool AcString::operator > (const wchar_t *pwsz) const
  921. {
  922. return this->compare(pwsz) > 0;
  923. }
  924. inline bool AcString::operator > (const AcString & acs) const
  925. {
  926. return this->compare(acs) > 0;
  927. }
  928. inline bool AcString::operator >= (wchar_t wch) const
  929. {
  930. return this->compare(wch) >= 0;
  931. }
  932. inline bool AcString::operator >= (const char *psz) const
  933. {
  934. return this->compare(psz) >= 0;
  935. }
  936. inline bool AcString::operator >= (const wchar_t *pwsz) const
  937. {
  938. return this->compare(pwsz) >= 0;
  939. }
  940. inline bool AcString::operator >= (const AcString & acs) const
  941. {
  942. return this->compare(acs) >= 0;
  943. }
  944. inline bool AcString::operator < (wchar_t wch) const
  945. {
  946. return this->compare(wch) < 0;
  947. }
  948. inline bool AcString::operator < (const char *psz) const
  949. {
  950. return this->compare(psz) < 0;
  951. }
  952. inline bool AcString::operator < (const wchar_t *pwsz) const
  953. {
  954. return this->compare(pwsz) < 0;
  955. }
  956. inline bool AcString::operator < (const AcString & acs) const
  957. {
  958. return this->compare(acs) < 0;
  959. }
  960. inline bool AcString::operator <= (char ch) const
  961. {
  962. return this->compare(ch) <= 0;
  963. }
  964. inline bool AcString::operator <= (wchar_t wch) const
  965. {
  966. return this->compare(wch) <= 0;
  967. }
  968. inline bool AcString::operator <= (const char *psz) const
  969. {
  970. return this->compare(psz) <= 0;
  971. }
  972. inline bool AcString::operator <= (const wchar_t *pwsz) const
  973. {
  974. return this->compare(pwsz) <= 0;
  975. }
  976. inline bool AcString::operator <= (const AcString & acs) const
  977. {
  978. return this->compare(acs) <= 0;
  979. }
  980. // We can do inline operators that deal with CStrings, without getting
  981. // into binary format dependencies. Don't make these out-of-line
  982. // functions, because then we'll have a dependency between our
  983. // components and CString-using clients.
  984. //
  985. #if defined(_AFX) || defined(_ADESK_MAC_) || defined(__ATLSTR_H__)
  986. inline AcString::AcString(const CStringW &csw)
  987. {
  988. const wchar_t *pwsz = (const wchar_t *)csw;
  989. this->clearAll();
  990. *this = pwsz;
  991. }
  992. inline AcString & AcString::operator=(const CStringW &csw)
  993. {
  994. const wchar_t *pwsz = (const wchar_t *)csw;
  995. return this->assign(pwsz);
  996. }
  997. inline AcString & AcString::operator+=(const CStringW &csw)
  998. {
  999. const wchar_t *pwsz = (const wchar_t *)csw;
  1000. return this->append(pwsz);
  1001. }
  1002. inline int AcString::compare(const CStringW & csw) const
  1003. {
  1004. const wchar_t *pwsz = (const wchar_t *)csw;
  1005. return this->compare(pwsz);
  1006. }
  1007. inline int AcString::compareNoCase(const CStringW & csw) const
  1008. {
  1009. const wchar_t *pwsz = (const wchar_t *)csw;
  1010. return this->compareNoCase(pwsz);
  1011. }
  1012. inline int AcString::match(const CStringW & csw) const
  1013. {
  1014. const wchar_t *pwsz = (const wchar_t *)csw;
  1015. return this->match(pwsz);
  1016. }
  1017. inline int AcString::matchNoCase(const CStringW & csw) const
  1018. {
  1019. const wchar_t *pwsz = (const wchar_t *)csw;
  1020. return this->matchNoCase(pwsz);
  1021. }
  1022. inline bool AcString::operator == (const CStringW & csw) const
  1023. {
  1024. return this->compare(csw) == 0;
  1025. }
  1026. inline bool AcString::operator != (const CStringW & csw) const
  1027. {
  1028. return this->compare(csw) != 0;
  1029. }
  1030. inline bool AcString::operator > (const CStringW & csw) const
  1031. {
  1032. return this->compare(csw) > 0;
  1033. }
  1034. inline bool AcString::operator >= (const CStringW & csw) const
  1035. {
  1036. return this->compare(csw) >= 0;
  1037. }
  1038. inline bool AcString::operator < (const CStringW & csw) const
  1039. {
  1040. return this->compare(csw) < 0;
  1041. }
  1042. inline bool AcString::operator <= (const CStringW & csw) const
  1043. {
  1044. return this->compare(csw) <= 0;
  1045. }
  1046. #endif
  1047. #ifdef _AFX
  1048. // Global CString-related operators
  1049. inline bool operator == (const CStringW & csw, const AcString & acs)
  1050. {
  1051. return acs.compare(csw) == 0;
  1052. }
  1053. inline bool operator != (const CStringW & csw, const AcString & acs)
  1054. {
  1055. return acs.compare(csw) != 0;
  1056. }
  1057. inline bool operator > (const CStringW & csw, const AcString & acs)
  1058. {
  1059. return acs.compare(csw) < 0;
  1060. }
  1061. inline bool operator >= (const CStringW & csw, const AcString & acs)
  1062. {
  1063. return acs.compare(csw) <= 0;
  1064. }
  1065. inline bool operator < (const CStringW & csw, const AcString & acs)
  1066. {
  1067. return acs.compare(csw) > 0;
  1068. }
  1069. inline bool operator <= (const CStringW & csw, const AcString & acs)
  1070. {
  1071. return acs.compare(csw) >= 0;
  1072. }
  1073. #ifndef DISABLE_CSTRING_PLUS_ACSTRING
  1074. inline AcString operator + (const CStringW & csw, const AcString & acs)
  1075. {
  1076. const wchar_t *pwsz = (const wchar_t *)csw;
  1077. return acs.precat(pwsz);
  1078. }
  1079. #endif
  1080. #endif // _AFX
  1081. // Inline global operators
  1082. inline bool operator == (wchar_t wch, const AcString & acs)
  1083. {
  1084. return acs.compare(wch) == 0;
  1085. }
  1086. inline bool operator == (const char *psz, const AcString & acs)
  1087. {
  1088. return acs.compare(psz) == 0;
  1089. }
  1090. inline bool operator == (const wchar_t *pwsz, const AcString & acs)
  1091. {
  1092. return acs.compare(pwsz) == 0;
  1093. }
  1094. inline bool operator != (wchar_t wch, const AcString & acs)
  1095. {
  1096. return acs.compare(wch) != 0;
  1097. }
  1098. inline bool operator != (const char *psz, const AcString & acs)
  1099. {
  1100. return acs.compare(psz) != 0;
  1101. }
  1102. inline bool operator != (const wchar_t *pwsz, const AcString & acs)
  1103. {
  1104. return acs.compare(pwsz) != 0;
  1105. }
  1106. inline bool operator > (wchar_t wch, const AcString & acs)
  1107. {
  1108. return acs.compare(wch) < 0;
  1109. }
  1110. inline bool operator > (const char *psz, const AcString & acs)
  1111. {
  1112. return acs.compare(psz) < 0;
  1113. }
  1114. inline bool operator > (const wchar_t *pwsz, const AcString & acs)
  1115. {
  1116. return acs.compare(pwsz) < 0;
  1117. }
  1118. inline bool operator >= (wchar_t wch, const AcString & acs)
  1119. {
  1120. return acs.compare(wch) <= 0;
  1121. }
  1122. inline bool operator >= (const char *psz, const AcString & acs)
  1123. {
  1124. return acs.compare(psz) <= 0;
  1125. }
  1126. inline bool operator >= (const wchar_t *pwsz, const AcString & acs)
  1127. {
  1128. return acs.compare(pwsz) <= 0;
  1129. }
  1130. inline bool operator < (wchar_t wch, const AcString & acs)
  1131. {
  1132. return acs.compare(wch) > 0;
  1133. }
  1134. inline bool operator < (const char *psz, const AcString & acs)
  1135. {
  1136. return acs.compare(psz) > 0;
  1137. }
  1138. inline bool operator < (const wchar_t *pwsz, const AcString & acs)
  1139. {
  1140. return acs.compare(pwsz) > 0;
  1141. }
  1142. inline bool operator <= (wchar_t wch, const AcString & acs)
  1143. {
  1144. return acs.compare(wch) >= 0;
  1145. }
  1146. inline bool operator <= (const char *psz, const AcString & acs)
  1147. {
  1148. return acs.compare(psz) >= 0;
  1149. }
  1150. inline bool operator <= (const wchar_t *pwsz, const AcString & acs)
  1151. {
  1152. return acs.compare(pwsz) >= 0;
  1153. }
  1154. // These don't modify the AcString. They return a copy.
  1155. inline AcString operator + (ACHAR ch, const AcString & acs)
  1156. {
  1157. return acs.precat(ch);
  1158. }
  1159. inline AcString operator + (const char *psz, const AcString & acs)
  1160. {
  1161. return acs.precat(psz);
  1162. }
  1163. inline AcString operator + (const wchar_t *pwsz, const AcString & acs)
  1164. {
  1165. return acs.precat(pwsz);
  1166. }
  1167. // Return a unique identifier (pointer) for the input string, to allow fast compares
  1168. // Strings containing the exact same chars will return the same AcUniqueString
  1169. // AcUniqueString pointers are valid for the process's lifetime
  1170. //
  1171. class AcUniqueString
  1172. {
  1173. public:
  1174. ACBASE_PORT static const AcUniqueString *Intern(const wchar_t *);
  1175. };
  1176. #endif // !_Ac_String_h