FBX C++ API Reference
fbxstring.h
Go to the documentation of this file.
1 /****************************************************************************************
2 
3  Copyright (C) 2015 Autodesk, Inc.
4  All rights reserved.
5 
6  Use of this software is subject to the terms of the Autodesk license agreement
7  provided at the time of installation or download, or which otherwise accompanies
8  this software in either electronic or hard copy form.
9 
10 ****************************************************************************************/
11 
13 #ifndef _FBXSDK_CORE_BASE_STRING_H_
14 #define _FBXSDK_CORE_BASE_STRING_H_
15 
16 #include <fbxsdk/fbxsdk_def.h>
17 
18 #include <fbxsdk/fbxsdk_nsbegin.h>
19 
25 FBXSDK_DLL void FbxUTF8ToWC(const char* pInUTF8, wchar_t*& pOutWideChar, size_t* pOutWideCharSize=NULL);
26 
32 FBXSDK_DLL void FbxWCToUTF8(const wchar_t* pInWideChar, char*& pOutUTF8, size_t* pOutUTF8Size=NULL);
33 
34 #if defined(FBXSDK_ENV_WIN)
35 
40  FBXSDK_DLL void FbxWCToAnsi(const wchar_t* pInWideChar, char*& pOutANSI, size_t* pOutANSISize=NULL);
41 
47  FBXSDK_DLL void FbxAnsiToWC(const char* pInANSI, wchar_t*& pOutWideChar, size_t* pOutWideCharSize=NULL);
48 
54  FBXSDK_DLL void FbxAnsiToUTF8(const char* pInANSI, char*& pOutUTF8, size_t* pOutUTF8Size=NULL);
55 
61  FBXSDK_DLL void FbxUTF8ToAnsi(const char* pInUTF8, char*& pOutANSI, size_t* pOutANSISize=NULL);
62 #endif
63 
67 {
68 public:
73  FbxString();
75 
78  FbxString(const FbxString& pString);
79 
82  FbxString(const char* pString);
83 
87  FbxString(char pChar, size_t pNbRepeat=1);
88 
92  FbxString(const char* pCharPtr, size_t pLength);
93 
96  FbxString(const int pValue);
97 
100  FbxString(const float pValue);
101 
104  FbxString(const double pValue);
105 
107  ~FbxString();
109 
114  size_t GetLen() const;
116 
118  size_t Size() const;
119 
121  bool IsEmpty() const;
122 
124  FbxString& Clear();
125 
129  char& operator[](int pIndex);
130 
134  char operator[](int pIndex) const;
135 
137  char* Buffer();
138 
140  const char* Buffer()const;
142 
149  const FbxString& operator=(const FbxString& pString);
150 
153  const FbxString& operator=(char pChar);
154 
157  const FbxString& operator=(const char* pString);
158 
161  const FbxString& operator=(int pValue);
162 
165  const FbxString& operator=(float pValue);
166 
169  const FbxString& operator=(double pValue);
170 
173  const FbxString& operator+=(const FbxString& pString);
174 
177  const FbxString& operator+=(char pChar);
178 
181  const FbxString& operator+=(const char* pString);
182 
185  const FbxString& operator+=(int pValue);
186 
189  const FbxString& operator+=(float pValue);
190 
193  const FbxString& operator+=(double pValue);
194 
197  bool operator== (const FbxString& pString) const;
198 
201  bool operator!= (const FbxString& pString) const;
202 
205  bool operator< (const FbxString& pString) const;
206 
209  bool operator<= (const FbxString& pString) const;
210 
213  bool operator>= (const FbxString& pString) const;
214 
217  bool operator> (const FbxString& pString) const;
218 
221  bool operator== (const char* pString) const;
222 
225  bool operator!= (const char* pString) const;
226 
229  bool operator< (const char* pString) const;
230 
233  bool operator<= (const char* pString) const;
234 
237  bool operator>= (const char* pString) const;
238 
241  bool operator> (const char* pString) const;
242 
246  friend FBXSDK_DLL FbxString operator+(const FbxString& pString1, const FbxString& pString2);
247 
251  friend FBXSDK_DLL FbxString operator+(const FbxString& pString, char pChar);
252 
256  friend FBXSDK_DLL FbxString operator+(char pChar, const FbxString& pString);
257 
261  friend FBXSDK_DLL FbxString operator+(const FbxString& pString1, const char* pString2);
262 
266  friend FBXSDK_DLL FbxString operator+(const char* pString1, const FbxString& pString2);
267 
271  friend FBXSDK_DLL FbxString operator+(const FbxString& pString, int pValue);
272 
276  friend FBXSDK_DLL FbxString operator+(int pValue, const FbxString& pString);
277 
281  friend FBXSDK_DLL FbxString operator+(const FbxString& pString, float pValue);
282 
286  friend FBXSDK_DLL FbxString operator+( float pValue, const FbxString& pString);
287 
291  friend FBXSDK_DLL FbxString operator+(const FbxString& pString, double pValue);
292 
294  operator const char*() const;
295 
299  const FbxString& Copy(const char* pString, size_t pLength);
300 
304  const FbxString& Append(const char* pString, size_t pLength);
305 
308  int Compare(const char* pString) const;
309 
312  int CompareNoCase(const char* pString) const;
313 
316  void Swap(FbxString& pString);
317 
319  FbxString Upper() const;
320 
322  FbxString Lower() const;
324 
332  FbxString Mid(size_t pFirst, size_t pCount) const;
333 
336  FbxString Mid(size_t pFirst) const;
337 
340  FbxString Left(size_t pCount) const;
341 
344  FbxString Right(size_t pCount) const;
346 
355  enum EPaddingType {eRight, eLeft, eBoth};
356 
361  FbxString Pad(EPaddingType pPadding, size_t pLen, char pCar=' ') const;
362 
367  FbxString UnPad(EPaddingType pPadding, char pCar='\0') const;
369 
378  int Find(char pChar, size_t pStartPosition=0) const;
379 
384  int Find(const char* pStrSub, size_t pStartPosition=0) const;
385 
389  int ReverseFind(char pChar) const;
390 
395  int FindOneOf(const char* pStrCharSet, size_t pStartPosition=0) const;
396 
402  bool FindAndReplace(const char* pFind, const char* pReplaceBy, size_t pStartPosition=0);
403 
408  bool ReplaceAll(const char* pFind, const char* pReplaceBy);
409 
414  bool ReplaceAll(char pFind, char pReplaceBy);
416 
424  int GetTokenCount(const char* pSpans) const;
425 
429  FbxString GetToken(int pTokenIndex, const char* pSpans) const;
431 
432 private:
433  // Lengths/sizes in characters.
434  // Note: an extra character is always allocated.
435  char* mData; // Actual string (zero terminated).
436 
437  FbxString(size_t pSrc1Len, const char* pSrc1Data, size_t pSrc2Len, const char* pSrc2Data); // Previously ConcatCopy
438  void Init();
439 
441  void Invalidate();
442 
443  void FreeBuffer();
444  void FreeBuffer(char *&pOldData);
445 
446  bool AllocCopy(FbxString& pDest, size_t pCopyLen, size_t pCopyIndex) const;
447  bool AllocBuffer(size_t pLen);
448  bool AllocBuffer(size_t pLen, char*& pOldData);
449 
450  bool AssignCopy(size_t pSrcLen, const char* pSrcData);
451  bool ConcatInPlace(size_t pSrcLen, const char* pSrcData);
452 
453  bool IsIn(char pChar, const char* pString) const;
454  bool InternalFindAndReplace(const char* pFind, const char* pReplaceBy, size_t& pStartPosition);
455 };
456 
458 
460 FBXSDK_DLL FbxString operator+(const FbxString& pString1, const FbxString& pString2);
461 
463 FBXSDK_DLL FbxString operator+(const FbxString& pString, char pChar);
464 
466 FBXSDK_DLL FbxString operator+(const FbxString& pString1, const char* pString2);
467 
469 FBXSDK_DLL FbxString operator+(const FbxString& pString, int pValue);
470 
472 FBXSDK_DLL FbxString operator+(const FbxString& pString, float pValue);
473 
475 FBXSDK_DLL FbxString operator+(const FbxString& pString, double pValue);
476 
478 struct FbxStringCompare { inline int operator()(const FbxString& pKeyA, const FbxString& pKeyB) const { return pKeyA.Compare(pKeyB); } };
479 
481 struct FbxStringCompareNoCase { inline int operator()(const FbxString& pKeyA, const FbxString& pKeyB) const { return pKeyA.CompareNoCase(pKeyB); } };
482 
484 struct FbxCharPtrCompare { inline int operator()(const char* pKeyA, const char* pKeyB) const { return strcmp(pKeyA, pKeyB); } };
485 
487 struct FbxCharPtrCompareNoCase { inline int operator()(const char* pKeyA, const char* pKeyB) const { return FBXSDK_stricmp(pKeyA, pKeyB); } };
488 
493 inline void FbxRemoveChar(FbxString& pString, char pToRemove)
494 {
495  int lPos = pString.ReverseFind(pToRemove);
496  while( lPos >= 0 )
497  {
498  pString = pString.Left(lPos) + pString.Mid(lPos + 1);
499  lPos = pString.ReverseFind(pToRemove);
500  }
501 }
502 
503 #include <fbxsdk/fbxsdk_nsend.h>
504 
505 #endif /* _FBXSDK_CORE_BASE_STRING_H_ */
FbxString operator+(const FbxString &pString1, const FbxString &pString2)
FbxString concatenation.
Functor to compare "C" strings without case sensitivity.
Definition: fbxstring.h:487
FBX SDK environment definition.
FbxString Mid(size_t pFirst, size_t pCount) const
Extract middle string for a given length.
void FbxUTF8ToWC(const char *pInUTF8, wchar_t *&pOutWideChar, size_t *pOutWideCharSize=((void *) 0))
Convert string from UTF8 to wide-char.
#define NULL
Definition: fbxarch.h:210
Utility class to manipulate strings.
Definition: fbxstring.h:66
Functor to compare FbxString.
Definition: fbxstring.h:478
int operator()(const char *pKeyA, const char *pKeyB) const
Definition: fbxstring.h:487
int ReverseFind(char pChar) const
Look for the last occurrence of character in string, like "C" strrchr().
int operator()(const FbxString &pKeyA, const FbxString &pKeyB) const
Definition: fbxstring.h:481
int Compare(const char *pString) const
Compare as "C" strcmp().
Functor to compare "C" strings.
Definition: fbxstring.h:484
int operator()(const char *pKeyA, const char *pKeyB) const
Definition: fbxstring.h:484
void FbxRemoveChar(FbxString &pString, char pToRemove)
Remove the given char in the given string.
Definition: fbxstring.h:493
FBXSDK_INCOMPATIBLE_WITH_ARRAY(FbxString)
int CompareNoCase(const char *pString) const
Compare as "C" stricmp().
void FbxWCToUTF8(const wchar_t *pInWideChar, char *&pOutUTF8, size_t *pOutUTF8Size=((void *) 0))
Convert string from wide-char to UTF8.
EPaddingType
Padding types.
Definition: fbxstring.h:355
FbxString Left(size_t pCount) const
Extract left string.
#define FBXSDK_DLL
Definition: fbxarch.h:173
Functor to compare FbxString without case sensitivity.
Definition: fbxstring.h:481
int operator()(const FbxString &pKeyA, const FbxString &pKeyB) const
Definition: fbxstring.h:478