00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032 #ifndef StringH
00033 #define StringH
00034
00035 #include <zeusbase/System/Interfaces/IString.hpp>
00036 #include <zeusbase/System/ByteArray.hpp>
00037
00038
00039 #ifdef _MSC_VER
00040 #pragma warning(push, 1) // Avoid Visual Studio 6.0 level 4 and 3 compiler warnings.
00041 #endif
00042
00043 #include <stdlib.h>
00044 #include <stdarg.h>
00045 #include <limits.h>
00046
00047 #ifdef _MSC_VER
00048 #pragma warning(pop)
00049 #endif
00050
00051
00052 #ifdef USE_BCB_BINDINGS
00053 namespace System
00054 {
00055 class WideString;
00056 #ifdef ENABLE_BCB_UNICODESTRING
00057 class UnicodeString;
00058 #endif
00059 };
00060 #endif
00061
00062 #ifdef USE_STL_BINDINGS
00063 #ifdef _MSC_VER
00064 #pragma warning(push, 1) // Avoid Visual Studio 6.0 level 4 and 3 compiler warnings.
00065 #pragma warning(disable: 4701) // Previous pragma has no effect!
00066 #endif
00067
00068 #include <string>
00069
00070 #ifdef _MSC_VER
00071 #pragma warning(default: 4701)
00072 #pragma warning(pop)
00073 #endif
00074 #endif
00075
00076 #ifdef USE_QT_BINDINGS
00077 class QString;
00078 #endif
00079
00080
00081
00082
00083 BEGIN_NAMESPACE_Zeus
00084
00085
00086 #define STRING_MIN_SIZE 10
00087
00088
00093
00094 #define INIT_TSTRING \
00095 m_pWBuffer(NULL), \
00096 m_pCBuffer(NULL), \
00097 m_iSize(0), \
00098 m_uiMemSize(0) \
00099
00100
00101
00112
00113 zeusbase_class TString : public IString
00114 {
00115 public:
00116
00117
00118 TString();
00119 TString(const wchar_t* data);
00120 TString(const char* data);
00121 TString(wchar_t wcChar, Uint uiCount=1);
00122 TString(char cChar, Uint uiCount=1);
00123 TString(const TString& strString);
00124 TString(const IString& strString);
00125 TString(const IString* pString);
00126 TString(Int32 lValue);
00127 TString(Int64 ldValue);
00128 TString(int iValue);
00129 TString(Uint32 ulValue);
00130 TString(Uint64 uldValue);
00131 TString(unsigned int uiValue);
00132 TString(Float fValue);
00133 TString(Float fValue, Uint uiDigits);
00134 TString(bool bValue);
00135
00136
00137 TString(const TString& rstr1, const TString& rstr2);
00138 TString(const TString& rstr, const wchar_t* pwc);
00139 TString(const wchar_t* pwc, const TString& rstr);
00140 TString(const wchar_t* pwc1, const wchar_t* pwc2);
00141
00142 TString(const TString& rstr1, const TString& rstr2, const TString& rstr3);
00143 TString(const TString& rstr1, const TString& rstr2, const wchar_t* pwc);
00144 TString(const TString& rstr1, const wchar_t* pwc, const TString& rstr2);
00145 TString(const TString& rstr, const wchar_t* pwc1, const wchar_t* pwc2);
00146 TString(const wchar_t* pwc, const TString& rstr1, const TString& rstr2);
00147 TString(const wchar_t* pwc1, const TString& rstr, const wchar_t* pwc2);
00148 TString(const wchar_t* pwc1, const wchar_t* pwc2, const TString& rstr);
00149 TString(const wchar_t* pwc1, const wchar_t* pwc2, const wchar_t* pwc3);
00150
00151 #ifdef USE_STL_BINDINGS
00152 TString(const std::wstring& rInstr);
00153 TString(const std::string& rInstr);
00154 #endif //USE_STL_BINDINGS
00155
00156 #ifdef USE_BCB_BINDINGS
00157 TString(const System::WideString& rInstr);
00158 #ifdef ENABLE_BCB_UNICODESTRING
00159 TString(const System::UnicodeString& rInstr);
00160 #endif
00161 #endif
00162
00163 #ifdef USE_QT_BINDINGS
00164 TString(const QString& rInStr);
00165 #endif
00166
00167
00168
00169 TString(wchar_t* pwcData, Uint uiBufferSize, bool bAdoptPointer);
00170
00171
00174
00175 inline virtual ~TString()
00176 {
00177 clearBuffers();
00178 }
00179
00180
00181
00182 static TString formatFloat(Float fValue,
00183 Float fRoundPrecision = 0,
00184 Uint uiTailingZeros = 0,
00185 Uint uiLeadingZeros = 1);
00186 static TString formatInt( Int iValue,
00187 Uint uiLeadingZeros);
00188 static TString format(const char* pcFormat, ...);
00189 static TString format(const wchar_t* pwcFormat, ...);
00190 static TString format(const IString& rFormat, ...);
00191 static TString formatV(const char* pcFormat, va_list Arg);
00192 static TString formatV(const wchar_t* pwcFormat, va_list Arg);
00193 static TString formatV(const IString& rFormat, va_list Arg);
00194
00195 static TString transcode(const IByteArray& list);
00196 static TByteArray transcode(const TString& rValue, bool bAsWideChar, bool bNullTerminated = true);
00197 static TByteArray transcode(const IString& rValue, bool bAsWideChar, bool bNullTerminated = true);
00198 static TString trimExt(const IString& rSource,
00199 const IString& rChars,
00200 bool bLeft = true,
00201 bool bRight = true);
00202
00203
00204
00205
00206 TString& operator=(const TString& rInstr);
00207 TString& operator=(const IString& rInstr);
00208 TString& operator=(const IString* pInstr);
00209 TString& operator=(const wchar_t* pData);
00210 TString& operator=(const Int iData);
00211 TString& operator=(const int iData);
00212 TString& operator=(const Uint uiData);
00213 TString& operator=(const unsigned int uiData);
00214 TString& operator=(const Float fData);
00215 TString& operator=(const char* pData);
00216 TString& operator=(bool bData);
00217 #ifdef USE_STL_BINDINGS
00218 TString& operator=(const std::wstring& rInstr);
00219 TString& operator=(const std::string& rInstr);
00220 #endif
00221 #ifdef USE_BCB_BINDINGS
00222 TString& operator=(const System::WideString& rInstr);
00223 #ifdef ENABLE_BCB_UNICODESTRING
00224 TString& operator=(const System::UnicodeString& rInstr);
00225 #endif
00226 #endif
00227
00228 bool operator==(const TString& rInstr) const;
00229 bool operator==(const IString& rInstr) const;
00230 bool operator==(const IString* pInstr) const;
00231 bool operator==(const wchar_t* pInbuffer) const;
00232 bool operator==(const char* pInbuffer) const;
00233 bool operator==(const Float fData) const;
00234 bool operator==(const Int iData) const;
00235 bool operator==(const int iData) const;
00236 bool operator==(const Uint uiData) const;
00237 bool operator==(const unsigned int uiData) const;
00238 bool operator==(bool bData) const;
00239 #ifdef USE_STL_BINDINGS
00240 bool operator==(const std::wstring& rInstr) const;
00241 bool operator==(const std::string& rInstr) const;
00242 #endif
00243 #ifdef USE_BCB_BINDINGS
00244 bool operator==(const System::WideString& rInstr) const;
00245 #ifdef ENABLE_BCB_UNICODESTRING
00246 bool operator==(const System::UnicodeString& rInstr) const;
00247 #endif
00248 #endif
00249
00250 TString operator+ (const TString& rInstr) const;
00251 TString operator+ (const IString& rInstr) const;
00252 TString operator+ (const wchar_t* pInbuffer) const;
00253 TString operator+ (const char* pInbuffer) const;
00254 TString operator+ (const wchar_t wc) const;
00255 TString operator+ (const char c) const;
00256 TString operator+ (const Int iInval) const;
00257 TString operator+ (const int iInval) const;
00258 TString operator+ (const Uint uiInval) const;
00259 TString operator+ (const unsigned int uiInval) const;
00260 TString operator+ (const Float fInval) const;
00261 #ifdef USE_STL_BINDINGS
00262 TString operator+ (const std::wstring& rInstr) const;
00263 TString operator+ (const std::string& rInstr) const;
00264 #endif
00265 bool operator!=(const TString& rInstr) const;
00266 bool operator!=(const IString& rInstr) const;
00267 bool operator!=(const IString* pInstr) const;
00268 bool operator!=(const wchar_t* pInbuffer)const;
00269 bool operator!=(const char* pInbuffer) const;
00270 bool operator!=(const Float fData) const;
00271 bool operator!=(const Int iData) const;
00272 bool operator!=(const int iData) const;
00273 bool operator!=(const Uint uiData) const;
00274 bool operator!=(const unsigned int uiData) const;
00275 bool operator!=(const bool bData) const;
00276 #ifdef USE_STL_BINDINGS
00277 bool operator!=(const std::wstring& rInstr) const;
00278 bool operator!=(const std::string& rInstr) const;
00279 #endif
00280 TString& operator+= (const TString& rInstr);
00281 TString& operator+= (const IString& rInstr);
00282 TString& operator+= (const wchar_t* pInbuffer);
00283 TString& operator+= (const char* pInbuffer);
00284 TString& operator+= (const wchar_t wc);
00285 TString& operator+= (const char c);
00286 TString& operator+= (const Int iInval);
00287 TString& operator+= (const int iInval);
00288 TString& operator+= (const Uint uiInval);
00289 TString& operator+= (const unsigned int uiInval);
00290 TString& operator+= (const Float fInval);
00291 #ifdef USE_STL_BINDINGS
00292 TString& operator+= (const std::wstring& rInstr);
00293 TString& operator+= (const std::string& rInstr);
00294 #endif //USE_STL_BINDINGS
00295
00296 wchar_t& operator[](Int iIndex);
00297 bool operator< (const TString& rInStr) const;
00298 bool operator<= (const TString& rInStr) const;
00299 bool operator> (const TString& rInStr) const;
00300 bool operator>= (const TString& rInStr) const;
00301
00302
00303
00304 bool containsChar(const wchar_t wcChar) const;
00305 bool containsCharOf(const wchar_t* wcChars) const;
00306 Int getFirstCharPos(const wchar_t wcChar) const;
00307 Int getFirstCharPosOf(const wchar_t* wcChars) const;
00308 Int getLastCharPos(const wchar_t wcChar) const;
00309 Int getLastCharPosOf(const wchar_t* wcChars) const;
00310 TString deleteSubString(Int iStartIndex, Int iEndIndex = IntMax) const;
00311 TString getSubString(Int iStartIndex, Int iEndIndex = IntMax) const;
00312 TString getLeft(Int iCharCount) const;
00313 TString getRight(Int iCharCount) const;
00314 TString deleteLeft(Int iCharCount) const;
00315 TString deleteRight(Int iCharCount) const;
00316 Int getSubStringCount(const IString& rSubstring) const;
00317 TString insert(Int iIndex, const IString& rStrToInsert) const;
00318 TString insert(Int iIndex, const TString& rStrToInsert) const;
00319 TString remove(const IString& rToRemove, Int* pReplaces = NULL) const;
00320 TString remove(const TString& strToRemove, Int* pReplaces = NULL) const;
00321 TString removeFirst(const IString& rToRemove) const;
00322 TString removeFirst(const TString& rToRemove) const;
00323 TString replace(const IString& rToRemove, const IString& rReplace, Int* pReplaces = NULL) const;
00324 TString replace(const TString& rToRemove, const TString& rReplace, Int* pReplaces = NULL) const;
00325 TString replaceFirst(const IString& rToRemove, const IString& rReplace) const;
00326 TString replaceFirst(const TString& rToRemove, const TString& rReplace) const;
00327 TString toUpperCase() const;
00328 TString toLowerCase() const;
00329 TString trim() const;
00330 TString trimLeft() const;
00331 TString trimRight() const;
00332 TString terminated(const IString& rTermination) const;
00333 TString terminated(const TString& rTermination) const;
00334 TString enclosed(const IString& rEnclosure) const;
00335 TString enclosed(const TString& rEnclosure) const;
00336 TString enquoted() const;
00337 Int64 getHash() const;
00338 const wchar_t* getPtrOfChar(Int iStartIndex, wchar_t wcChar) const;
00339 const wchar_t* getPtrOfFirstChar(wchar_t wcChar) const;
00340 const wchar_t* getPtrOfLastChar(wchar_t wcChar) const;
00341 const wchar_t* getPtrOfStr(Int iStartIndex, const IString& rSubString) const;
00342 const wchar_t* getPtrOfStr(Int iStartIndex, const TString& rSubString) const;
00343 const wchar_t* getPtrOfFirstStr(const IString& rSubString) const;
00344 const wchar_t* getPtrOfFirstStr(const TString& rSubString) const;
00345 const wchar_t* getPtrOfLastStr(const IString& rSubString) const;
00346 const wchar_t* getPtrOfLastStr(const TString& rSubString) const;
00347
00348 TString extractSubString(const TString& strBefore, const TString& strAfter = L"",
00349 Int iSearchStartPosForBeforeString = 0,
00350 Int* piSubStringPos = NULL) const;
00351
00352
00353
00354 virtual const wchar_t* MQUALIFIER c_bstr() const;
00355 virtual const char* MQUALIFIER c_str(BOOL_ERRORRETVAL(pError)) const;
00356 virtual Float MQUALIFIER toFloat(Float fPredef = 0.0, bool* pbError = NULL) const;
00357 virtual Int MQUALIFIER toInt(Int iPredef = 0, bool* pbError = NULL) const;
00358 virtual Uint MQUALIFIER toUint(Uint uiPredef = 0, bool* pbError = NULL) const;
00359 virtual Timeval MQUALIFIER toTimeval(Timeval tmPredef = 0, bool* pbError = NULL) const;
00360 virtual bool MQUALIFIER toBool(bool bPredef = false, bool* pbError = NULL) const;
00361 virtual bool MQUALIFIER isFloat() const;
00362 virtual bool MQUALIFIER isInt() const;
00363 virtual bool MQUALIFIER isBool() const;
00364 virtual bool MQUALIFIER equals(const wchar_t* pInbuffer, bool bIgnoreCase = false) const;
00365 virtual bool MQUALIFIER equalsStr(const IString& rInstr, bool bIgnoreCase = false) const;
00366 virtual void MQUALIFIER concat(const wchar_t* pInbuffer);
00367 virtual void MQUALIFIER concatStr(const IString& rInstr);
00368 virtual void MQUALIFIER assign(const wchar_t* pInbuffer);
00369 virtual void MQUALIFIER assignStr(const IString& rInstr);
00370 virtual Int MQUALIFIER getSize() const;
00371 virtual wchar_t MQUALIFIER getChar(Int iIndex) const;
00372 virtual Int MQUALIFIER getFirstPos(const wchar_t* pSubBuffer) const;
00373 virtual Int MQUALIFIER getFirstPosStr(const IString& rSubString) const;
00374 virtual Int MQUALIFIER getLastPos(const wchar_t* pSubBuffer) const;
00375 virtual Int MQUALIFIER getLastPosStr(const IString& rSubString) const;
00376 virtual void MQUALIFIER clear();
00377 virtual bool MQUALIFIER isEmpty() const;
00378 virtual bool MQUALIFIER endsWith(const wchar_t* pString) const;
00379 virtual bool MQUALIFIER endsWithStr(const IString& rString) const;
00380 virtual bool MQUALIFIER startsWith(const wchar_t* pString) const;
00381 virtual bool MQUALIFIER startsWithStr(const IString& rString) const;
00382 virtual Int MQUALIFIER compareTo(const IString& rString) const;
00383 virtual bool MQUALIFIER contains(const wchar_t* pSubString) const;
00384 virtual bool MQUALIFIER containsStr(const IString& rSubString) const;
00385 virtual Int MQUALIFIER getPos(Int iStartIndex, const wchar_t* pSubBuffer) const;
00386 virtual Int MQUALIFIER getPosOfStr(Int iStartIndex, const IString& rSubString) const;
00387
00388 protected:
00389 static TString convertDouble(const Float& rfValue, Int iDigit = 15);
00390
00391 private:
00393 wchar_t* m_pWBuffer;
00395 mutable char* m_pCBuffer;
00397 static wchar_t m_wcEmpty;
00399 mutable Int m_iSize;
00401 Uint m_uiMemSize;
00402
00403
00404 void clearBuffers();
00405 void clearWBuffer();
00406 void clearCBuffer() const;
00407 void updateSize() const;
00408 wchar_t* convToWStr(const char* pData);
00409 char* convToCStr(const wchar_t* pData, bool* pError) const;
00410
00411 void adoptPointer(wchar_t* pData, Uint uiMemSize);
00412 static void replace_internal(std::wstring& rData, Int iPos, Int iCharsToRemove, const std::wstring& rReplace);
00413 void assignInt32(Int32 lValue);
00414 void assignInt64(Int64 ldValue);
00415 void assignUint32(Uint32 ulValue);
00416 void assignUint64(Uint64 uldValue);
00417 };
00418
00419
00420
00421
00422
00423
00428
00429 inline TString::TString(const wchar_t* pData)
00430 : INIT_TSTRING
00431 {
00432 assign(pData);
00433 }
00434
00435
00439
00440 inline TString::TString(const IString& rString)
00441 : INIT_TSTRING
00442 {
00443 assign(rString.c_bstr());
00444 }
00445
00446
00450
00451 inline TString::TString(const TString& rString)
00452 #if defined(__COLINUX__)
00453 : IString(rString),
00454 INIT_TSTRING
00455 #else
00456 : INIT_TSTRING
00457 #endif
00458 {
00459 assign(rString.m_pWBuffer);
00460 }
00461
00462
00467
00468 inline TString::TString(const char* pData)
00469 : INIT_TSTRING
00470 {
00471
00472 convToWStr(pData);
00473 updateSize();
00474 }
00475
00476
00480
00481 inline TString::TString(Int32 lValue)
00482 : INIT_TSTRING
00483 {
00484 assignInt32(lValue);
00485 }
00486
00487
00491
00492 inline TString::TString(Int64 ldValue)
00493 : INIT_TSTRING
00494 {
00495 assignInt64(ldValue);
00496 }
00497
00498
00502
00503 inline TString::TString(Uint32 ulValue)
00504 : INIT_TSTRING
00505 {
00506 assignUint32(ulValue);
00507 }
00508
00509
00513
00514 inline TString::TString(Uint64 uldValue)
00515 : INIT_TSTRING
00516 {
00517 assignUint64(uldValue);
00518 }
00519
00520
00524
00525 inline TString::TString(int iValue)
00526 : INIT_TSTRING
00527 {
00528 #if defined(__ZEUS32__)
00529 assignInt32((Int32)iValue);
00530 #elif defined(__ZEUS64__)
00531 assignInt64((Int64)iValue);
00532 #else
00533 #error "TString::TString(int iValue): constructor not implemented for this platform"
00534 #endif
00535 }
00536
00537
00541
00542 inline TString::TString(unsigned int uiValue)
00543 : INIT_TSTRING
00544 {
00545 #if defined(__ZEUS32__)
00546 assignUint32((Uint32)uiValue);
00547 #elif defined(__ZEUS64__)
00548 assignUint64((Uint64)uiValue);
00549 #else
00550 #error "TString::TString(unsigned int uiValue): constructor not implemented for this platform"
00551 #endif
00552 }
00553
00554
00558
00559 inline TString::TString(Float fValue)
00560 : INIT_TSTRING
00561 {
00562 assignStr(convertDouble(fValue));
00563 }
00564
00565
00566
00570
00571 inline TString::TString(bool bValue)
00572 : INIT_TSTRING
00573 {
00574 assignInt32(bValue);
00575 }
00576
00577
00578
00583
00584 inline TString::TString(Float fValue, Uint uiDigits)
00585 : INIT_TSTRING
00586 {
00587 assignStr(convertDouble(fValue, (Int)uiDigits));
00588 }
00589
00590 #ifdef USE_STL_BINDINGS
00591
00595
00596 inline TString::TString(const std::wstring& rInstr)
00597 : INIT_TSTRING
00598 {
00599 assign(rInstr.c_str());
00600 }
00601
00602
00606
00607 inline TString::TString(const std::string& rInstr)
00608 : INIT_TSTRING
00609 {
00610 convToWStr(rInstr.c_str());
00611 }
00612 #endif
00613
00614
00615
00618
00619 inline TString::TString(wchar_t* pwcData, Uint uiBufferSize, bool bAdoptPointer)
00620 {
00621 m_pCBuffer = NULL;
00622
00623 if (bAdoptPointer)
00624 {
00625 m_pWBuffer = pwcData;
00626 m_uiMemSize = uiBufferSize;
00627 updateSize();
00628 }
00629 else
00630 {
00631 m_pWBuffer = NULL;
00632 m_iSize = 0;
00633 m_uiMemSize = 0;
00634 assign(pwcData);
00635 }
00636 }
00637
00638
00641
00642 inline void TString::clearBuffers()
00643 {
00644 clearCBuffer();
00645 clearWBuffer();
00646 }
00647
00648
00656
00657 inline TByteArray TString::transcode(const TString& rValue,
00658 bool bAsWideChar,
00659 bool bNullTerminated )
00660 {
00661 return TString::transcode((const IString&)rValue, bAsWideChar, bNullTerminated);
00662 }
00663
00664
00670
00671 inline bool TString::containsChar(const wchar_t wcChar) const
00672 {
00673 return (this->getFirstCharPos(wcChar) >= 0);
00674 }
00675
00676
00683
00684 inline TString TString::getLeft(Int iCharCount) const
00685 {
00686 return this->getSubString(0, iCharCount-1);
00687 }
00688
00689
00696
00697 inline TString TString::getRight(Int iCharCount) const
00698 {
00699 Int iSize = getSize();
00700 return this->getSubString(iSize - iCharCount, iSize-1);
00701 }
00702
00703
00709
00710 inline TString TString::deleteLeft(Int iCharCount) const
00711 {
00712
00713
00714 if (iCharCount > 0)
00715 {
00716 if (iCharCount < getSize())
00717 {
00718 return (m_pWBuffer + iCharCount);
00719 }
00720 else
00721 {
00722 return L"";
00723 }
00724 }
00725 else
00726 {
00727 return this;
00728 }
00729 }
00730
00731
00737
00738 inline TString TString::deleteRight(Int iCharCount) const
00739 {
00740 Int iSize = getSize();
00741 return getSubString(0, iSize-iCharCount-1);
00742 }
00743
00744
00750
00751 inline TString TString::insert(Int iIndex, const TString& rStrToInsert) const
00752 {
00753 return this->insert(iIndex, (const IString&)rStrToInsert);
00754 }
00755
00756
00763
00764 inline TString TString::remove(const IString& rToRemove, Int* pReplaces ) const
00765 {
00766 return replace(rToRemove, (const IString&)TString(L""), pReplaces);
00767 }
00768
00769
00776
00777 inline TString TString::remove(const TString& rToRemove, Int* pReplaces ) const
00778 {
00779 return replace((const IString&)rToRemove, (const IString&)TString(L""), pReplaces);
00780 }
00781
00782
00788
00789 inline TString TString::removeFirst(const IString& rToRemove) const
00790 {
00791 return replaceFirst((const IString&)rToRemove, (const IString&)TString(L""));
00792 }
00793
00794
00800
00801 inline TString TString::removeFirst(const TString& rToRemove) const
00802 {
00803 return replaceFirst((const IString&)rToRemove, (const IString&)TString(L""));
00804 }
00805
00806
00814
00815 inline TString TString::replaceFirst(const TString& rToRemove, const TString& rReplace) const
00816 {
00817 return replaceFirst((const IString&)rToRemove, (const IString&)rReplace);
00818 }
00819
00820
00825
00826 inline TString TString::terminated(const TString& rTermination) const
00827 {
00828 return terminated((const IString&) rTermination);
00829 }
00830
00831
00836
00837 inline TString TString::enclosed(const TString& rEnclosure) const
00838 {
00839 return enclosed((const IString&) rEnclosure);
00840 }
00841
00842
00851
00852 inline TString TString::replace(const TString& rToRemove, const TString& rReplace, Int* pReplaces ) const
00853 {
00854 return replace((const IString&)rToRemove, (const IString&)rReplace, pReplaces);
00855 }
00856
00857
00862
00863 inline TString TString::trim() const
00864 {
00865 return TString::trimExt(*this, TString(L" \t\r\n"), true, true);
00866 }
00867
00868
00873
00874 inline TString TString::trimLeft() const
00875 {
00876 return TString::trimExt(*this, TString(L" \t\r\n"), true, false);
00877 }
00878
00879
00884
00885 inline TString TString::trimRight() const
00886 {
00887 return TString::trimExt(*this, TString(L" \t\r\n"), false, true);
00888 }
00889
00890
00896
00897 inline TString TString::terminated(const IString& rTermination) const
00898 {
00899 TString strReturn = *this;
00900
00901 if (!strReturn.endsWithStr(rTermination))
00902 {
00903 strReturn += rTermination;
00904 }
00905
00906 return strReturn;
00907 }
00908
00909
00910
00916
00917 inline TString TString::enclosed(const IString& rEnclosure) const
00918 {
00919 TString strReturn = terminated(rEnclosure);
00920
00921 if (!this->startsWithStr(rEnclosure))
00922 {
00923 strReturn = TString(rEnclosure) + strReturn;
00924 }
00925
00926 return strReturn;
00927 }
00928
00929
00930
00935
00936 inline TString TString::enquoted() const
00937 {
00938 return enclosed(TString(L"\""));
00939 }
00940
00941
00944
00945 inline const wchar_t* TString::getPtrOfStr(Int iStartIndex, const TString& rSubString) const
00946 {
00947 return getPtrOfStr(iStartIndex, (const IString&)rSubString);
00948 }
00949
00950
00953
00954 inline const wchar_t* TString::getPtrOfFirstStr(const TString& rSubString) const
00955 {
00956 return getPtrOfFirstStr((const IString&)rSubString);
00957 }
00958
00959
00962
00963 inline const wchar_t* TString::getPtrOfLastStr(const TString& rSubString) const
00964 {
00965 return getPtrOfLastStr((const IString&)rSubString);
00966 }
00967
00968
00973
00974 inline TString TString::format(const char* pcFormat, ...)
00975 {
00976 va_list Args;
00977 va_start(Args, pcFormat);
00978 TString strRetval = formatV(pcFormat, Args);
00979 va_end(Args);
00980 return strRetval;
00981 }
00982
00983
00988
00989 inline TString TString::format(const wchar_t* pwcFormat, ...)
00990 {
00991 va_list Args;
00992 va_start(Args, pwcFormat);
00993 TString strRetval = formatV(pwcFormat, Args);
00994 va_end(Args);
00995 return strRetval;
00996 }
00997
00998
01003
01004 inline TString TString::format(const IString& rFormat, ...)
01005 {
01006 va_list Args;
01007 va_start(Args, rFormat);
01008 TString strRetval = formatV(rFormat, Args);
01009 va_end(Args);
01010 return strRetval;
01011 }
01012
01013
01014
01017
01018 inline const wchar_t* MQUALIFIER TString::c_bstr() const
01019 {
01020
01021 return m_pWBuffer;
01022 }
01023
01024
01027
01028 inline const char* MQUALIFIER TString::c_str(bool* pError) const
01029 {
01030 return convToCStr(m_pWBuffer, pError);
01031 }
01032
01033
01036
01037 inline bool MQUALIFIER TString::isFloat() const
01038 {
01039 bool bError = false;
01040 toFloat(0, &bError);
01041 return !bError;
01042 }
01043
01044
01045
01048
01049 inline bool MQUALIFIER TString::isInt() const
01050 {
01051 bool bError = false;
01052 toInt(0, &bError);
01053 return !bError;
01054 }
01055
01056
01057
01060
01061 inline bool MQUALIFIER TString::isBool() const
01062 {
01063 bool bError = false;
01064 toBool(false, &bError);
01065 return !bError;
01066 }
01067
01068
01069
01072
01073 inline bool MQUALIFIER TString::equalsStr(const IString& rInstr, bool bIgnoreCase ) const
01074 {
01075 return this->equals(rInstr.c_bstr(), bIgnoreCase);
01076 }
01077
01078
01081
01082 inline void MQUALIFIER TString::concatStr(const IString& rInstr)
01083 {
01084 concat(rInstr.c_bstr());
01085 }
01086
01087
01090
01091 inline void MQUALIFIER TString::assignStr(const IString& rInstr)
01092 {
01093 this->assign(rInstr.c_bstr());
01094 }
01095
01096
01097
01100
01101 inline wchar_t MQUALIFIER TString::getChar(Int iIndex) const
01102 {
01103 wchar_t wcRetval = 0x0000;
01104 Int iCounter = getSize();
01105
01106 if (iIndex < iCounter && iIndex >= 0 && m_pWBuffer != NULL)
01107 {
01108 wcRetval = m_pWBuffer[iIndex];
01109 }
01110 return wcRetval;
01111 }
01112
01113
01116
01117 inline Int MQUALIFIER TString::getSize() const
01118 {
01119 return m_iSize;
01120 }
01121
01122
01125
01126 inline Int MQUALIFIER TString::getFirstPos(const wchar_t* pSubBuffer) const
01127 {
01128 return getPos(0, pSubBuffer);
01129 }
01130
01131
01134
01135 inline Int MQUALIFIER TString::getFirstPosStr(const IString& rSubString)const
01136 {
01137 return getPos(0, rSubString.c_bstr());
01138 }
01139
01140
01143
01144 inline Int MQUALIFIER TString::getLastPosStr(const IString& rSubString)const
01145 {
01146 return getLastPos(rSubString.c_bstr());
01147 }
01148
01149
01150
01153
01154 inline void MQUALIFIER TString::clear()
01155 {
01156 if (m_pWBuffer != NULL)
01157 {
01158 m_pWBuffer[0] = 0;
01159 }
01160
01161 m_iSize = 0;
01162 }
01163
01164
01165
01168
01169 inline bool MQUALIFIER TString::isEmpty()const
01170 {
01171 return (getSize() == 0);
01172 }
01173
01174
01177
01178 inline bool MQUALIFIER TString::endsWith(const wchar_t* pString)const
01179 {
01180 return this->endsWithStr(TString(pString));
01181 }
01182
01183
01186
01187 inline bool MQUALIFIER TString::startsWith(const wchar_t* pString)const
01188 {
01189 return this->startsWithStr(TString(pString));
01190 }
01191
01192
01195
01196 inline bool MQUALIFIER TString::contains(const wchar_t* pSubString) const
01197 {
01198 return this->containsStr(TString(pSubString));
01199 }
01200
01201
01204
01205 inline bool MQUALIFIER TString::containsStr(const IString& rSubString) const
01206 {
01207 return (this->getFirstPosStr(rSubString) >= 0);
01208 }
01209
01210
01213
01214 inline Int MQUALIFIER TString::getPosOfStr(Int iStartIndex, const IString& rSubString) const
01215 {
01216 return getPos(iStartIndex, rSubString.c_bstr());
01217 }
01218
01219
01223
01224 inline TString& TString::operator=(const TString& rInstr)
01225 {
01226 assign(rInstr.m_pWBuffer);
01227 return *this;
01228 }
01229
01230
01234
01235 inline TString& TString::operator=(const IString& rInstr)
01236 {
01237 assign(rInstr.c_bstr());
01238 return *this;
01239 }
01240
01241
01242
01246
01247 inline TString& TString::operator=(const IString* pInstr)
01248 {
01249 if (pInstr == NULL)
01250 {
01251 clear();
01252 }
01253 else
01254 {
01255 assignStr(*pInstr);
01256 }
01257
01258 return *this;
01259 }
01260
01261
01262
01266
01267 inline TString& TString::operator=(const wchar_t* pData)
01268 {
01269 assign(pData);
01270 return *this;
01271 }
01272
01273
01277
01278 inline TString& TString::operator=(const Int iData)
01279 {
01280 #if defined(__ZEUS32__)
01281 this->assignInt32(iData);
01282 #elif defined(__ZEUS64__)
01283 this->assignInt64(iData);
01284 #else
01285 #error "TString::operator =(const Int iData): assign operator not implemented for this platform"
01286 #endif
01287 return *this;
01288 }
01289
01290
01294
01295 inline TString& TString::operator=(const int iData)
01296 {
01297 #if defined(__ZEUS32__)
01298 this->assignInt32(iData);
01299 #elif defined(__ZEUS64__)
01300 this->assignInt64(iData);
01301 #else
01302 #error "TString::operator =(const int iData): assign operator not implemented for this platform"
01303 #endif
01304 return *this;
01305 }
01306
01307
01311
01312 inline TString& TString::operator=(const Uint uiData)
01313 {
01314 #if defined(__ZEUS32__)
01315 this->assignUint32(static_cast<Uint32>(uiData));
01316 #elif defined(__ZEUS64__)
01317 this->assignUint64(static_cast<Uint32>(uiData));
01318 #else
01319 #error "TString::operator =(const Uint uiData): assign operator not implemented for this platform"
01320 #endif
01321 return *this;
01322 }
01323
01324
01328
01329 inline TString& TString::operator=(const unsigned int uiData)
01330 {
01331 #if defined(__ZEUS32__)
01332 this->assignUint32(static_cast<Uint32>(uiData));
01333 #elif defined(__ZEUS64__)
01334 this->assignUint64(static_cast<Uint32>(uiData));
01335 #else
01336 #error "TString::operator =(const unsigned int uiData): assign operator not implemented for this platform"
01337 #endif
01338 return *this;
01339 }
01340
01341
01345
01346 inline TString& TString::operator=(const Float fData)
01347 {
01348 TString strValue = convertDouble(fData);
01349 this->assign(strValue.m_pWBuffer);
01350 return *this;
01351 }
01352
01353
01354
01358
01359 inline TString& TString::operator=(const char* pData)
01360 {
01361 m_pWBuffer = convToWStr(pData);
01362 return *this;
01363 }
01364
01365
01366
01370
01371 inline TString& TString::operator=(bool bData)
01372 {
01373 assignInt32(bData);
01374 return *this;
01375 }
01376
01377
01378 #ifdef USE_STL_BINDINGS
01379
01383
01384 inline TString& TString::operator=(const std::wstring& rInstr)
01385 {
01386 assign(rInstr.c_str());
01387 return *this;
01388 }
01389
01390
01394
01395 inline TString& TString::operator=(const std::string& rInstr)
01396 {
01397 m_pWBuffer = convToWStr(rInstr.c_str());
01398 return *this;
01399 }
01400 #endif //USE_STL_BINDINGS
01401
01402
01406
01407 inline bool TString::operator==(const TString& rInstr)const
01408 {
01409 return equals(rInstr.m_pWBuffer);
01410 }
01411
01412
01416
01417 inline bool TString::operator==(const IString& rInstr)const
01418 {
01419 return equals(rInstr.c_bstr());
01420 }
01421
01422
01423
01428
01429 inline bool TString::operator==(const IString* pInstr) const
01430 {
01431 return equals(pInstr == NULL ? NULL : pInstr->c_bstr());
01432 }
01433
01434
01435
01439
01440 inline bool TString::operator==(const wchar_t* pInbuffer) const
01441 {
01442 return equals(pInbuffer);
01443 }
01444
01445
01449
01450 inline bool TString::operator==(const char* inbuffer)const
01451 {
01452 TString str(inbuffer);
01453 return equals(str.m_pWBuffer);
01454 }
01455
01456
01460
01461 inline bool TString::operator==(const Float fData) const
01462 {
01463 TString strFormat = convertDouble(fData);
01464 return equals(strFormat.m_pWBuffer);
01465 }
01466
01467
01471
01472 inline bool TString::operator==(const Int iData) const
01473 {
01474 TString strData(iData);
01475 return equalsStr(strData);
01476 }
01477
01478
01482
01483 inline bool TString::operator==(const int iData) const
01484 {
01485 TString strData(iData);
01486 return equalsStr(strData);
01487 }
01488
01489
01493
01494 inline bool TString::operator==(const Uint uiData) const
01495 {
01496 TString strData(uiData);
01497 return equalsStr(strData);
01498 }
01499
01500
01504
01505 inline bool TString::operator==(const unsigned int uiData) const
01506 {
01507 TString strData(uiData);
01508 return equalsStr(strData);
01509 }
01510
01511
01512
01516
01517 inline bool TString::operator==(bool bData) const
01518 {
01519 TString strData(bData);
01520 return equalsStr(strData);
01521 }
01522
01523
01524 #ifdef USE_STL_BINDINGS
01525
01528
01529 inline bool TString::operator==(const std::wstring& rInstr)const
01530 {
01531 TString str(rInstr.c_str());
01532 return equals(str.m_pWBuffer);
01533 }
01534
01535
01538
01539 inline bool TString::operator==(const std::string& rInstr)const
01540 {
01541 TString str(rInstr.c_str());
01542 return equals(str.m_pWBuffer);
01543 }
01544 #endif // USE_STL_BINDINGS
01545
01546
01550
01551 inline TString TString::operator+ (const TString& rInstr) const
01552 {
01553 TString str(this->m_pWBuffer);
01554 str.concat(rInstr.m_pWBuffer);
01555 return str;
01556 }
01557
01558
01562
01563 inline TString TString::operator+ (const IString& rInstr) const
01564 {
01565 TString str(this->m_pWBuffer);
01566 str.concat(rInstr.c_bstr());
01567 return str;
01568 }
01569
01570
01574
01575 inline TString TString::operator+ (const wchar_t* pInbuffer) const
01576 {
01577 TString str(this->m_pWBuffer);
01578 str.concat(pInbuffer);
01579 return str;
01580 }
01581
01582
01586
01587 inline TString TString::operator+ (const char* pInbuffer) const
01588 {
01589 TString str(this->m_pWBuffer);
01590 TString strC(pInbuffer);
01591 str.concat(strC.m_pWBuffer);
01592 return str;
01593 }
01594
01595
01599
01600 inline TString TString::operator+ (const wchar_t wc) const
01601 {
01602 TString str(this->m_pWBuffer);
01603
01604 wchar_t wcBuffer[2] = { wc, 0 };
01605 str.concat(wcBuffer);
01606 return str;
01607 }
01608
01609
01613
01614 inline TString TString::operator+ (const char c) const
01615 {
01616 TString str(this->m_pWBuffer);
01617
01618 wchar_t wcBuffer[2] = { (wchar_t)c, 0 };
01619 str.concat(wcBuffer);
01620 return str;
01621 }
01622
01623
01627
01628 inline TString TString::operator+ (const Int iInval) const
01629 {
01630 TString str(this->m_pWBuffer);
01631 TString strInval(iInval);
01632 str.concatStr(strInval);
01633 return str;
01634 }
01635
01636
01640
01641 inline TString TString::operator+ (const int iInval) const
01642 {
01643 TString str(this->m_pWBuffer);
01644 TString strInval(iInval);
01645 str.concatStr(strInval);
01646 return str;
01647 }
01648
01649
01653
01654 inline TString TString::operator+ (const Uint uiInval) const
01655 {
01656 TString str(this->m_pWBuffer);
01657 TString strInval(uiInval);
01658 str.concatStr(strInval);
01659 return str;
01660 }
01661
01662
01666
01667 inline TString TString::operator+ (const unsigned int uiInval) const
01668 {
01669 TString str(this->m_pWBuffer);
01670 TString strInval(uiInval);
01671 str.concatStr(strInval);
01672 return str;
01673 }
01674
01675
01679
01680 inline TString TString::operator+ (const Float fInval) const
01681 {
01682 TString strTmp(this->m_pWBuffer);
01683 TString strConv = convertDouble(fInval);
01684 strTmp.concatStr(strConv);
01685 return strTmp;
01686 }
01687
01688 #ifdef USE_STL_BINDINGS
01689
01690
01693
01694 inline TString TString::operator+ (const std::wstring& rInstr) const
01695 {
01696 TString str(this->m_pWBuffer);
01697 TString strC(rInstr.c_str());
01698 str.concat(strC.m_pWBuffer);
01699 return str;
01700 }
01701
01702
01705
01706 inline TString TString::operator+ (const std::string& rInstr) const
01707 {
01708 TString str(this->m_pWBuffer);
01709 TString strC(rInstr.c_str());
01710 str.concat(strC.m_pWBuffer);
01711 return str;
01712 }
01713 #endif //USE_STL_BINDINGS
01714
01715
01719
01720 inline bool TString::operator!=(const TString& rInstr) const
01721 {
01722 return !(equals(rInstr.m_pWBuffer));
01723 }
01724
01725
01729
01730 inline bool TString::operator!=(const IString& rInstr) const
01731 {
01732 return !(equals(rInstr.c_bstr()));
01733 }
01734
01735
01736
01741
01742 inline bool TString::operator!=(const IString* pInstr) const
01743 {
01744 return !equals(pInstr == NULL ? NULL : pInstr->c_bstr());
01745 }
01746
01747
01748
01752
01753 inline bool TString::operator!=(const wchar_t* pInbuffer)const
01754 {
01755 return !(equals(pInbuffer));
01756 }
01757
01758
01762
01763 inline bool TString::operator!=(const char* pInbuffer) const
01764 {
01765 TString str(pInbuffer);
01766 return !(equals(str.m_pWBuffer));
01767 }
01768
01769
01773
01774 inline bool TString::operator!=(const Float fData) const
01775 {
01776 TString str(fData);
01777 return !(equals(str.m_pWBuffer));
01778 }
01779
01780
01784
01785 inline bool TString::operator!=(const Int iData) const
01786 {
01787 TString str(iData);
01788 return !(equals(str.m_pWBuffer));
01789 }
01790
01791
01795
01796 inline bool TString::operator!=(const int iData) const
01797 {
01798 TString str(iData);
01799 return !(equals(str.m_pWBuffer));
01800 }
01801
01802
01806
01807 inline bool TString::operator!=(const Uint uiData) const
01808 {
01809 TString str(uiData);
01810 return !(equals(str.m_pWBuffer));
01811 }
01812
01813
01817
01818 inline bool TString::operator!=(const unsigned int uiData) const
01819 {
01820 TString str(uiData);
01821 return !(equals(str.m_pWBuffer));
01822 }
01823
01824
01825
01828
01829 inline bool TString::operator!=(bool bData) const
01830 {
01831 TString str(bData);
01832 return !(equals(str.m_pWBuffer));
01833 }
01834
01835
01836 #ifdef USE_STL_BINDINGS
01837
01840
01841 inline bool TString::operator!=(const std::wstring& rInstr) const
01842 {
01843 TString str(rInstr.c_str());
01844 return !equals(str.m_pWBuffer);
01845 }
01846
01847
01850
01851 inline bool TString::operator!=(const std::string& rInstr) const
01852 {
01853 TString str(rInstr.c_str());
01854 return !equals(str.m_pWBuffer);
01855 }
01856 #endif //USE_STL_BINDINGS
01857
01858
01863
01864 inline TString& TString::operator+= (const TString& rInstr)
01865 {
01866 this->concatStr(rInstr);
01867 return *this;
01868 }
01869
01870
01875
01876 inline TString& TString::operator+= (const IString& rInstr)
01877 {
01878 this->concatStr(rInstr);
01879 return *this;
01880 }
01881
01882
01887
01888 inline TString& TString::operator+= (const wchar_t* pInbuffer)
01889 {
01890 this->concat(pInbuffer);
01891 return *this;
01892 }
01893
01894
01899
01900 inline TString& TString::operator+= (const char* pInbuffer)
01901 {
01902 TString strInBuffer(pInbuffer);
01903 this->concatStr(strInBuffer);
01904 return *this;
01905 }
01906
01907
01908
01915
01916 inline TString& TString::operator+=(const wchar_t wc)
01917 {
01918 wchar_t wcBuffer[2] = { wc, 0 };
01919 concat(wcBuffer);
01920
01921 return *this;
01922 }
01923
01924
01925
01932
01933 inline TString& TString::operator+=(const char c)
01934 {
01935 wchar_t wcBuffer[2] = { (wchar_t)c, 0 };
01936 concat(wcBuffer);
01937
01938 return *this;
01939 }
01940
01941
01942
01947
01948 inline TString& TString::operator+= (const Int iInval)
01949 {
01950 TString strInVal(iInval);
01951 this->concatStr(strInVal);
01952 return *this;
01953 }
01954
01955
01960
01961 inline TString& TString::operator+= (const int iInval)
01962 {
01963 TString strInVal(iInval);
01964 this->concatStr(strInVal);
01965 return *this;
01966 }
01967
01968
01973
01974 inline TString& TString::operator+= (const Uint uiInval)
01975 {
01976 TString strInVal(uiInval);
01977 this->concatStr(strInVal);
01978 return *this;
01979 }
01980
01981
01986
01987 inline TString& TString::operator+= (const unsigned int uiInval)
01988 {
01989 TString strInVal(uiInval);
01990 this->concatStr(strInVal);
01991 return *this;
01992 }
01993
01994
01999
02000 inline TString& TString::operator+= (const Float fInval)
02001 {
02002 TString strInVal(fInval);
02003 this->concatStr(strInVal);
02004 return *this;
02005 }
02006
02007 #ifdef USE_STL_BINDINGS
02008
02012
02013 inline TString& TString::operator+= (const std::wstring& rInstr)
02014 {
02015 TString strIn(rInstr.c_str());
02016 this->concatStr(strIn);
02017 return *this;
02018 }
02019
02020
02024
02025 inline TString& TString::operator+= (const std::string& rInstr)
02026 {
02027 TString strIn(rInstr.c_str());
02028 this->concatStr(strIn);
02029 return *this;
02030 }
02031 #endif
02032
02033
02038
02039 inline wchar_t& TString::operator[](Int iIndex)
02040 {
02041 Int iCounter = getSize();
02042 if (iIndex < iCounter && iIndex >= 0 && m_pWBuffer != NULL)
02043 {
02044 return m_pWBuffer[iIndex];
02045 }
02046 else
02047 {
02048 m_wcEmpty = 0x0000;
02049 return m_wcEmpty;
02050 }
02051 }
02052
02053
02060
02061 inline bool TString::operator<(const TString& rInStr) const
02062 {
02063 return (this->compareTo(rInStr) < 0);
02064 }
02065
02066
02073
02074 inline bool TString::operator<=(const TString& rInStr) const
02075 {
02076 return (this->compareTo(rInStr) <= 0);
02077 }
02078
02079
02086
02087 inline bool TString::operator>(const TString& rInStr) const
02088 {
02089 return (this->compareTo(rInStr) > 0);
02090 }
02091
02092
02099
02100 inline bool TString::operator>=(const TString& rInStr) const
02101 {
02102 return (this->compareTo(rInStr) >= 0);
02103 }
02104
02105
02106
02107
02108
02109
02112
02113 inline TString operator+ (wchar_t* pIn, const TString& rIn2)
02114 {
02115 return (TString(pIn) + rIn2);
02116 }
02117
02118
02121
02122 inline bool operator== (const IString& rInStr1, const wchar_t* pInStr2)
02123 {
02124 return (TString(pInStr2) == rInStr1);
02125 }
02126
02127
02130
02131 inline bool operator== (const wchar_t* pInStr1, const IString& rInStr2)
02132 {
02133 return (TString(pInStr1) == rInStr2);
02134 }
02135
02136
02139
02140 inline bool operator== (const IString& rInStr1, const char* pInStr2)
02141 {
02142 return (TString(pInStr2) == rInStr1);
02143 }
02144
02145
02148
02149 inline bool operator== (const char* pInStr1, const IString& rInStr2)
02150 {
02151 return (TString(pInStr1) == rInStr2);
02152 }
02153
02154
02157
02158 inline bool operator!=(const IString& rInStr1, const wchar_t* pInStr2)
02159 {
02160 return (TString(pInStr2) != rInStr1);
02161 }
02162
02163
02166
02167 inline bool operator!=(const wchar_t* pInStr1, const IString& rInStr2)
02168 {
02169 return (TString(pInStr1) != rInStr2);
02170 }
02171
02172
02175
02176 inline bool operator!=(const IString& rInStr1, const char* pInStr2)
02177 {
02178 return (TString(pInStr2) != rInStr1);
02179 }
02180
02181
02184
02185 inline bool operator!=(const char* pInStr1, const IString& rInStr2)
02186 {
02187 return (TString(pInStr1) != rInStr2);
02188 }
02189
02190 #ifdef USE_STL_BINDINGS
02191
02194
02195 inline void operator<<(std::string& rOutstr, const TString& rInstr)
02196 {
02197 rOutstr = rInstr.c_str(NULL);
02198 }
02199
02200
02203
02204 inline void operator<<(std::wstring& rOutstr, const TString& rInstr)
02205 {
02206 rOutstr = rInstr.c_bstr();
02207 }
02208 #endif //USE_STL_BINDINGS
02209
02210
02211 END_NAMESPACE_Zeus
02212
02213 #endif