StringWrapper.h

Go to the documentation of this file.
00001 
00097 #ifndef INCLUDED_StringWrapper
00098 #define INCLUDED_StringWrapper
00099 
00100 // system
00101 #include <string>
00102 #include <string.h>
00103 #ifdef _WIN32
00104 # define strcasecmp     _stricmp
00105 # define strncasecmp    _strnicmp
00106 # define snprintf       _snprintf
00107 # define vsnprintf      _vsnprintf
00108 #endif
00109 
00110 // ICU
00111 #include <unicode/unistr.h>
00112 #include <unicode/ustring.h>
00113 
00114 
00115 // ----------------------------------------------------------------------------
00116 // String Debuggging
00117 
00118 // These macros set/check flags in debug mode to ensure that the string classes are
00119 // being used correctly. Asserts indicate incorrect usage of the class.
00120 #ifdef STRINGWRAPPER_ASSERT
00121 # define STRINGWRAPPER_NULLSAFE_DEFINE      bool m_bIsTerminated
00122 # define STRINGWRAPPER_NULLSAFE_SET(x)      m_bIsTerminated=(x)
00123 # define STRINGWRAPPER_NULLSAFE_TRUE        m_bIsTerminated=true
00124 # define STRINGWRAPPER_NULLSAFE_ASSERT      STRINGWRAPPER_ASSERT(m_bIsTerminated)
00125 # define STRINGWRAPPER_OPENBUF_DEFINE       bool m_bBufferIsOpen
00126 # define STRINGWRAPPER_OPENBUF_TRUE         m_bBufferIsOpen=true
00127 # define STRINGWRAPPER_OPENBUF_FALSE        m_bBufferIsOpen=false
00128 # define STRINGWRAPPER_OPENBUF_ASSERT       STRINGWRAPPER_ASSERT(!m_bBufferIsOpen)
00129 # define STRINGWRAPPER_OPENBUF_ASSERT_(x)   STRINGWRAPPER_ASSERT(!x.m_bBufferIsOpen)
00130 # define STRINGWRAPPER_OPENBUF_ASSERT_TRUE  STRINGWRAPPER_ASSERT(m_bBufferIsOpen)
00131 #else
00132 # define STRINGWRAPPER_ASSERT(x)
00133 # define STRINGWRAPPER_NULLSAFE_DEFINE
00134 # define STRINGWRAPPER_NULLSAFE_SET(x)
00135 # define STRINGWRAPPER_NULLSAFE_TRUE
00136 # define STRINGWRAPPER_NULLSAFE_ASSERT
00137 # define STRINGWRAPPER_OPENBUF_DEFINE
00138 # define STRINGWRAPPER_OPENBUF_TRUE
00139 # define STRINGWRAPPER_OPENBUF_FALSE
00140 # define STRINGWRAPPER_OPENBUF_ASSERT
00141 # define STRINGWRAPPER_OPENBUF_ASSERT_(x)
00142 # define STRINGWRAPPER_OPENBUF_ASSERT_TRUE
00143 #endif
00144 
00145 // ----------------------------------------------------------------------------
00146 // API definitions
00147 
00148 #ifndef STRINGWRAPPER_CLASS_API
00149 # define STRINGWRAPPER_CLASS_API
00150 #endif
00151 #ifndef STRINGWRAPPER_API
00152 # define STRINGWRAPPER_API
00153 #endif
00154 #ifdef STRINGWRAPPER_NAMESPACE
00155 # define STRINGWRAPPER_NS STRINGWRAPPER_NAMESPACE
00156 namespace STRINGWRAPPER_NS {
00157 #else
00158 # define STRINGWRAPPER_NS
00159 #endif
00160 
00161 // ----------------------------------------------------------------------------
00165 class STRINGWRAPPER_CLASS_API NarrowString
00166 {
00167     int32_t mLen;        // length of data in buffer (this class can store nulls embedded data)
00168     int32_t mSiz;        // size of the buffer
00169     char *  mBuf;        // data
00170     char    mStatic[10]; // short static buffer
00171     STRINGWRAPPER_OPENBUF_DEFINE;
00172 
00173 public:
00174     inline NarrowString()
00175         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00176     {
00177         *mBuf = 0;
00178         STRINGWRAPPER_OPENBUF_FALSE;
00179     }
00180 
00181     inline NarrowString(const char * text)
00182         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00183     {
00184         *mBuf = 0;
00185         STRINGWRAPPER_OPENBUF_FALSE;
00186         setTo(text);
00187     }
00188 
00189     inline NarrowString(const char * text, int32_t len)
00190         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00191     {
00192         *mBuf = 0;
00193         STRINGWRAPPER_OPENBUF_FALSE;
00194         setTo(text, len);
00195     }
00196 
00197     inline NarrowString(const NarrowString & text)
00198         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00199     {
00200         *mBuf = 0;
00201         STRINGWRAPPER_OPENBUF_FALSE;
00202         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00203         setTo(text);
00204     }
00205 
00206     inline NarrowString(const NarrowString & text, int32_t start)
00207         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00208     {
00209         *mBuf = 0;
00210         STRINGWRAPPER_OPENBUF_FALSE;
00211         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00212         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00213         setTo(text, start);
00214     }
00215 
00216     inline NarrowString(const NarrowString & text, int32_t start, int32_t len)
00217         : mLen(0), mSiz(sizeof mStatic), mBuf(mStatic)
00218     {
00219         *mBuf = 0;
00220         STRINGWRAPPER_OPENBUF_FALSE;
00221         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00222         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00223         setTo(text, start, len);
00224     }
00225 
00226     inline ~NarrowString()
00227     {
00228         if (mBuf != mStatic) free(mBuf);
00229     }
00230 
00234     inline bool isEmpty() const {
00235         STRINGWRAPPER_OPENBUF_ASSERT;
00236         return length() == 0;
00237     }
00238 
00239     inline int32_t length() const {
00240         STRINGWRAPPER_OPENBUF_ASSERT;
00241         return mLen;
00242     }
00243 
00248     inline NarrowString & operator=(const NarrowString & text) {
00249         STRINGWRAPPER_OPENBUF_ASSERT;
00250         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00251         setTo(text);
00252         return *this;
00253     }
00254 
00255     inline NarrowString & operator=(const char * text) {
00256         STRINGWRAPPER_OPENBUF_ASSERT;
00257         setTo(text);
00258         return *this;
00259     }
00260 
00261     inline NarrowString & operator=(char ch) {
00262         STRINGWRAPPER_OPENBUF_ASSERT;
00263         setTo(ch);
00264         return *this;
00265     }
00266 
00267     inline NarrowString & setTo(const NarrowString & text) {
00268         STRINGWRAPPER_OPENBUF_ASSERT;
00269         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00270         setTo(text.getBuffer());
00271         return *this;
00272     }
00273 
00274     inline NarrowString & setTo(const NarrowString & text, int32_t start) {
00275         STRINGWRAPPER_OPENBUF_ASSERT;
00276         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00277         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00278         setTo(text.getBuffer() + start);
00279         return *this;
00280     }
00281 
00282     inline NarrowString & setTo(const NarrowString & text, int32_t start, int32_t len) {
00283         STRINGWRAPPER_OPENBUF_ASSERT;
00284         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00285         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00286         if (len < 0) len = text.length() - start;
00287         setTo(text.getBuffer() + start, len);
00288         return *this;
00289     }
00290 
00291     inline NarrowString & setTo(const char * text) {
00292         STRINGWRAPPER_OPENBUF_ASSERT;
00293         setTo(text, strlen(text));
00294         return *this;
00295     }
00296 
00297     inline NarrowString & setTo(const char * text, int32_t len) {
00298         STRINGWRAPPER_OPENBUF_ASSERT;
00299         if (len < 0) len = (int32_t) strlen(text);
00300         remove();
00301         append(text, len);
00302         return *this;
00303     }
00304 
00305     inline NarrowString & setTo(char ch) {
00306         STRINGWRAPPER_OPENBUF_ASSERT;
00307         remove();
00308         append(&ch, 1);
00309         return *this;
00310     }
00311 
00316     inline NarrowString & operator+=(const NarrowString & text) {
00317         STRINGWRAPPER_OPENBUF_ASSERT;
00318         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00319         append(text);
00320         return *this;
00321     }
00322 
00323     inline NarrowString & operator+=(const char * text) {
00324         STRINGWRAPPER_OPENBUF_ASSERT;
00325         append(text);
00326         return *this;
00327     }
00328 
00329     inline NarrowString & operator+=(char ch) {
00330         STRINGWRAPPER_OPENBUF_ASSERT;
00331         append(&ch, 1);
00332         return *this;
00333     }
00334 
00335     inline NarrowString & append(const NarrowString & text) {
00336         STRINGWRAPPER_OPENBUF_ASSERT;
00337         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00338         append(text.getBuffer(), text.length());
00339         return *this;
00340     }
00341 
00342     inline NarrowString & append(const NarrowString & text, int32_t start, int32_t len) {
00343         STRINGWRAPPER_OPENBUF_ASSERT;
00344         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00345         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00346         if (len < 0) len = text.length() - start;
00347         append(text.getBuffer() + start, len);
00348         return *this;
00349     }
00350 
00351     inline NarrowString & append(const char * text, int32_t len) {
00352         STRINGWRAPPER_OPENBUF_ASSERT;
00353         if (len < 0) len = (int32_t) strlen(text);
00354         int32_t nCurLen = length();
00355         setCapacity(nCurLen + len); // always adds extra 1 for null char
00356         memcpy(mBuf + nCurLen, text, len);
00357         mLen += len;
00358         mBuf[mLen] = 0;
00359         return *this;
00360     }
00361 
00362     inline NarrowString & append(const char * text, int32_t start, int32_t len) {
00363         STRINGWRAPPER_OPENBUF_ASSERT;
00364         STRINGWRAPPER_ASSERT(start >= 0 && start < (int32_t) strlen(text));
00365         if (len < 0) len = (int32_t) strlen(text) - start;
00366         append(text + start, len);
00367         return *this;
00368     }
00369 
00370     inline NarrowString & append(char ch) {
00371         STRINGWRAPPER_OPENBUF_ASSERT;
00372         append(&ch, 1);
00373         return *this;
00374     }
00375 
00380     inline bool operator==(const NarrowString & text) const {
00381         STRINGWRAPPER_OPENBUF_ASSERT;
00382         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00383         return compare(text) == 0;
00384     }
00385 
00386     inline bool operator!=(const NarrowString & text) const {
00387         STRINGWRAPPER_OPENBUF_ASSERT;
00388         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00389         return compare(text) != 0;
00390     }
00391 
00392     inline bool operator> (const NarrowString & text) const {
00393         STRINGWRAPPER_OPENBUF_ASSERT;
00394         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00395         return compare(text) >  0;
00396     }
00397 
00398     inline bool operator>=(const NarrowString & text) const {
00399         STRINGWRAPPER_OPENBUF_ASSERT;
00400         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00401         return compare(text) >= 0;
00402     }
00403 
00404     inline bool operator< (const NarrowString & text) const {
00405         STRINGWRAPPER_OPENBUF_ASSERT;
00406         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00407         return compare(text) <  0;
00408     }
00409 
00410     inline bool operator<=(const NarrowString & text) const {
00411         STRINGWRAPPER_OPENBUF_ASSERT;
00412         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00413         return compare(text) <= 0;
00414     }
00415 
00416     inline int8_t compare(const NarrowString & text) const {
00417         STRINGWRAPPER_OPENBUF_ASSERT;
00418         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00419         return (int8_t) strcmp(getBuffer(), text.getBuffer());
00420     }
00421 
00422     inline int8_t compare(const NarrowString & text, int32_t len) const {
00423         STRINGWRAPPER_OPENBUF_ASSERT;
00424         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00425         if (len < 0) len = (int32_t) text.length();
00426         return (int8_t) strncmp(getBuffer(), text.getBuffer(), len);
00427     }
00428 
00429     inline int8_t compare(const char * text) const {
00430         STRINGWRAPPER_OPENBUF_ASSERT;
00431         return (int8_t) strcmp(getBuffer(), text);
00432     }
00433 
00434     inline int8_t compare(const char * text, int32_t len) const {
00435         STRINGWRAPPER_OPENBUF_ASSERT;
00436         if (len < 0) len = (int32_t) strlen(text);
00437         return (int8_t) strncmp(getBuffer(), text, len);
00438     }
00439 
00440     inline int8_t compare(int32_t start, int32_t len, 
00441         const char * srcChars, int32_t srcStart, int32_t srcLength) const
00442     {
00443         STRINGWRAPPER_OPENBUF_ASSERT;
00444         if (len < 0) len = length() - start;
00445         if (srcLength < 0) srcLength = strlen(srcChars) - srcStart;
00446         int rc = strncmp(getBuffer() + start, srcChars + srcStart, min(len, srcLength));
00447         if (rc != 0) return (rc < 0) ? -1 : 1;
00448         if (len == srcLength) return 0;
00449         return (len < srcLength) ? -1 : 1;
00450     }
00451 
00452     inline int8_t caseCompare(const NarrowString & text) const {
00453         STRINGWRAPPER_OPENBUF_ASSERT;
00454         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00455         return caseCompare(text.getBuffer(), text.length());
00456     }
00457 
00458     inline int8_t caseCompare(const char * text) const {
00459         STRINGWRAPPER_OPENBUF_ASSERT;
00460         return caseCompare(text, strlen(text));
00461     }
00462 
00463     inline int8_t caseCompare(const NarrowString & text, int32_t len) const {
00464         STRINGWRAPPER_OPENBUF_ASSERT;
00465         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00466         if (len < 0) len = text.length();
00467         return caseCompare(text.getBuffer(), len);
00468     }
00469 
00470     int8_t caseCompare(const char * text, int32_t len) const;
00471 
00472     inline int8_t caseCompare(const NarrowString & text, int32_t start, int32_t len) const {
00473         STRINGWRAPPER_OPENBUF_ASSERT;
00474         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00475         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
00476         if (len < 0) len = text.length() - start;
00477         return caseCompare(text.getBuffer() + start, len);
00478     }
00479 
00480     inline int8_t caseCompare(const char * text, int32_t start, int32_t len) const {
00481         STRINGWRAPPER_OPENBUF_ASSERT;
00482         STRINGWRAPPER_ASSERT(start >= 0);
00483         if (len < 0) len = strlen(text) - start;
00484         return caseCompare(text + start, len);
00485     }
00486 
00491     inline char first() const {
00492         STRINGWRAPPER_OPENBUF_ASSERT;
00493         STRINGWRAPPER_ASSERT(!isEmpty());
00494         return getCharAt(0);
00495     }
00496 
00497     inline char last() const {
00498         STRINGWRAPPER_OPENBUF_ASSERT;
00499         STRINGWRAPPER_ASSERT(!isEmpty());
00500         return getCharAt(length()-1);
00501     }
00502 
00503     inline char operator[](int32_t offset) const {
00504         STRINGWRAPPER_OPENBUF_ASSERT;
00505         STRINGWRAPPER_ASSERT(offset >= 0 && offset < length());
00506         return getCharAt(offset);
00507     }
00508 
00509     inline char getCharAt(int32_t offset) const {
00510         STRINGWRAPPER_OPENBUF_ASSERT;
00511         STRINGWRAPPER_ASSERT(offset >= 0 && offset < length());
00512         return mBuf[offset];
00513     }
00514 
00515     inline NarrowString & setCharAt(int32_t offset, char ch) {
00516         STRINGWRAPPER_OPENBUF_ASSERT;
00517         STRINGWRAPPER_ASSERT(offset >= 0 && offset < length());
00518         mBuf[offset] = ch;
00519         return *this;
00520     }
00521 
00526     inline const char * getBuffer() const {
00527         STRINGWRAPPER_OPENBUF_ASSERT;
00528         STRINGWRAPPER_ASSERT(mBuf[mLen] == 0);
00529         return mBuf;
00530     }
00531 
00532     inline char * getBuffer(int32_t minCapacity) {
00533         STRINGWRAPPER_OPENBUF_ASSERT;
00534         setCapacity(minCapacity); // always adds extra 1 for null char
00535         STRINGWRAPPER_OPENBUF_TRUE;
00536         return mBuf;
00537     }
00538 
00539     inline void releaseBuffer(int32_t newLength = -1) {
00540         STRINGWRAPPER_OPENBUF_ASSERT_TRUE;
00541         if (newLength < 0) newLength = (int32_t) strlen(mBuf);
00542         STRINGWRAPPER_ASSERT(newLength < mSiz);
00543         mLen = newLength;
00544         mBuf[mLen] = 0;
00545         STRINGWRAPPER_OPENBUF_FALSE;
00546     }
00547 
00548     inline int32_t getCapacity() const {
00549         STRINGWRAPPER_OPENBUF_ASSERT;
00550         return mSiz;
00551     }
00552 
00553     void setCapacity(int32_t newSiz);
00554 
00559     inline NarrowString & remove() {
00560         STRINGWRAPPER_OPENBUF_ASSERT;
00561         truncate(0);
00562         return *this;
00563     }
00564 
00565     inline NarrowString & remove(int32_t start, int32_t len = INT32_MAX) {
00566         STRINGWRAPPER_OPENBUF_ASSERT;
00567         STRINGWRAPPER_ASSERT(start >= 0 && start < length());
00568         return replace(start, len, "", 0);
00569     }
00570 
00571     inline bool truncate(int32_t targetLength) {
00572         STRINGWRAPPER_OPENBUF_ASSERT;
00573         STRINGWRAPPER_ASSERT(targetLength <= length());
00574         mLen = targetLength;
00575         mBuf[mLen] = 0;
00576         return true;
00577     }
00578 
00583     inline NarrowString & insert(int32_t offset, const NarrowString & text) {
00584         STRINGWRAPPER_OPENBUF_ASSERT;
00585         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00586         return insert(offset, text.getBuffer(), text.length());
00587     }
00588 
00589     inline NarrowString & insert(int32_t offset, const char * text) {
00590         STRINGWRAPPER_OPENBUF_ASSERT;
00591         return insert(offset, text, -1);
00592     }
00593 
00594     inline NarrowString & insert(int32_t offset, const char * text, int32_t len) {
00595         STRINGWRAPPER_OPENBUF_ASSERT;
00596         STRINGWRAPPER_ASSERT(offset >= 0 && offset <= length());
00597         STRINGWRAPPER_ASSERT(text);
00598         return replace(offset, 0, text, len);
00599     }
00600 
00601     inline NarrowString & insert(int32_t offset, char ch) {
00602         STRINGWRAPPER_OPENBUF_ASSERT;
00603         return insert(offset, &ch, 1);
00604     }
00605 
00610     NarrowString & toUpper();
00611 
00612     NarrowString & toLower();
00613 
00614     NarrowString & trim();
00615 
00620     inline int32_t indexOf(char c, int32_t start = 0) const {
00621         STRINGWRAPPER_OPENBUF_ASSERT;
00622         STRINGWRAPPER_ASSERT(start >= 0);
00623         if (start >= length()) return -1;
00624         const char * p = strchr(getBuffer() + start, c);
00625         return p ? p - getBuffer() : -1;
00626     }
00627 
00628     inline int32_t indexOf(const NarrowString & text, int32_t start = 0) const {
00629         STRINGWRAPPER_OPENBUF_ASSERT;
00630         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00631         return indexOf(text.getBuffer(), start);
00632     }
00633 
00634     inline int32_t indexOf(const char * text, int32_t start = 0) const {
00635         STRINGWRAPPER_OPENBUF_ASSERT;
00636         STRINGWRAPPER_ASSERT(start >= 0);
00637         if (start >= length()) return -1;
00638         const char * p = strstr(getBuffer() + start, text);
00639         return p ? p - getBuffer() : -1;
00640     }
00641 
00642     inline int32_t lastIndexOf(char c, int32_t start = -1) const {
00643         STRINGWRAPPER_OPENBUF_ASSERT;
00644         if (isEmpty()) return -1;
00645         if (start >= length()) return -1;
00646         if (start < 0) start = length() - 1;
00647         for (; start >= 0; --start) {
00648             if (getCharAt(start) == c) return start;
00649         }
00650         return -1;
00651     }
00652 
00653     inline int32_t lastIndexOf(const NarrowString & text, int32_t start = -1) const {
00654         STRINGWRAPPER_OPENBUF_ASSERT;
00655         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00656         return lastIndexOf(text.getBuffer(), start, text.length());
00657     }
00658 
00659     inline int32_t lastIndexOf(const char * text, int32_t start = -1) const {
00660         STRINGWRAPPER_OPENBUF_ASSERT;
00661         return lastIndexOf(text, start, -1);
00662     }
00663 
00664     inline int32_t lastIndexOf(const char * text, int32_t start, int32_t len) const {
00665         STRINGWRAPPER_OPENBUF_ASSERT;
00666         if (isEmpty()) return -1;
00667         if (len < 0) len = (int32_t) strlen(text);
00668         if (len == 0 || len > length()) return -1;
00669         if (start < 0 || start + len > length()) start = length() - len;
00670 
00671         // simple search algorithm, not the fastest
00672         for (; start >= 0; --start) {
00673             if (!strncmp(getBuffer() + start, text, len)) return start;
00674         }
00675 
00676         return -1;
00677     }
00678 
00683     inline NarrowString & replace(int32_t start, int32_t len, char srcChar) {
00684         STRINGWRAPPER_OPENBUF_ASSERT;
00685         STRINGWRAPPER_ASSERT(start >= 0 && start < length());
00686         return replace(start, len, &srcChar, 1);
00687     }
00688 
00689     inline NarrowString & replace(int32_t start, int32_t len, const NarrowString & text) {
00690         STRINGWRAPPER_OPENBUF_ASSERT;
00691         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00692         STRINGWRAPPER_ASSERT(start >= 0 && start < length());
00693         return replace(start, len, text.getBuffer(), text.length());
00694     }
00695 
00696     NarrowString & replace(int32_t start, int32_t len, const char * srcText, int32_t srcLength = -1);
00697 
00698     inline NarrowString & findAndReplace(char chOld, char chNew) {
00699         STRINGWRAPPER_OPENBUF_ASSERT;
00700         int32_t n = indexOf(chOld);
00701         while (n >= 0) {
00702             setCharAt(n, chNew);
00703             n = indexOf(chOld, n + 1);
00704         }
00705         return *this;
00706     }
00707 
00708     inline NarrowString & findAndReplace(
00709         const NarrowString & oldText, const NarrowString & newText)
00710     {
00711         STRINGWRAPPER_OPENBUF_ASSERT;
00712         STRINGWRAPPER_OPENBUF_ASSERT_(newText);
00713         int32_t n = indexOf(oldText);
00714         while (n >= 0) {
00715             replace(n, oldText.length(), newText);
00716             n = indexOf(oldText, n + newText.length());
00717         }
00718         return *this;
00719     }
00720 
00726     void format(const char * a_pszFormat, ...);
00727     void formatV(const char * a_pszFormat, va_list ap);
00728 
00732     struct LessNoCase {
00733         bool operator()(const NarrowString & ltext, const NarrowString & rtext) const {
00734             return ltext.caseCompare(rtext) < 0;
00735         }
00736     };
00737 };
00738 
00739 // ----------------------------------------------------------------------------
00744 class STRINGWRAPPER_CLASS_API WideString
00745 {
00746     UnicodeString mStr;
00747     STRINGWRAPPER_NULLSAFE_DEFINE;
00748     STRINGWRAPPER_OPENBUF_DEFINE;
00749 
00750 public:
00751     inline WideString() {
00752         STRINGWRAPPER_OPENBUF_FALSE;
00753         STRINGWRAPPER_NULLSAFE_TRUE;
00754         mStr.getTerminatedBuffer();
00755     }
00756 
00757     inline WideString(const UChar * text)
00758         : mStr(text)
00759     {
00760         STRINGWRAPPER_OPENBUF_FALSE;
00761         STRINGWRAPPER_NULLSAFE_TRUE;
00762         mStr.getTerminatedBuffer();
00763     }
00764 
00765     inline WideString(const UChar * text, int32_t len)
00766         : mStr(text, (len < 0) ? u_strlen(text) : len)
00767     {
00768         STRINGWRAPPER_OPENBUF_FALSE;
00769         STRINGWRAPPER_NULLSAFE_TRUE;
00770         mStr.getTerminatedBuffer();
00771     }
00772 
00773     inline WideString(const WideString & text)
00774         : mStr(text.mStr)
00775     {
00776         STRINGWRAPPER_OPENBUF_FALSE;
00777         STRINGWRAPPER_NULLSAFE_TRUE;
00778         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00779         mStr.getTerminatedBuffer();
00780     }
00781 
00782     inline WideString(const WideString & text, int32_t start)
00783         : mStr(text.mStr, start)
00784     {
00785         STRINGWRAPPER_OPENBUF_FALSE;
00786         STRINGWRAPPER_NULLSAFE_TRUE;
00787         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00788         mStr.getTerminatedBuffer();
00789     }
00790 
00791     inline WideString(const WideString & text, int32_t start, int32_t len)
00792         : mStr(text.mStr, start, (len < 0) ? text.mStr.length() - start : len)
00793     {
00794         STRINGWRAPPER_OPENBUF_FALSE;
00795         STRINGWRAPPER_NULLSAFE_TRUE;
00796         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00797         mStr.getTerminatedBuffer();
00798     }
00799 
00800     inline WideString(const char * text, int32_t len, UnicodeString::EInvariant)
00801         : mStr(text, (len < 0) ? strlen(text) : len, US_INV)
00802     {
00803         STRINGWRAPPER_OPENBUF_FALSE;
00804         STRINGWRAPPER_NULLSAFE_TRUE;
00805         mStr.getTerminatedBuffer();
00806     }
00807 
00808     inline ~WideString() { }
00809 
00813     inline bool isEmpty() const {
00814         STRINGWRAPPER_OPENBUF_ASSERT;
00815         return mStr.isEmpty() == TRUE;
00816     }
00817 
00818     inline int32_t length() const {
00819         STRINGWRAPPER_OPENBUF_ASSERT;
00820         return mStr.length();
00821     }
00822 
00827     inline WideString & operator=(const WideString & text) {
00828         STRINGWRAPPER_OPENBUF_ASSERT;
00829         STRINGWRAPPER_NULLSAFE_TRUE;
00830         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00831         return setTo(text.mStr.getBuffer(), text.mStr.length());
00832     }
00833 
00834     inline WideString & operator=(const UnicodeString & text) {
00835         STRINGWRAPPER_OPENBUF_ASSERT;
00836         STRINGWRAPPER_NULLSAFE_TRUE;
00837         return setTo(text.getBuffer(), text.length());
00838     }
00839 
00840     inline WideString & operator=(const UChar * text) {
00841         STRINGWRAPPER_OPENBUF_ASSERT;
00842         STRINGWRAPPER_NULLSAFE_TRUE;
00843         return setTo(text, u_strlen(text));
00844     }
00845 
00846     inline WideString & operator=(UChar ch) {
00847         STRINGWRAPPER_OPENBUF_ASSERT;
00848         STRINGWRAPPER_NULLSAFE_TRUE;
00849         return setTo(&ch, 1);
00850     }
00851 
00852     inline WideString & setTo(const WideString & text) {
00853         STRINGWRAPPER_OPENBUF_ASSERT;
00854         STRINGWRAPPER_NULLSAFE_TRUE;
00855         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00856         return setTo(text.mStr.getBuffer(), text.mStr.length());
00857     }
00858 
00859     inline WideString & setTo(const UnicodeString & text) {
00860         STRINGWRAPPER_OPENBUF_ASSERT;
00861         STRINGWRAPPER_NULLSAFE_TRUE;
00862         return setTo(text.getBuffer(), text.length());
00863     }
00864 
00865     inline WideString & setTo(const WideString & text, int32_t start) {
00866         STRINGWRAPPER_OPENBUF_ASSERT;
00867         STRINGWRAPPER_NULLSAFE_TRUE;
00868         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00869         return setTo(text.mStr.getBuffer() + start, text.mStr.length() - start);
00870     }
00871 
00872     inline WideString & setTo(const WideString & text, int32_t start, int32_t len) {
00873         STRINGWRAPPER_OPENBUF_ASSERT;
00874         STRINGWRAPPER_NULLSAFE_TRUE;
00875         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00876         if (len < 0) len = text.mStr.length() - start;
00877         return setTo(text.mStr.getBuffer() + start, len);
00878     }
00879 
00880     inline WideString & setTo(const UChar * text) {
00881         STRINGWRAPPER_OPENBUF_ASSERT;
00882         STRINGWRAPPER_NULLSAFE_TRUE;
00883         return setTo(text, u_strlen(text));
00884     }
00885 
00886     inline WideString & setTo(const UChar * text, int32_t len) {
00887         STRINGWRAPPER_OPENBUF_ASSERT;
00888         STRINGWRAPPER_NULLSAFE_TRUE;
00889         if (len < 0) len = u_strlen(text);
00890         // to avoid reallocations we manually get the buffer including space for a NULL
00891         UChar * pBuf = mStr.getBuffer(len+1);
00892         memcpy(pBuf, text, len*sizeof(UChar));
00893         pBuf[len] = 0;
00894         mStr.releaseBuffer(len);
00895         mStr.getTerminatedBuffer();
00896         return *this;
00897     }
00898 
00899     inline WideString & setTo(const char * text, int32_t len, UnicodeString::EInvariant) {
00900         STRINGWRAPPER_OPENBUF_ASSERT;
00901         STRINGWRAPPER_NULLSAFE_TRUE;
00902         if (len < 0) len = strlen(text);
00903         mStr.setTo(text, len, US_INV);
00904         mStr.getTerminatedBuffer();
00905         return *this;
00906     }
00907 
00908     inline WideString & setTo(UChar ch) {
00909         STRINGWRAPPER_OPENBUF_ASSERT;
00910         STRINGWRAPPER_NULLSAFE_TRUE;
00911         return setTo(&ch, 1);
00912     }
00913 
00918     inline WideString & operator+=(const WideString & text) {
00919         STRINGWRAPPER_OPENBUF_ASSERT;
00920         STRINGWRAPPER_NULLSAFE_TRUE;
00921         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00922         mStr.append(text.mStr.getBuffer(), text.mStr.length());
00923         mStr.getTerminatedBuffer();
00924         return *this;
00925     }
00926 
00927     inline WideString & operator+=(const UChar * text) {
00928         STRINGWRAPPER_OPENBUF_ASSERT;
00929         STRINGWRAPPER_NULLSAFE_TRUE;
00930         mStr.append(text, u_strlen(text));
00931         mStr.getTerminatedBuffer();
00932         return *this;
00933     }
00934 
00935     inline WideString & operator+=(UChar ch) {
00936         STRINGWRAPPER_OPENBUF_ASSERT;
00937         STRINGWRAPPER_NULLSAFE_TRUE;
00938         mStr.append(&ch, 1);
00939         mStr.getTerminatedBuffer();
00940         return *this;
00941     }
00942 
00943     inline WideString & append(const WideString & text) {
00944         STRINGWRAPPER_OPENBUF_ASSERT;
00945         STRINGWRAPPER_NULLSAFE_TRUE;
00946         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00947         mStr.append(text.mStr.getBuffer(), text.mStr.length());
00948         mStr.getTerminatedBuffer();
00949         return *this;
00950     }
00951 
00952     inline WideString & append(const WideString & text, int32_t start, int32_t len) {
00953         STRINGWRAPPER_OPENBUF_ASSERT;
00954         STRINGWRAPPER_NULLSAFE_TRUE;
00955         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00956         if (len < 0) len = text.mStr.length() - start;
00957         mStr.append(text.mStr.getBuffer() + start, len);
00958         mStr.getTerminatedBuffer();
00959         return *this;
00960     }
00961 
00962     inline WideString & append(const UChar * text, int32_t len) {
00963         STRINGWRAPPER_OPENBUF_ASSERT;
00964         STRINGWRAPPER_NULLSAFE_TRUE;
00965         if (len < 0) len = u_strlen(text);
00966         mStr.append(text, len);
00967         mStr.getTerminatedBuffer();
00968         return *this;
00969     }
00970 
00971     inline WideString & append(const UChar * text, int32_t start, int32_t len) {
00972         STRINGWRAPPER_OPENBUF_ASSERT;
00973         STRINGWRAPPER_NULLSAFE_TRUE;
00974         if (len < 0) len = u_strlen(text) - start;
00975         mStr.append(text + start, len);
00976         mStr.getTerminatedBuffer();
00977         return *this;
00978     }
00979 
00980     inline WideString & append(UChar ch) {
00981         STRINGWRAPPER_OPENBUF_ASSERT;
00982         STRINGWRAPPER_NULLSAFE_TRUE;
00983         mStr.append(&ch, 1);
00984         mStr.getTerminatedBuffer();
00985         return *this;
00986     }
00987 
00992     inline bool operator==(const WideString & text) const {
00993         STRINGWRAPPER_OPENBUF_ASSERT;
00994         STRINGWRAPPER_OPENBUF_ASSERT_(text);
00995         return compare(text) == 0;
00996     }
00997 
00998     inline bool operator!=(const WideString & text) const {
00999         STRINGWRAPPER_OPENBUF_ASSERT;
01000         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01001         return compare(text) != 0;
01002     }
01003 
01004     inline bool operator> (const WideString & text) const {
01005         STRINGWRAPPER_OPENBUF_ASSERT;
01006         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01007         return compare(text) >  0;
01008     }
01009 
01010     inline bool operator>=(const WideString & text) const {
01011         STRINGWRAPPER_OPENBUF_ASSERT;
01012         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01013         return compare(text) >= 0;
01014     }
01015 
01016     inline bool operator< (const WideString & text) const {
01017         STRINGWRAPPER_OPENBUF_ASSERT;
01018         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01019         return compare(text) <  0;
01020     }
01021 
01022     inline bool operator<=(const WideString & text) const {
01023         STRINGWRAPPER_OPENBUF_ASSERT;
01024         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01025         return compare(text) <= 0;
01026     }
01027 
01028     inline int8_t compare(const WideString & text) const {
01029         STRINGWRAPPER_OPENBUF_ASSERT;
01030         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01031         return mStr.compare(text.mStr);
01032     }
01033 
01034     inline int8_t compare(const WideString & text, int32_t len) const {
01035         STRINGWRAPPER_OPENBUF_ASSERT;
01036         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01037         if (len < 0) len = text.length();
01038         return mStr.compare(text.mStr.getBuffer(), len);
01039     }
01040 
01041     inline int8_t compare(const UChar * text) const {
01042         STRINGWRAPPER_OPENBUF_ASSERT;
01043         return mStr.compare(text);
01044     }
01045 
01046     inline int8_t compare(const UChar * text, int32_t len) const {
01047         STRINGWRAPPER_OPENBUF_ASSERT;
01048         if (len < 0) len = u_strlen(text);
01049         return mStr.compare(text, len);
01050     }
01051 
01052     inline int8_t compare(int32_t start, int32_t len, 
01053         const UChar *srcChars, int32_t srcStart, int32_t srcLength) const
01054     {
01055         STRINGWRAPPER_OPENBUF_ASSERT;
01056         if (len < 0) len = length() - start;
01057         if (srcLength < 0) srcLength = u_strlen(srcChars) - srcStart;
01058         return mStr.compare(start, len, srcChars, srcStart, srcLength);
01059     }
01060 
01061     inline int8_t caseCompare(int32_t options, const WideString & text) const {
01062         STRINGWRAPPER_OPENBUF_ASSERT;
01063         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01064         return caseCompare(options, text.getBuffer(), text.length());
01065     }
01066 
01067     inline int8_t caseCompare(int32_t options, const UChar * text) const {
01068         STRINGWRAPPER_OPENBUF_ASSERT;
01069         return caseCompare(options, text, u_strlen(text));
01070     }
01071 
01072     inline int8_t caseCompare(int32_t options, const WideString & text, int32_t len) const {
01073         STRINGWRAPPER_OPENBUF_ASSERT;
01074         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01075         if (len < 0) len = text.length();
01076         return caseCompare(options, text.getBuffer(), len);
01077     }
01078 
01079     inline int8_t caseCompare(int32_t options, const UChar * text, int32_t len) const {
01080         STRINGWRAPPER_OPENBUF_ASSERT;
01081         if (len < 0) len = u_strlen(text);
01082         if (len > length()) len = length();
01083         return mStr.caseCompare(0, len, text, 0, len, options);
01084     }
01085 
01086     inline int8_t caseCompare(int32_t options, const WideString & text, int32_t start, int32_t len) const {
01087         STRINGWRAPPER_OPENBUF_ASSERT;
01088         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01089         STRINGWRAPPER_ASSERT(start >= 0 && start < text.length());
01090         if (len < 0) len = text.length() - start;
01091         return caseCompare(options, text.getBuffer() + start, len);
01092     }
01093 
01094     inline int8_t caseCompare(int32_t options, const UChar * text, int32_t start, int32_t len) const {
01095         STRINGWRAPPER_OPENBUF_ASSERT;
01096         STRINGWRAPPER_ASSERT(start >= 0);
01097         if (len < 0) len = u_strlen(text) - start;
01098         return caseCompare(options, text + start, len);
01099     }
01100 
01105     inline UChar first() const {
01106         STRINGWRAPPER_OPENBUF_ASSERT;
01107         STRINGWRAPPER_ASSERT(!isEmpty());
01108         return mStr[0];
01109     }
01110 
01111     inline UChar last() const {
01112         STRINGWRAPPER_OPENBUF_ASSERT;
01113         STRINGWRAPPER_ASSERT(!isEmpty());
01114         return mStr[mStr.length()-1];
01115     }
01116 
01117     inline UChar operator[](int32_t offset) const {
01118         STRINGWRAPPER_OPENBUF_ASSERT;
01119         STRINGWRAPPER_ASSERT(offset >= 0 && offset < length());
01120         return mStr[offset];
01121     }
01122 
01123     inline UChar getCharAt(int32_t offset) const { return operator[](offset); }
01124 
01125     inline WideString & setCharAt(int32_t offset, UChar ch) {
01126         STRINGWRAPPER_OPENBUF_ASSERT;
01127         STRINGWRAPPER_NULLSAFE_TRUE;
01128         STRINGWRAPPER_ASSERT(offset >= 0 && offset < length());
01129         mStr.setCharAt(offset, ch);
01130         mStr.getTerminatedBuffer();
01131         return *this;
01132     }
01133 
01138     inline const UChar * getBuffer() const {
01139         STRINGWRAPPER_OPENBUF_ASSERT;
01140         STRINGWRAPPER_NULLSAFE_ASSERT;
01141         STRINGWRAPPER_ASSERT(mStr.getBuffer()[mStr.length()] == 0);
01142         return mStr.getBuffer();
01143     }
01144 
01145     inline UChar * getBuffer(int32_t minCapacity) {
01146         STRINGWRAPPER_OPENBUF_ASSERT;
01147         STRINGWRAPPER_OPENBUF_TRUE;
01148         return mStr.getBuffer(minCapacity+1);
01149     }
01150 
01151     inline void releaseBuffer(int32_t newLength = -1) {
01152         STRINGWRAPPER_OPENBUF_ASSERT_TRUE;
01153         mStr.releaseBuffer(newLength);
01154         mStr.getTerminatedBuffer();
01155         STRINGWRAPPER_OPENBUF_FALSE;
01156         STRINGWRAPPER_NULLSAFE_TRUE;
01157     }
01158 
01159     inline int32_t getCapacity() const {
01160         STRINGWRAPPER_OPENBUF_ASSERT;
01161         return mStr.getCapacity();
01162     }
01163 
01164     inline void setCapacity(int32_t n) {
01165         STRINGWRAPPER_OPENBUF_ASSERT;
01166         if (n+1 > mStr.getCapacity()) {
01167             int32_t nLen = mStr.length();
01168             mStr.getBuffer(n);
01169             mStr.releaseBuffer(nLen);
01170         }
01171     }
01172 
01177     inline WideString & remove() {
01178         STRINGWRAPPER_OPENBUF_ASSERT;
01179         STRINGWRAPPER_NULLSAFE_TRUE;
01180         mStr.remove();
01181         mStr.getTerminatedBuffer();
01182         return *this;
01183     }
01184 
01185     inline WideString & remove(int32_t start, int32_t length = INT32_MAX) {
01186         STRINGWRAPPER_OPENBUF_ASSERT;
01187         STRINGWRAPPER_NULLSAFE_TRUE;
01188         mStr.remove(start, length);
01189         mStr.getTerminatedBuffer();
01190         return *this;
01191     }
01192 
01193     inline bool truncate(int32_t targetLength) {
01194         STRINGWRAPPER_OPENBUF_ASSERT;
01195         if (!mStr.truncate(targetLength)) return false;
01196         STRINGWRAPPER_NULLSAFE_TRUE;
01197         mStr.getTerminatedBuffer();
01198         return true;
01199     }
01200 
01205     inline WideString & insert(int32_t offset, const WideString & srcText, int32_t srcLen = -1) {
01206         STRINGWRAPPER_OPENBUF_ASSERT;
01207         STRINGWRAPPER_NULLSAFE_TRUE;
01208         STRINGWRAPPER_OPENBUF_ASSERT_(srcText);
01209         return insert(offset, srcText.mStr.getBuffer(),
01210             srcLen == -1 ? srcText.mStr.length() : srcLen);
01211     }
01212 
01213     inline WideString & insert(int32_t offset, const UChar * srcText, int32_t srcLen = -1) {
01214         STRINGWRAPPER_OPENBUF_ASSERT;
01215         STRINGWRAPPER_NULLSAFE_TRUE;
01216         mStr.insert(offset, srcText, srcLen);
01217         mStr.getTerminatedBuffer();
01218         return *this;
01219     }
01220 
01221     inline WideString & insert(int32_t offset, UChar ch) {
01222         STRINGWRAPPER_OPENBUF_ASSERT;
01223         STRINGWRAPPER_NULLSAFE_TRUE;
01224         mStr.insert(offset, ch);
01225         mStr.getTerminatedBuffer();
01226         return *this;
01227     }
01228 
01233     inline WideString & toUpper() {
01234         STRINGWRAPPER_OPENBUF_ASSERT;
01235         STRINGWRAPPER_NULLSAFE_TRUE;
01236         mStr.toUpper();
01237         mStr.getTerminatedBuffer();
01238         return *this;
01239     }
01240 
01241     inline WideString & toLower() {
01242         STRINGWRAPPER_OPENBUF_ASSERT;
01243         STRINGWRAPPER_NULLSAFE_TRUE;
01244         mStr.toLower();
01245         mStr.getTerminatedBuffer();
01246         return *this;
01247     }
01248 
01249     inline WideString & trim() {
01250         STRINGWRAPPER_OPENBUF_ASSERT;
01251         STRINGWRAPPER_NULLSAFE_TRUE;
01252         mStr.trim();
01253         mStr.getTerminatedBuffer();
01254         return *this;
01255     }
01256 
01261     inline int32_t indexOf(UChar c, int32_t start = 0) const {
01262         STRINGWRAPPER_OPENBUF_ASSERT;
01263         return mStr.indexOf(c, start);
01264     }
01265 
01266     inline int32_t indexOf(const WideString & text, int32_t start = 0) const {
01267         STRINGWRAPPER_OPENBUF_ASSERT;
01268         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01269         return mStr.indexOf(text.mStr, start);
01270     }
01271 
01272     inline int32_t indexOf(const UChar * text, int32_t start = 0) const {
01273         STRINGWRAPPER_OPENBUF_ASSERT;
01274         return mStr.indexOf(text, start);
01275     }
01276 
01277     inline int32_t indexOf(const char * text, int32_t start = 0) const {
01278         STRINGWRAPPER_OPENBUF_ASSERT;
01279         return mStr.indexOf(text, start);
01280     }
01281 
01282     inline int32_t lastIndexOf(UChar c, int32_t start = 0) const {
01283         STRINGWRAPPER_OPENBUF_ASSERT;
01284         return mStr.lastIndexOf(c, start);
01285     }
01286 
01287     inline int32_t lastIndexOf(const WideString & text, int32_t start = 0) const {
01288         STRINGWRAPPER_OPENBUF_ASSERT;
01289         STRINGWRAPPER_OPENBUF_ASSERT_(text);
01290         return mStr.lastIndexOf(text.mStr, start);
01291     }
01292 
01293     inline int32_t lastIndexOf(const UChar * text, int32_t start = 0) const {
01294         STRINGWRAPPER_OPENBUF_ASSERT;
01295         return mStr.lastIndexOf(text, start);
01296     }
01297 
01298     inline int32_t lastIndexOf(const char * text, int32_t start = 0) const {
01299         STRINGWRAPPER_OPENBUF_ASSERT;
01300         return mStr.lastIndexOf(text, start);
01301     }
01302 
01307     inline WideString & replace(int32_t start, int32_t length, UChar srcChar) {
01308         STRINGWRAPPER_OPENBUF_ASSERT;
01309         STRINGWRAPPER_NULLSAFE_TRUE;
01310         return replace(start, length, &srcChar, 1);
01311     }
01312 
01313     inline WideString & replace(int32_t start, int32_t length, const WideString & srcText) {
01314         STRINGWRAPPER_OPENBUF_ASSERT;
01315         STRINGWRAPPER_NULLSAFE_TRUE;
01316         STRINGWRAPPER_OPENBUF_ASSERT_(srcText);
01317         return replace(start, length, srcText.mStr.getBuffer(), srcText.mStr.length());
01318     }
01319 
01320     inline WideString & replace(int32_t start, int32_t length,
01321         const UChar * srcText, int32_t srcLength = -1)
01322     {
01323         STRINGWRAPPER_OPENBUF_ASSERT;
01324         STRINGWRAPPER_NULLSAFE_TRUE;
01325         if (srcLength == -1) srcLength = u_strlen(srcText);
01326         mStr.replace(start, length, srcText, srcLength);
01327         mStr.getTerminatedBuffer();
01328         return *this;
01329     }
01330 
01331     inline WideString & findAndReplace(UChar chOld, UChar chNew) {
01332         STRINGWRAPPER_OPENBUF_ASSERT;
01333         STRINGWRAPPER_NULLSAFE_TRUE;
01334         mStr.findAndReplace(chOld, chNew);
01335         mStr.getTerminatedBuffer();
01336         return *this;
01337     }
01338 
01339     inline WideString & findAndReplace(
01340         const WideString & oldText, const WideString & newText)
01341     {
01342         STRINGWRAPPER_OPENBUF_ASSERT;
01343         STRINGWRAPPER_NULLSAFE_TRUE;
01344         STRINGWRAPPER_OPENBUF_ASSERT_(newText);
01345         mStr.findAndReplace(oldText.mStr, newText.mStr);
01346         mStr.getTerminatedBuffer();
01347         return *this;
01348     }
01349 
01355     void format(const char * a_pszFormat, ...);
01356     void formatV(const char * a_pszFormat, va_list ap);
01357 
01361     struct LessNoCase {
01362         int32_t mOptions;
01363         LessNoCase(int32_t aOptions = 0) : mOptions(aOptions) { }
01364         bool operator()(const WideString & lhs, const WideString & rhs) const {
01365             return lhs.caseCompare(mOptions, rhs) < 0;
01366         }
01367     };
01368 
01376     enum ALIAS { USE_ALIAS };
01377     inline WideString(ALIAS, const UChar * text, int32_t len, bool isNullTerminated)
01378         : mStr(isNullTerminated, text, (len < 0) ? u_strlen(text) : len)
01379     {
01380         STRINGWRAPPER_ASSERT(isNullTerminated || len >= 0);
01381         STRINGWRAPPER_ASSERT(!isNullTerminated || mStr.getBuffer()[mStr.length()] == 0);
01382         STRINGWRAPPER_NULLSAFE_SET(isNullTerminated);
01383         STRINGWRAPPER_OPENBUF_FALSE;
01384     }
01385 
01386     inline WideString & setTo(ALIAS, const UChar * text, int32_t len, bool isNullTerminated) {
01387         STRINGWRAPPER_OPENBUF_ASSERT;
01388         STRINGWRAPPER_ASSERT(isNullTerminated || len >= 0);
01389         if (len < 0) len = u_strlen(text);
01390         mStr.setTo(isNullTerminated, text, len);
01391         STRINGWRAPPER_ASSERT(!isNullTerminated || mStr.getBuffer()[mStr.length()] == 0);
01392         STRINGWRAPPER_NULLSAFE_SET(isNullTerminated);
01393         return *this;
01394     }
01395 
01396     inline const UnicodeString & getUnicodeString() const { return mStr; }
01398 };
01399 
01400 #define LITERAL_WIDE_STRING(str)                STRINGWRAPPER_NS::WideString(str, sizeof(str)-1, US_INV)
01401 #define NAMED_LITERAL_WIDE_STRING(name, str)    const STRINGWRAPPER_NS::WideString name(str, sizeof(str)-1, US_INV)
01402 
01403 
01404 // ------------------------------------------------------------------------
01408 STRINGWRAPPER_API WideString & ConvertCPtoUTF16(
01409     const char * src, int32_t srcLen, const char * codepage, WideString & dest);
01410 
01412 inline WideString & ConvertCPtoUTF16(
01413     const NarrowString & src, const char * codepage, WideString & dest)
01414 {
01415     return ConvertCPtoUTF16(src.getBuffer(), src.length(), codepage, dest);
01416 }
01417 
01419 inline WideString & ConvertASCIItoUTF16(const char * src, int32_t srcLen, WideString & dest) {
01420     return ConvertCPtoUTF16(src, srcLen, "", dest);
01421 }
01422 
01424 inline WideString & ConvertASCIItoUTF16(const NarrowString & src, WideString & dest) {
01425     return ConvertCPtoUTF16(src.getBuffer(), src.length(), "", dest);
01426 }
01427 
01429 inline WideString & ConvertUTF8toUTF16(const char * src, int32_t srcLen, WideString & dest) {
01430     return ConvertCPtoUTF16(src, srcLen, "UTF-8", dest);
01431 }
01432 
01434 inline WideString & ConvertUTF8toUTF16(const NarrowString & src, WideString & dest) {
01435     return ConvertCPtoUTF16(src.getBuffer(), src.length(), "UTF-8", dest);
01436 }
01437 
01439 inline WideString & ConvertNativeToUTF16(const char * src, int32_t srcLen, WideString & dest) {
01440     return ConvertCPtoUTF16(src, srcLen, NULL, dest);
01441 }
01442 
01444 inline WideString & ConvertNativeToUTF16(const NarrowString & src, WideString & dest) {
01445     return ConvertCPtoUTF16(src.getBuffer(), src.length(), NULL, dest);
01446 }
01447 
01450 // ------------------------------------------------------------------------
01454 STRINGWRAPPER_API bool ConvertUTF16toCP(
01455     const UChar * src, int32_t srcLen, const char * codepage, NarrowString & dest);
01456 
01458 inline bool ConvertUTF16toCP(const WideString & src, const char * codepage, NarrowString & dest) {
01459     return ConvertUTF16toCP(src.getBuffer(), src.length(), codepage, dest);
01460 }
01461 
01463 inline bool ConvertUTF16toASCII(const UChar * src, int32_t srcLen, NarrowString & dest) {
01464     return ConvertUTF16toCP(src, srcLen, "", dest);
01465 }
01466 
01468 inline bool ConvertUTF16toASCII(const WideString & src, NarrowString & dest) {
01469     return ConvertUTF16toCP(src, "", dest);
01470 }
01471 
01473 inline NarrowString & ConvertUTF16toUTF8(const UChar * src, int32_t srcLen, NarrowString & dest) {
01474     ConvertUTF16toCP(src, srcLen, "UTF-8", dest);
01475     return dest;
01476 }
01477 
01479 inline NarrowString & ConvertUTF16toUTF8(const WideString & src, NarrowString & dest) {
01480     ConvertUTF16toCP(src, "UTF-8", dest);
01481     return dest;
01482 }
01483 
01485 inline bool ConvertUTF16toNative(const WideString & src, NarrowString & dest) {
01486     return ConvertUTF16toCP(src, NULL, dest);
01487 }
01488 
01490 inline bool ConvertUTF16toNative(const UChar * src, int32_t srcLen, NarrowString & dest) {
01491     return ConvertUTF16toCP(src, srcLen, NULL, dest);
01492 }
01493 
01496 #ifdef STRINGWRAPPER_NAMESPACE
01497 }
01498 #endif
01499 
01500 #endif // INCLUDED_StringWrapper

Generated on Mon Apr 14 11:15:37 2008 for StringWrapper by  doxygen 1.5.4