00001
00004 #ifndef _FBXSDK_KSTRING_H_
00005 #define _FBXSDK_KSTRING_H_
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
00033
00034
00035
00036
00037
00038
00039
00040
00041 #include <kbaselib_h.h>
00042
00043 #if defined(KARCH_ENV_WIN32)
00044
00045
00046 #define UTF8_to_WIDECHAR( inUTF8,outWideChar ) \
00047 wchar_t outWideChar[1024]; \
00048 MultiByteToWideChar( CP_UTF8, 0, inUTF8, -1, outWideChar, 1024 );
00049
00050 #define WIDECHAR_to_UTF8( inWideChar,outUTF8 ) \
00051 char outUTF8[1024]; \
00052 WideCharToMultiByte( CP_UTF8,0,inWideChar,-1,outUTF8,1024,NULL,NULL);
00053
00054 #define WIDECHAR_to_ANSI( inWideChar,outANSI ) \
00055 char outANSI[1024]; \
00056 WideCharToMultiByte( CP_ACP,0,inWideChar,-1,outANSI,1024,NULL,NULL);
00057
00058 #define ANSI_to_WIDECHAR( inANSI,outWideChar ) \
00059 wchar_t outWideChar[1024]; \
00060 MultiByteToWideChar( CP_ACP, 0, inANSI, -1, outWideChar, 1024 );
00061
00062 #define ANSI_to_UTF8( inANSI,outUTF8 ) { \
00063 wchar_t tempWideChar[1024]; \
00064 MultiByteToWideChar( CP_ACP, 0, inANSI, -1, tempWideChar, 1024); \
00065 WideCharToMultiByte( CP_UTF8, 0, tempWideChar, -1, outUTF8, 1024, NULL, NULL); \
00066 }
00067
00068 #define UTF8_to_ANSI( inUTF8,outANSI, dummy, dummy1 ) { \
00069 wchar_t tempWideChar[1024]; \
00070 MultiByteToWideChar( CP_UTF8, 0, inUTF8, -1, tempWideChar, 1024); \
00071 WideCharToMultiByte( CP_ACP, 0, tempWideChar, -1, outANSI, 1024, NULL, NULL); \
00072 }
00073 #endif
00074
00075
00076 #include <kbaselib_nsbegin.h>
00077
00078 #if !defined(KARCH_ENV_WIN32)
00079 KBASELIB_DLL void UTF8_to_ANSI( const char* pSrc, char* pDest, int pDestSize, char pSubstitute = '.' );
00080 #endif
00081
00082 #define KStringStaticSize 64
00083
00087 class KBASELIB_DLL KString
00088 {
00089 public:
00094
00095 static KString *Create();
00097 static KString *Create(KString *pString);
00099 void Destroy();
00101 static KString* DestroyIfEmpty(KString *pString);
00103 static KString* StringOrEmpty(KString *pString);
00105
00106 public:
00107
00112
00114 KString();
00115
00117 KString(const KString& pStr);
00118
00120 KString(const char* pStr);
00121
00123 KString(char pChar, int pNbRepeat = 1);
00124
00126 KString(const char* pCharPtr, int pLength);
00127
00129 KString(const int pValue);
00130
00132 KString(const float pValue);
00133
00135 KString(const double pValue);
00136
00138 ~KString();
00139
00141
00146
00148 bool IsOK() const;
00149
00151 KString &Invalidate();
00152
00154 int GetLen() const;
00155
00157 bool IsEmpty() const;
00158
00160 KString &Empty();
00161
00163
00168
00170 char& operator[](int pIndex);
00171
00173 char operator[](int pIndex) const;
00174
00176 operator const char*() const;
00177
00179 char* ToChars() const;
00180
00182 char* Buffer();
00183
00185 char* GetBuffer();
00186
00188
00193
00195 const KString& operator=(const KString& pStr);
00196
00198 const KString& operator=(char pChar);
00199
00201 const KString& operator=(const char* pStr);
00202
00204 const KString& operator=(int pValue);
00205
00207 const KString& operator=(float pValue);
00208
00210 const KString& operator=(double pValue);
00211
00213 const KString& Copy(int pLen, const char* pStr);
00214
00216
00221
00223 const KString& Append(const char* pStr);
00224
00226 const KString& AppendN(const char* pStr, int pLength);
00227
00229 const KString& operator+=(const KString& pKStr);
00230
00232 const KString& operator+=(char pChar);
00233
00235 const KString& operator+=(const char* pStr);
00236
00238 const KString& operator+=(int pValue);
00239
00241 const KString& operator+=(float pValue);
00242
00244 friend KBASELIB_DLL KString operator+(const KString& pKStr1, const KString& pKStr2);
00245
00247 friend KBASELIB_DLL KString operator+(const KString& pKStr, char pChar);
00248
00250 friend KBASELIB_DLL KString operator+(const KString& pKStr, const char* pStr);
00251
00253 friend KBASELIB_DLL KString operator+(const KString& pKStr, int pValue);
00254
00256 friend KBASELIB_DLL KString operator+(const KString& pKStr, float pValue);
00257
00259
00264
00266 int Compare(const char * pStr) const;
00267
00269 int CompareNoCase( const char * pStr ) const;
00270
00272 bool operator==(const KString &pStr) const;
00273
00275 bool operator!=(const KString &pStr) const;
00276
00278 bool operator< (const KString &pStr) const;
00279
00281 bool operator<=(const KString &pStr) const;
00282
00284 bool operator>=(const KString &pStr) const;
00285
00287 bool operator> (const KString &pStr) const;
00288
00290 bool operator==(const char *pStr) const;
00291
00293 bool operator!=(const char *pStr) const;
00294
00296 bool operator< (const char *pStr) const;
00297
00299 bool operator<=(const char *pStr) const;
00300
00302 bool operator>=(const char *pStr) const;
00303
00305 bool operator> (const char *pStr) const;
00306
00308
00313
00315 KString Mid(int pFirst, int pCount) const;
00316
00318 KString Mid(int pFirst) const;
00319
00321 KString Left(int pCount) const;
00322
00324 KString Right(int pCount) const;
00325
00327
00332
00334 enum PaddingType { eRight, eLeft, eBoth };
00335
00337 KString Pad(PaddingType pPadding, int pLen, char pCar = ' ') const;
00338
00340 KString UnPad(PaddingType pPadding) const;
00341
00343
00348
00350 KString Upper() const;
00351
00353 KString Lower() const;
00354
00356 KString Reverse() const;
00357
00359 KString ConvertToUnix() const;
00360
00362 KString ConvertToWindows() const;
00363
00365
00370
00374 int Find(char pChar, int pStartPosition = 0) const;
00375
00379 int Find(const char* pStrSub, int pStartPosition = 0) const;
00380
00384 int ReverseFind(char pChar) const;
00385
00389 int FindOneOf(const char * pStrCharSet, int pStartPosition = 0) const;
00390
00394 bool FindAndReplace(const char* pFind, const char* pReplaceBy, int pStartPosition = 0);
00395
00397
00402
00404 int GetTokenCount(const char* pSpans);
00405
00407 KString GetToken(int pTokenIndex, const char* pSpans);
00408
00410
00412
00413
00414
00415
00416
00417
00419
00420 #ifndef DOXYGEN_SHOULD_SKIP_THIS
00421
00422 private:
00423
00424
00425
00426 char *mData;
00427 int mDataLen;
00428 int mAllocLen;
00429 char mStaticData[KStringStaticSize];
00430
00431 void Init();
00432 void FreeBuffer();
00433 void FreeBuffer(char *&pOldData);
00434
00435 bool AllocCopy(KString& pDest, int pCopyLen, int pCopyIndex) const;
00436 bool AllocBuffer(int pLen);
00437 bool AllocBuffer(int pLen, char *&pOldData);
00438
00439 bool AssignCopy(int pSrcLen, const char * pSrcData);
00440 bool ConcatCopy(int pSrc1Len, const char * pSrc1Data,
00441 int pSrc2Len, const char * pSrc2Data);
00442 bool ConcatInPlace(int pSrcLen, const char * pSrcData);
00443
00444 bool IsIn(char pChar, const char* pString);
00445
00446 #endif // #ifndef DOXYGEN_SHOULD_SKIP_THIS
00447
00448 };
00449
00451 KBASELIB_DLL KString operator+(const KString& pKStr1, const KString& pKStr2);
00452
00454 KBASELIB_DLL KString operator+(const KString& pKStr, char pChar);
00455
00457 KBASELIB_DLL KString operator+(const KString& pKStr, const char* pStr);
00458
00460 KBASELIB_DLL KString operator+(const KString& pKStr, int pValue);
00461
00463 KBASELIB_DLL KString operator+(const KString& pKStr, float pValue);
00464
00465
00466
00467 inline void StripQuotationMarks(KString& str)
00468 {
00469 str = str.Mid( 1, str.GetLen() - 2 );
00470 }
00471
00472 inline void RemoveChar( KString& pString, char lToRemove )
00473 {
00474 int lPos = pString.ReverseFind( lToRemove );
00475
00476 while( lPos >= 0 )
00477 {
00478 pString = pString.Left( lPos ) + pString.Mid( lPos + 1 );
00479 lPos = pString.ReverseFind( lToRemove );
00480 }
00481 }
00482
00483 #include <kbaselib_nsend.h>
00484
00485 #endif // #define _FBXSDK_KSTRING_H_
00486