123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476 |
- //
- //////////////////////////////////////////////////////////////////////////////
- //
- // Copyright 2015 Autodesk, Inc. All rights reserved.
- //
- // Use of this software is subject to the terms of the Autodesk license
- // agreement provided at the time of installation or download, or which
- // otherwise accompanies this software in either electronic or hard copy form.
- //
- //////////////////////////////////////////////////////////////////////////////
- #ifndef _Ac_String_h_
- #define _Ac_String_h_
- #include "acbasedefs.h"
- #include "adesk.h"
- #include "AcHeapOpers.h"
- #include "AdAChar.h"
- #pragma pack (push, 1)
- class AcDbHandle;
- // Notes:
- // 1. All "char" arguments are assumed to be ansi codes in the current
- // code page, unless otherwise specified to be utf-8.
- //
- // 2. In places where a single (ansi) char value is passed, the value
- // cannot be a leading byte of a double-byte char, except
- // where noted.
- //
- // 3. All wchar_t arguments are assumed to be "widechar" Unicode values.
- //
- // 4. Many methods and operators taking ansi (const char *) arguments may
- // be phased out in the future. Clients should use Unicode strings.
- //
- class AcString : public AcHeapOperators
- {
- public:
- //
- // Constructors and destructor
- //
- // Default ctor, initializes to empty string.
- ACBASE_PORT AcString();
- // Initialize with a single character.
- // ch : input (ansi) character
- ACBASE_PORT AcString(char ch);
- // Initialize with a single Unicode character
- // wch : input character
- ACBASE_PORT AcString(wchar_t wch);
- // Initialize from an ansi or utf-8 string.
- // psz : input pointer to source string.
- ACBASE_PORT AcString(const char *psz, bool bUtf8 = false);
- // Initialize from a Unicode string
- // wpsz : input pointer to source string
- ACBASE_PORT AcString(const wchar_t *pwsz);
- // Copy constructor
- // acs : input reference to an existing AcString object
- ACBASE_PORT AcString(const AcString & acs);
- // Values for the nCtorFlags arg of the following constructor
- enum {
- kAppRes = 0x0001, // use app's default resource dll
- kSigned = 0x0002, // format the arg as signed int
- kUnSigned = 0x0003, // format the arg as unsigned int
- kHex = 0x0004 // format the arg as hex
- };
- // Multi-purpose constructor, takes an unsigned argument and
- // uses it either to load a resource string or to create a
- // numerical string (base 10 or hex).
- //
- // nCtorFlags : input flags, indicating type of construction
- // nArg : input argument value, interpreted according to flags
- ACBASE_PORT AcString(int nCtorFlags, unsigned nArg);
- // Formats an AcDbHandle value in hex, as in: "a2f".
- // h : input reference to an acdb handle value
- ACBASE_PORT AcString(const AcDbHandle &h);
- #if defined(_WINBASE_) || defined(_ADESK_MAC_)
- // Loads a resource string from the specified dll handle.
- // hDll : input windows handle to a loaded resource dll
- // nId : input int id of the resource string to load
- ACBASE_PORT AcString(HINSTANCE hDll, unsigned nId);
- #endif
- // Destructor: frees up memory.
- ACBASE_PORT ~AcString();
- //
- // Querying methods
- //
- // Get a pointer to the current string (code page based). This
- // pointer is only valid until the AcString object is next modified!
- ACBASE_PORT const char * ansiPtr() const;
- // Deprecated. Please use ansiPtr() or utf8Ptr() instead
- const char * kszPtr() const;
- // Get a pointer to the current string as Unicode UTF-8. This
- // pointer is only valid until the AcString object is modified!
- ACBASE_PORT const char * utf8Ptr() const;
- // Get a pointer to the current string (in Unicode). This pointer
- // is only valid until this AcString object is next modified!
- ACBASE_PORT const wchar_t * kwszPtr() const;
- // Get a pointer to the current string as a TCHAR pointer.
- // Pointer is only valid until this AcString is next modified.
- #ifdef UNICODE
- const wchar_t * constPtr() const;
- const wchar_t * kTCharPtr() const;
- #else
- const char * constPtr() const;
- const char * kTCharPtr() const;
- #endif
- // Get a pointer to the current string in ACHARs.
- const ACHAR * kACharPtr() const;
- // Get a pointer to the current string (in Unicode). Pointer
- // is valid only until this AcString is next modified.
- operator const wchar_t * () const;
- // Test whether the current string value is empty. I.e.,
- // logical length is zero.
- ACBASE_PORT bool isEmpty() const;
- // Return logical length of (i.e. number of characters in) the string.
- //
- ACBASE_PORT unsigned length() const;
- // Return length of the current string, in TCHAR units.
- // Deprecated. Please use length() instead
- unsigned tcharLength() const;
- // Returns true if all chars are in the ascii range: 0x20..0x7f
- ACBASE_PORT bool isAscii() const;
- //
- // Parsing methods.
- //
- enum {
- // Enum value allowing caller to specify how to handle errors
- // (invalid chars or overflow) during string parsing.
- kParseZero = 0, // return zero on errors
- kParseMinus1 = 0x01, // return -1 or ffff
- kParseAssert = 0x02, // pop an assert in debug build
- kParseExcept = 0x04, // throw an int exception
- kParseNoEmpty = 0x08, // treat empty string as error
- kParseDefault = (kParseAssert | kParseZero)
- };
- // Parse the current string as decimal, return a signed int
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT int asDeci(int nFlags = kParseDefault) const;
- // Parse the current string as hexadecimal, return a signed int
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT int asHex (int nFlags = kParseDefault) const;
- // Parse the current string as decimal, return an unsigned int
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT unsigned int asUDeci(int nFlags = kParseDefault) const;
- // Parse the current string as hexadecimal, return an unsigned int
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT unsigned int asUHex (int nFlags = kParseDefault) const;
- // Parse the current string as decimal, return a signed int64
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT __int64 asDeci64(int nFlags = kParseDefault) const;
- // Parse the current string as hexadecimal, return a signed int64
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT __int64 asHex64 (int nFlags = kParseDefault) const;
- // Parse the current string as decimal, return an unsigned int64
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT Adesk::UInt64 asUDeci64(int nFlags = kParseDefault) const;
- // Parse the current string as hexadecimal, return an unsigned int64
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT Adesk::UInt64 asUHex64 (int nFlags = kParseDefault) const;
- // Parse the current string as hexadecimal. Return the handle.
- // nFlags : input bits specifying how to do the parsing
- ACBASE_PORT AcDbHandle asAcDbHandle(int nFlags = kParseDefault) const;
- //
- // Find char/string/one of a string of chars, from front or back
- // Return the position (index) at which the character or substring
- // was found.
- //
- // The find methods which start at the end of the string return
- // an index relative to the front of the string.
- // Find a single char in the string.
- // ch : input char to search for
- int find(ACHAR ch) const;
- // Find a substring in the string
- // psz : input string to search for
- ACBASE_PORT int find(const ACHAR *psz) const;
- // Find an AcString in the string.
- // acs : input string object to search for
- ACBASE_PORT int find(const AcString & acs) const;
- // Find any of a group of chars in the string.
- // psz : input pointer to string of chars to search for
- ACBASE_PORT int findOneOf(const ACHAR *psz) const;
- // Find last occurrence of a char in the string
- // ch : input char to search for
- int findRev(ACHAR ch) const;
- // Find last occurrence of any of a group of chars in the string
- // psz : input pointer to string of chars to search for
- ACBASE_PORT int findRev(const ACHAR *psz) const;
- // Find last occurrence of a group of chars in the string
- // psz : input ptr to the string of chars to search for
- ACBASE_PORT int findOneOfRev(const ACHAR *psz) const;
- // Find last occurrence of a string in the string
- // acs : input reference to the string to search for
- ACBASE_PORT int findRev(const AcString & acs) const;
- //
- // Extraction methods
- // Note: mid() and substr() are the same thing - we define both
- // for compatibility with CString and std::string
- //
- // The input index arguments are byte indices into the string.
- // Get a substring from the string. (same as substr() method)
- // nStart : input index (in bytes) from the start of the string
- // nNumChars : input number of chars (not bytes) to retrieve.
- // if nNumChars is -1, then return the rest of the string
- AcString mid(int nStart, int nNumChars) const;
- // Get a substring from the start of string.
- // nNumChars : input number of chars (not bytes) to retrieve.
- // if nNumChars is -1, then return the rest of the string
- AcString substr(int numChars) const;
- // Get a substring from the string. (same as mid() method)
- // nStart : input index (in bytes) from the start of the string
- // nNumChars : input number of chars (not bytes) to retrieve.
- // if nNumChars is -1, then return the rest of the string
- ACBASE_PORT AcString substr(int nStart, int nNumChars) const;
- // Get a substring from the end of string.
- // nNumChars : input number of chars (not bytes) to retrieve.
- ACBASE_PORT AcString substrRev(int numChars) const;
- //
- // Assignment operators and methods
- //
- // assign a char to the string
- // ch : input (ansi) char to assign
- AcString & assign(char ch);
- // assign a Unicode char to the string
- // wch : input char to assign
- AcString & assign(wchar_t wch);
- // assign a string of (ansi) chars to the string
- // psz : input pointer to the string of chars to assign
- ACBASE_PORT AcString & assign(const char *psz);
- // assign a string of Unicode chars to the string
- // pwsz : input pointer to the string of chars to assign
- ACBASE_PORT AcString & assign(const wchar_t *pwsz);
- // assign an AcString object to the string
- // acs : input reference to the AcString
- ACBASE_PORT AcString & assign(const AcString & acs);
- // assign an AcDbHandle object to the string (format it as hex)
- // h : input reference to the AcDbHandle object
- ACBASE_PORT AcString & assign(const AcDbHandle & h);
- // assign a char to the string
- // ch : input (ansi) char to assign
- AcString & operator = (char ch);
- // assign a Unicode char to the string
- // wch : input char to assign
- AcString & operator = (wchar_t wch);
- // assign a string of (ansi) chars to the string
- // psz : input pointer to the string of chars to assign
- AcString & operator = (const char *psz);
- // assign a string of Unicode chars to the string
- // pwsz : input pointer to the string of chars to assign
- AcString & operator = (const wchar_t *pwsz);
- // assign an AcString object to the string
- // acs : input reference to the AcString
- AcString & operator = (const AcString & acs);
- // assign an AcDbHandle object to the string (format it as hex)
- // h : input reference to the AcDbHandle object
- AcString & operator = (const AcDbHandle & h);
- // Set the string to be empty.
- ACBASE_PORT AcString & setEmpty();
- // Set the string from a resource string
- // nId : input id of the string resource in the current mfc resource dll
- ACBASE_PORT bool loadString(unsigned nId);
- #if defined(_WINBASE_) || defined(_ADESK_MAC_)
- // Set the string from a resource string
- // hDll : input windows handle to a loaded resource dll
- // nId : input id of the string resource in the specified resource dll
- ACBASE_PORT bool loadString(HINSTANCE hDll, unsigned nId);
- #endif
- // Format the string using "printf" rules.
- // pszFmt : input pointer to the printf format string
- ACBASE_PORT void format (const ACHAR *pszFmt, ...);
- // Format the string using "printf" rules
- // pszFmt : input pointer to the printf format string
- // args : input variable args list, containing values to be formatted
- ACBASE_PORT void formatV(const ACHAR *pszFmt, va_list args);
- //
- // Modifying operators and methods
- //
- // append an ansi char to the end of the string
- // ch : input (ansi) char to append
- AcString & operator += (char ch);
- // append a Unicode char to the end of the string
- // wch : input char to append
- AcString & operator += (wchar_t wch);
- // append a char string to the end of the string
- // psz : input pointer to the (ansi) char string
- AcString & operator += (const char * psz);
- // append a Unicode string to the end of the string
- // pwsz : input pointer to the Unicode string
- AcString & operator += (const wchar_t * pwsz);
- // append an AcString object to the end of the string
- // acs : input reference to the AcString
- AcString & operator += (const AcString & acs);
- // append an ansi char to the end of the string
- // ch : input char to append
- AcString & append(char ch);
- // append a Unicode char to the end of the string
- // wch : input char to append
- AcString & append(wchar_t wch);
- // append a char string to the end of the string
- // psz : input pointer to the (ansi) char string
- ACBASE_PORT AcString & append(const char *psz);
- // append a Unicode string to the end of the string
- // pwsz : input pointer to the Unicode string
- ACBASE_PORT AcString & append(const wchar_t *pwsz);
- // append an AcString object to the end of the string
- // acs : input reference to the AcString
- ACBASE_PORT AcString & append(const AcString & acs);
- // Catenation operators and methods These are like append,
- // but they do not modify the current string. They return a
- // new combined string.
- // Copy the string and append a char to it
- // ch : input (ansi) char to append to the string copy
- AcString operator + (char ch) const;
- // Copy the string and append a Unicode char to it
- // ch : input char to append to the string copy
- AcString operator + (wchar_t wch) const;
- // Copy the string and append a string of chars to it
- // psz : input pointer to the (ansi) string to append
- AcString operator + (const char * psz) const;
- // Copy the string and append a string of Unicode chars to it
- // pwsz : input pointer to the string to append
- AcString operator + (const wchar_t * pwsz) const;
- // Copy the string and append an AcString to it
- // pwsz : input reference to the AcString to append
- AcString operator + (const AcString & acs) const;
- // Copy the string and append a char to it
- // ch : input (ansi) char to append to the string copy
- AcString concat(char ch) const;
- // Copy the string and append a Unicode char to it
- // ch : input char to append to the string copy
- AcString concat(wchar_t wch) const;
- // Copy the string and append a string of chars to it
- // psz : input pointer to the (ansi) string to append
- ACBASE_PORT AcString concat(const char * psz) const;
- // Copy the string and append a string of Unicode chars to it
- // pwsz : input pointer to the string to append
- ACBASE_PORT AcString concat(const wchar_t * pwsz) const;
- // Copy the string and append an AcString to it
- // pwsz : input reference to the AcString to append
- ACBASE_PORT AcString concat(const AcString & acs) const;
- // These copy the current string and then insert the char or
- // string in front of it. They're used by the global "+" operators.
- // Copy the string and insert a char in front of it
- // ch : input char to insert
- AcString precat(ACHAR ch) const;
- // Copy the string and insert a string of chars in front of it
- // psz : input pointer to the string of (ansi) chars to insert
- ACBASE_PORT AcString precat(const char * psz) const;
- // Copy the string and insert a string of chars in front of it
- // psz : input pointer to the string of chars to insert
- ACBASE_PORT AcString precat(const wchar_t * psz) const;
- //
- // Comparison operators and methods
- // The int return value is -1, 0 or 1, indicating <, == or >
- //
- // Compare the string to a single Unicode char
- // wch : input char to compare to
- int compare(wchar_t wch) const;
- // Compare the string to a string of (ansi) chars
- // psz : input pointer to the string of chars to compare to
- ACBASE_PORT int compare(const char *psz) const;
- // Compare the string to a string of Unicode chars
- // pwsz : input pointer to the string of chars to compare to
- ACBASE_PORT int compare(const wchar_t *pwsz) const;
- // Compare the string to a string of Unicode chars
- // acs : input reference of the other AcString to compare to
- ACBASE_PORT int compare(const AcString & acs) const;
- // Compare the string case-independently to a Unicode char
- // wch : input char to compare to
- int compareNoCase(wchar_t wch) const;
- // Compare the string case-independently to a string of chars
- // psz : input pointer to the string of (ansi) chars to compare to
- ACBASE_PORT int compareNoCase(const char *psz) const;
- // Compare the string case-independently to a string of Unicode chars
- // pwsz : input pointer to the string of chars to compare to
- ACBASE_PORT int compareNoCase(const wchar_t *pwsz) const;
- // Compare the string case-independently to another AcString
- // acs : input reference to the other AcString
- ACBASE_PORT int compareNoCase(const AcString & acs) const;
- // Compare the string for equality with a Unicode char
- // wch : input char to compare to
- bool operator == (wchar_t wch) const;
- // Compare the string for equality with a string of chars
- // psz : input pointer to the string of (ansi) chars
- bool operator == (const char *psz) const;
- // Compare the string for equality with a string of Unicode chars
- // pwsz : input pointer to the string of chars
- bool operator == (const wchar_t *pwsz) const;
- // Compare the string for equality with another AcString
- // acs : input reference to the other AcString
- bool operator == (const AcString & acs) const;
- // Compare the string for non-equality with a Unicode char
- // wch : input char to compare to
- bool operator != (wchar_t wch) const;
- // Compare the string for non-equality with a string of chars
- // psz : input pointer to the string of (ansi) chars
- bool operator != (const char *psz) const;
- // Compare the string for non-equality with a string of Unicode chars
- // pwsz : input pointer to the string of chars
- bool operator != (const wchar_t *pwsz) const;
- // Compare the string for non-equality with another AcString
- // acs : input reference to the other AcString
- bool operator != (const AcString & acs) const;
- // Compare the string for greater than a Unicode char
- // wch : input char to compare to
- bool operator > (wchar_t wch) const;
- // Compare the string for greater than a string of chars
- // psz : input pointer to the string of (ansi) chars to compare to
- bool operator > (const char *psz) const;
- // Compare the string for greater than a string of Unicode chars
- // pwsz : input pointer to the string of chars to compare to
- bool operator > (const wchar_t *pwsz) const;
- // Compare the string for greater than another AcString
- // acs : input reference to the other AcString
- bool operator > (const AcString & acs) const;
- // Compare the string for greater than or equal to a Unicode char
- // wch : input char to compare to
- bool operator >= (wchar_t wch) const;
- // Compare the string for greater than or equal to a string of chars
- // psz : input pointer to the string of (ansi) chars
- bool operator >= (const char *psz) const;
- // Compare the string for greater than/equal to a string of Unicode chars
- // pwsz : input pointer to the string of chars
- bool operator >= (const wchar_t *pwsz) const;
- // Compare the string for greater than or equal to another AcString
- // acs : input reference to the other AcString
- bool operator >= (const AcString & acs) const;
- // Compare the string for less than a Unicode char
- // wch : input char to compare to
- bool operator < (wchar_t wch) const;
- // Compare the string for less than a string of chars
- // psz : input pointer to the string of (ansi) chars to compare to
- bool operator < (const char *psz) const;
- // Compare the string for less than a string of Unicode chars
- // pwsz : input pointer to the string of chars to compare to
- bool operator < (const wchar_t *pwsz) const;
- // Compare the string for less than another AcString
- // acs : input reference to the other AcString
- bool operator < (const AcString & acs) const;
- // Compare the string for less than or equal to a char
- // ch : input (ansi) char to compare to
- bool operator <= (char ch) const;
- // Compare the string for less than or equal to a Unicode char
- // wch : input char to compare to
- bool operator <= (wchar_t wch) const;
- // Compare the string for less than or equal to a string of chars
- // psz : input pointer to the string of (ansi) chars
- bool operator <= (const char *psz) const;
- // Compare the string for less than/equal to a string of Unicode chars
- // pwsz : input pointer to the string of chars
- bool operator <= (const wchar_t *pwsz) const;
- // Compare the string for less or equal to than another AcString
- // acs : input reference to the other AcString
- bool operator <= (const AcString & acs) const;
- // The match() methods return how many chars (not bytes) match
- // between two strings. Not fully implemented yet (non-ascii
- // chars not supported yet).
- // Return the number of chars that match a string of chars
- // psz : input pointer to the string of (ansi) chars
- ACBASE_PORT int match(const char *psz) const;
- // Return the number of chars matching a string of Unicode chars
- // pwsz : input pointer to the string of chars
- ACBASE_PORT int match(const wchar_t *pwsz) const;
- // Return the number of chars matching another AcString
- // acs : input reference to the other AcString
- ACBASE_PORT int match(const AcString & acs) const;
- // Return number of chars case-independently matching a string of chars
- // psz : input pointer to the string of (ansi) chars
- ACBASE_PORT int matchNoCase(const char *psz) const;
- // Return number of chars case-indep'ly matching a string of Unicode chars
- // pwsz : input pointer to the string of chars
- ACBASE_PORT int matchNoCase(const wchar_t *pwsz) const;
- // Return number of chars case-indep'ly matching another AcString
- // acs : input reference to the other AcString
- ACBASE_PORT int matchNoCase(const AcString & acs) const;
- #if defined(_AFX) || defined (_ADESK_MAC_) || defined(__ATLSTR_H__)
- //
- // MFC CString-using methods. The CStringA class is the ansi
- // code page based CString, while CStringW is Unicode based.
- // CString maps to one or the other depending on whether the
- // UNICODE preprocessor symbol is defined.
- //
- // Construct an AcString from a CStringW
- // csw : input reference to the CStringW
- AcString(const CStringW &csw);
- // Initialize this AcString from a CStringW
- // csw : input reference to the CStringW
- AcString & operator = (const CStringW &csw);
- // Append a CStringW to this AcString
- // csa : input reference to the CStringW
- AcString & operator += (const CStringW &csw);
- // Compare this string to a CStringW
- // csw : input reference to the CStringW
- int compare(const CStringW & csw) const;
- // Compare this string case independently to a CStringW
- // csw : input reference to the CStringW
- int compareNoCase(const CStringW & csw) const;
- // Compare for equality with a CStringW
- // csw : input reference to the CStringW
- bool operator == (const CStringW & ) const;
- // Compare for non-equality with a CStringW
- // csw : input reference to the CStringW
- bool operator != (const CStringW & ) const;
- // Compare for less than a CStringW
- // csw : input reference to the CStringW
- bool operator < (const CStringW & ) const;
- // Compare for less than or equal to a CStringW
- // csw : input reference to the CStringW
- bool operator <= (const CStringW & ) const;
- // Compare for greater than a CStringW
- // csw : input reference to the CStringW
- bool operator > (const CStringW & ) const;
- // Compare for greater than or equal to a CStringW
- // csw : input reference to the CStringW
- bool operator >= (const CStringW & ) const;
- // Return number of chars matching a CStringW
- // csw : input reference to the CStringW
- int match(const CStringW & csw) const;
- // Return number of chars case-independently matching a CStringW
- // csw : input reference to the CStringW
- int matchNoCase(const CStringW & csw) const;
- // Note: unfortunately there is not now an assignment operator for
- // assigning AcStrings to CStrings, as in CString cs = AcString("x");
- #endif
- private:
- // size is 8 bytes in 32-bit build, 16 in 64-bit build.
- #if !defined(_WIN64) && !defined (_AC64)
- enum {
- #ifdef _ADESK_MAC_
- kObjSize = 14,
- #else
- kObjSize = 8,
- #endif
- kMbArrSize = 7,
- kUCArrSize = 3,
- kPadArrSize = 3
- };
- #else
- enum {
- #ifdef _ADESK_MAC_
- kObjSize = 30,
- #else
- kObjSize = 16,
- #endif
- kMbArrSize = 15,
- kUCArrSize = 7,
- kPadArrSize = 7
- };
- #endif
- void clearAll();
- struct PtrAndData;
- unsigned char mnFlags;
- union {
- struct {
- unsigned char mnPad2[kPadArrSize];
- union {
- wchar_t *mpwszData;
- char *mpszData;
- PtrAndData *mpPtrAndData;
- };
- }mptr;
- struct {
- unsigned char mnPad1;
- wchar_t mwszStr[kUCArrSize];
- }mchr;
- char mszStr[kMbArrSize];
- };
- friend class AcStringImp;
- };
- #ifdef AC_ACARRAY_H
- typedef
- AcArray< AcString, AcArrayObjectCopyReallocator< AcString > > AcStringArray;
- #endif
- #pragma pack (pop)
- //
- // Global operators
- //
- // Compare an AcString and a Unicode char for equality
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator == (wchar_t wch, const AcString & acs);
- // Compare an AcString and a string of chars char for equality
- // psz : input pointer to the string of chars
- // acs : input reference to the AcString
- bool operator == (const char *psz, const AcString & acs);
- // Compare an AcString and a string of Unicode chars for equality
- // pwsz : input char to the string of Unicode chars
- // acs : input reference to the AcString
- bool operator == (const wchar_t *pwsz, const AcString & acs);
- // Compare an AcString and a Unicode char for non-equality
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator != (wchar_t wch, const AcString & acs);
- // Compare an AcString and a string of chars char for non-equality
- // psz : input pointer to the string of chars
- // acs : input reference to the AcString
- bool operator != (const char *psz, const AcString & acs);
- // Compare an AcString and a string of Unicode chars for non-equality
- // pwsz : input char to the string of Unicode chars
- // acs : input reference to the AcString
- bool operator != (const wchar_t *pwsz, const AcString & acs);
- // Return whether a Unicode char is greater than an AcString
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator > (wchar_t wch, const AcString & acs);
- // Return whether a string of chars is greater than an AcString
- // psz : input pointer to the string of chars
- // acs : input reference to the AcString
- bool operator > (const char *psz, const AcString & acs);
- // Return whether a string of Unicode chars is greater than an AcString
- // pwsz : input pointer to the string of Unicode chars
- // acs : input reference to the AcString
- bool operator > (const wchar_t *pwsz, const AcString & acs);
- // Check for a Unicode char being greater than or equal to an AcString
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator >= (wchar_t wch, const AcString & acs);
- // Check for a string of chars being greater than or equal to an AcString
- // psz : input char to compare
- // acs : input reference to the AcString
- bool operator >= (const char *psz, const AcString & acs);
- // Check for a string of Unicode chars being greater than/equal to an AcString
- // pwsz : input char to compare
- // acs : input reference to the AcString
- bool operator >= (const wchar_t *pwsz, const AcString & acs);
- // Check for a Unicode char being less than an AcString
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator < (wchar_t wch, const AcString & acs);
- // Check for a string of chars being less than an AcString
- // psz : input char to compare
- // acs : input reference to the AcString
- bool operator < (const char *psz, const AcString & acs);
- // Check for a string of Unicode chars being less than an AcString
- // pwsz : input char to compare
- // acs : input reference to the AcString
- bool operator < (const wchar_t *pwsz, const AcString & acs);
- // Check for a Unicode char being less than or equal to an AcString
- // wch : input char to compare
- // acs : input reference to the AcString
- bool operator <= (wchar_t wch, const AcString & acs);
- // Check for a string of chars being less than or equal to an AcString
- // psz : input char to compare
- // acs : input reference to the AcString
- bool operator <= (const char *psz, const AcString & acs);
- // Check for a string of Unicode chars being less than/equal to an AcString
- // pwsz : input char to compare
- // acs : input reference to the AcString
- bool operator <= (const wchar_t *pwsz, const AcString & acs);
- // Copy an AcString and insert a Unicode char in front of it
- // wch : input char to insert
- AcString operator + (wchar_t wch, const AcString & acs);
- // Copy an AcString and insert a string of chars in front of it
- // psz : input pointer to the string of chars to insert
- AcString operator + (const char *psz, const AcString & acs);
- // Copy an AcString and insert a string of Unicode chars in front of it
- // pwsz : input pointer to the string of chars to insert
- AcString operator + (const wchar_t *pwsz, const AcString & acs);
- #if defined(_AFX) || defined(__ATLSTR_H__)
- // Compare a CStringW for equality with an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator == (const CStringW & csw, const AcString & acs);
- // Compare a CStringW for in-equality with an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator != (const CStringW & csw, const AcString & acs);
- // Compare a CStringW for greater than an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator > (const CStringW & csw, const AcString & acs);
- // Compare a CStringW for greater than or equal to an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator >= (const CStringW & csw, const AcString & acs);
- // Compare a CStringW for less than an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator < (const CStringW & csw, const AcString & acs);
- // Compare a CStringW for less than or equal to an AcString
- // csw : input reference to the CStringW
- // acs : input reference to the AcString
- bool operator <= (const CStringW & csw, const AcString & acs);
- #define DISABLE_CSTRING_PLUS_ACSTRING 1
- #ifndef DISABLE_CSTRING_PLUS_ACSTRING
- // For now, these are disabled to avoid ambiguities. If someone
- // says CString cs = CString("a") + "b", then the "b" could get
- // implicitly converted into an AcString or a CString, so it
- // won't compile.
- //
- AcString operator + (const CStringW & csw, const AcString & acs);
- #endif
- #endif
- // Accessing inlines
- //
- // Deprecated. Please use ansiPtr() or utf8Ptr()
- //
- inline const char * AcString::kszPtr() const
- {
- return this->ansiPtr();
- }
- inline AcString::operator const wchar_t *() const
- {
- return this->kwszPtr();
- }
- #ifdef UNICODE
- inline const wchar_t * AcString::constPtr() const
- {
- return this->kwszPtr();
- }
- inline const wchar_t * AcString::kTCharPtr() const
- {
- return this->kwszPtr();
- }
- // This method only supported for apps built in same way as acad.
- inline unsigned AcString::tcharLength() const
- {
- return this->length();
- }
- #elif _UNICODE
- #error "Unexpected _UNICODE definition"
- #else
- inline const char * AcString::constPtr() const
- {
- return this->kszPtr();
- }
- inline const char * AcString::kTCharPtr() const
- {
- return this->kszPtr();
- }
- #endif
- inline const ACHAR * AcString::kACharPtr() const
- {
- #if defined (_ADESK_WINDOWS_)
- return this->kwszPtr();
- #else
- return (const ACHAR*)this->kwszPtr();
- #endif
- }
- inline void AcString::clearAll()
- {
- this->mnFlags = 0;
- this->mchr.mnPad1 = 0;
- this->mchr.mwszStr[0] = 0;
- this->mptr.mpszData = nullptr;
- }
- // Searching inlines
- //
- inline int AcString::find(ACHAR ch) const
- {
- const ACHAR str[2] = {ch, '\0'};
- return this->findOneOf(str);
- }
- inline int AcString::findRev(ACHAR ch) const
- {
- const ACHAR str[2] = {ch, '\0'};
- return this->findOneOfRev(str);
- }
- // Extraction inlines
- //
- inline AcString AcString::mid(int nStart, int nNumChars) const
- {
- return this->substr(nStart, nNumChars);
- }
- inline AcString AcString::substr(int nNumChars) const
- {
- return this->substr(0, nNumChars);
- }
- // Assignment inlines
- //
- inline AcString & AcString::assign(char ch)
- {
- const char str[2] = {ch, '\0'};
- return this->assign(str);
- }
- inline AcString & AcString::assign(wchar_t wch)
- {
- const wchar_t wstr[2] = {wch, L'\0'};
- return this->assign(wstr);
- }
- inline AcString & AcString::operator = (char ch)
- {
- return this->assign(ch);
- }
- inline AcString & AcString::operator = (wchar_t wch)
- {
- return this->assign(wch);
- }
- inline AcString & AcString::operator = (const char *psz)
- {
- return this->assign(psz);
- }
- inline AcString & AcString::operator = (const wchar_t *pwsz)
- {
- return this->assign(pwsz);
- }
- inline AcString & AcString::operator = (const AcString & acs)
- {
- return this->assign(acs);
- }
- inline AcString & AcString::operator = (const AcDbHandle & h)
- {
- return this->assign(h);
- }
- // Modifying inlines
- //
- inline AcString & AcString::operator += (char ch)
- {
- return this->append(ch);
- }
- inline AcString & AcString::operator += (wchar_t wch)
- {
- return this->append(wch);
- }
- inline AcString & AcString::operator += (const char *psz)
- {
- return this->append(psz);
- }
- inline AcString & AcString::operator += (const wchar_t *pwsz)
- {
- return this->append(pwsz);
- }
- inline AcString & AcString::operator += (const AcString & acs)
- {
- return this->append(acs);
- }
- inline AcString & AcString::append(char ch)
- {
- const char str[2] = {ch, '\0'};
- return this->append(str);
- }
- inline AcString & AcString::append(wchar_t wch)
- {
- const wchar_t wstr[2] = {wch, L'\0'};
- return this->append(wstr);
- }
- // Concatenation inlines
- inline AcString AcString::operator + (char ch) const
- {
- return this->concat(ch);
- }
- inline AcString AcString::operator + (wchar_t wch) const
- {
- return this->concat(wch);
- }
- inline AcString AcString::operator + (const char * psz) const
- {
- return this->concat(psz);
- }
- inline AcString AcString::operator + (const wchar_t * pwsz) const
- {
- return this->concat(pwsz);
- }
- inline AcString AcString::operator + (const AcString & acs) const
- {
- return this->concat(acs);
- }
- inline AcString AcString::concat(char ch) const
- {
- const char str[2] = {ch, '\0'};
- return this->concat(str);
- }
- inline AcString AcString::concat(wchar_t wch) const
- {
- const wchar_t wstr[2] = {wch, L'\0'};
- return this->concat(wstr);
- }
- inline AcString AcString::precat(ACHAR ch) const
- {
- const ACHAR str[2] = {ch, '\0'};
- return this->precat(str);
- }
- // Comparison inlines
- //
- inline int AcString::compare(wchar_t wch) const
- {
- const wchar_t wstr[2] = {wch, L'\0'};
- return this->compare(wstr);
- }
- inline int AcString::compareNoCase(wchar_t wch) const
- {
- const wchar_t wstr[2] = {wch, L'\0'};
- return this->compareNoCase(wstr);
- }
- inline bool AcString::operator == (wchar_t wch) const
- {
- return this->compare(wch) == 0;
- }
- inline bool AcString::operator == (const char *psz) const
- {
- return this->compare(psz) == 0;
- }
- inline bool AcString::operator == (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) == 0;
- }
- inline bool AcString::operator == (const AcString & acs) const
- {
- return this->compare(acs) == 0;
- }
- inline bool AcString::operator != (wchar_t wch) const
- {
- return this->compare(wch) != 0;
- }
- inline bool AcString::operator != (const char *psz) const
- {
- return this->compare(psz) != 0;
- }
- inline bool AcString::operator != (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) != 0;
- }
- inline bool AcString::operator != (const AcString & acs) const
- {
- return this->compare(acs) != 0;
- }
- inline bool AcString::operator > (wchar_t wch) const
- {
- return this->compare(wch) > 0;
- }
- inline bool AcString::operator > (const char *psz) const
- {
- return this->compare(psz) > 0;
- }
- inline bool AcString::operator > (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) > 0;
- }
- inline bool AcString::operator > (const AcString & acs) const
- {
- return this->compare(acs) > 0;
- }
- inline bool AcString::operator >= (wchar_t wch) const
- {
- return this->compare(wch) >= 0;
- }
- inline bool AcString::operator >= (const char *psz) const
- {
- return this->compare(psz) >= 0;
- }
- inline bool AcString::operator >= (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) >= 0;
- }
- inline bool AcString::operator >= (const AcString & acs) const
- {
- return this->compare(acs) >= 0;
- }
- inline bool AcString::operator < (wchar_t wch) const
- {
- return this->compare(wch) < 0;
- }
- inline bool AcString::operator < (const char *psz) const
- {
- return this->compare(psz) < 0;
- }
- inline bool AcString::operator < (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) < 0;
- }
- inline bool AcString::operator < (const AcString & acs) const
- {
- return this->compare(acs) < 0;
- }
- inline bool AcString::operator <= (char ch) const
- {
- return this->compare(ch) <= 0;
- }
- inline bool AcString::operator <= (wchar_t wch) const
- {
- return this->compare(wch) <= 0;
- }
- inline bool AcString::operator <= (const char *psz) const
- {
- return this->compare(psz) <= 0;
- }
- inline bool AcString::operator <= (const wchar_t *pwsz) const
- {
- return this->compare(pwsz) <= 0;
- }
- inline bool AcString::operator <= (const AcString & acs) const
- {
- return this->compare(acs) <= 0;
- }
- // We can do inline operators that deal with CStrings, without getting
- // into binary format dependencies. Don't make these out-of-line
- // functions, because then we'll have a dependency between our
- // components and CString-using clients.
- //
- #if defined(_AFX) || defined(_ADESK_MAC_) || defined(__ATLSTR_H__)
- inline AcString::AcString(const CStringW &csw)
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- this->clearAll();
- *this = pwsz;
- }
- inline AcString & AcString::operator=(const CStringW &csw)
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->assign(pwsz);
- }
- inline AcString & AcString::operator+=(const CStringW &csw)
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->append(pwsz);
- }
- inline int AcString::compare(const CStringW & csw) const
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->compare(pwsz);
- }
- inline int AcString::compareNoCase(const CStringW & csw) const
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->compareNoCase(pwsz);
- }
- inline int AcString::match(const CStringW & csw) const
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->match(pwsz);
- }
- inline int AcString::matchNoCase(const CStringW & csw) const
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return this->matchNoCase(pwsz);
- }
- inline bool AcString::operator == (const CStringW & csw) const
- {
- return this->compare(csw) == 0;
- }
- inline bool AcString::operator != (const CStringW & csw) const
- {
- return this->compare(csw) != 0;
- }
- inline bool AcString::operator > (const CStringW & csw) const
- {
- return this->compare(csw) > 0;
- }
- inline bool AcString::operator >= (const CStringW & csw) const
- {
- return this->compare(csw) >= 0;
- }
- inline bool AcString::operator < (const CStringW & csw) const
- {
- return this->compare(csw) < 0;
- }
- inline bool AcString::operator <= (const CStringW & csw) const
- {
- return this->compare(csw) <= 0;
- }
- #endif
- #ifdef _AFX
- // Global CString-related operators
- inline bool operator == (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) == 0;
- }
- inline bool operator != (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) != 0;
- }
- inline bool operator > (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) < 0;
- }
- inline bool operator >= (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) <= 0;
- }
- inline bool operator < (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) > 0;
- }
- inline bool operator <= (const CStringW & csw, const AcString & acs)
- {
- return acs.compare(csw) >= 0;
- }
- #ifndef DISABLE_CSTRING_PLUS_ACSTRING
- inline AcString operator + (const CStringW & csw, const AcString & acs)
- {
- const wchar_t *pwsz = (const wchar_t *)csw;
- return acs.precat(pwsz);
- }
- #endif
- #endif // _AFX
- // Inline global operators
- inline bool operator == (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) == 0;
- }
- inline bool operator == (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) == 0;
- }
- inline bool operator == (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) == 0;
- }
- inline bool operator != (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) != 0;
- }
- inline bool operator != (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) != 0;
- }
- inline bool operator != (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) != 0;
- }
- inline bool operator > (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) < 0;
- }
- inline bool operator > (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) < 0;
- }
- inline bool operator > (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) < 0;
- }
- inline bool operator >= (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) <= 0;
- }
- inline bool operator >= (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) <= 0;
- }
- inline bool operator >= (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) <= 0;
- }
- inline bool operator < (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) > 0;
- }
- inline bool operator < (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) > 0;
- }
- inline bool operator < (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) > 0;
- }
- inline bool operator <= (wchar_t wch, const AcString & acs)
- {
- return acs.compare(wch) >= 0;
- }
- inline bool operator <= (const char *psz, const AcString & acs)
- {
- return acs.compare(psz) >= 0;
- }
- inline bool operator <= (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.compare(pwsz) >= 0;
- }
- // These don't modify the AcString. They return a copy.
- inline AcString operator + (ACHAR ch, const AcString & acs)
- {
- return acs.precat(ch);
- }
- inline AcString operator + (const char *psz, const AcString & acs)
- {
- return acs.precat(psz);
- }
- inline AcString operator + (const wchar_t *pwsz, const AcString & acs)
- {
- return acs.precat(pwsz);
- }
- // Return a unique identifier (pointer) for the input string, to allow fast compares
- // Strings containing the exact same chars will return the same AcUniqueString
- // AcUniqueString pointers are valid for the process's lifetime
- //
- class AcUniqueString
- {
- public:
- ACBASE_PORT static const AcUniqueString *Intern(const wchar_t *);
- };
- #endif // !_Ac_String_h
|