CFx SDK Documentation  2022 SP0
OdAnsiString.h
Go to the documentation of this file.
1 // Copyright (C) 2002-2017, Open Design Alliance (the "Alliance").
3 // All rights reserved.
4 //
5 // This software and its documentation and related materials are owned by
6 // the Alliance. The software may only be incorporated into application
7 // programs owned by members of the Alliance, subject to a signed
8 // Membership Agreement and Supplemental Software License Agreement with the
9 // Alliance. The structure and organization of this software are the valuable
10 // trade secrets of the Alliance and its suppliers. The software is also
11 // protected by copyright law and international treaty provisions. Application
12 // programs incorporating this software must include the following statement
13 // with their copyright notices:
14 //
15 // This application incorporates Teigha(R) software pursuant to a license
16 // agreement with Open Design Alliance.
17 // Teigha(R) Copyright (C) 2002-2017 by Open Design Alliance.
18 // All rights reserved.
19 //
20 // By use of this software, its documentation or related materials, you
21 // acknowledge and accept the above terms.
23 
24 
25 
26 
27 
28 #ifndef __ODANSISTRING_H__
29 #define __ODANSISTRING_H__
30 
31 #ifdef TD_UNICODE
32 #define ODA_CDECL
33 #define ODA_PASCAL
34 
35 #include <stdarg.h>
36 #include <stdio.h>
37 
38 #include "OdMutex.h"
39 #include "OdPlatform.h"
40 #include "OdArrayPreDef.h"
41 #include "OdCodePage.h"
42 
43 #define odaIsValidString(lpch) (true)
44 
45 #include "TD_PackPush.h"
46 class OdString;
47 
48 #ifdef sgi
49 #include <string>
50  // va_XXXX items are in std namespace for newest SGI compiler
51 
52 using namespace std;
53 #endif
54 
65 struct OdStringDataA
66 {
70  OdRefCounter nRefs;
71 
75  int nDataLength;
76 
80  int nAllocLength;
81 
82  OdCodePageId codepage;
83 
87  char* data()
88  { return (char*)(this+1); }
89 };
90 
91 #ifdef _WIN32_WCE
92 ODA_ASSUME((sizeof(OdStringDataA)%8)==0);
93 #endif
94 
100  struct OdEmptyStringDataA
101 {
102  OdStringDataA kStrData;
103  char kChar;
104 };
105 
114 class FIRSTDLL_EXPORT OdAnsiString
115 {
116 public:
117 
118  OdAnsiString()
119  { init(); }
120 
123  OdAnsiString(const OdAnsiString& source);
124 
128  OdAnsiString(char ch, int length);
129 
130  OdAnsiString(const char* source);
131 
132  OdAnsiString(const char* source, int length);
133  OdAnsiString(const char* source, OdCodePageId);
134  OdAnsiString(const char* source, int length, OdCodePageId);
135  OdAnsiString(const OdString& , OdCodePageId);
136 
137  void setCodepage(OdCodePageId id);
138 
139  OdCodePageId codepage() const
140  { return getData()->codepage; }
141 
145  int getLength() const
146  { return getData()->nDataLength; }
147 
151  bool isEmpty() const
152  { return getData()->nDataLength == 0; }
153 
157  void empty();
158 
163  char getAt(int charIndex) const
164  {
165  ODA_ASSERT(charIndex >= 0);
166  ODA_ASSERT(charIndex < getData()->nDataLength);
167  return m_pchData[charIndex];
168  }
169 
177  char operator[](int charIndex) const
178  {
179  ODA_ASSERT(charIndex >= 0);
180  ODA_ASSERT(charIndex < getData()->nDataLength);
181  return m_pchData[charIndex];
182  }
183 
191  void setAt(int charIndex, char ch);
192 
196  const char* c_str() const
197  { return m_pchData; }
198 
202  operator const char*() const
203  { return m_pchData; }
204 
205  OdAnsiString& operator=(const OdAnsiString& source);
206 
207  OdAnsiString& operator=(char ch);
208 
209  OdAnsiString& operator=(const char* source);
210 
211  OdAnsiString& operator=(const OdString& source);
212 
219  OdAnsiString& operator+=(const OdAnsiString& string);
220 
227  OdAnsiString& operator+=(char ch);
228 
235  OdAnsiString& operator+=(const char* string);
236 
242  friend FIRSTDLL_EXPORT OdAnsiString operator+(const OdAnsiString& string1, const OdAnsiString& string2);
243  friend FIRSTDLL_EXPORT OdAnsiString operator+(const OdAnsiString& string, char ch);
244  friend FIRSTDLL_EXPORT OdAnsiString operator+(char ch, const OdAnsiString& string);
245 
246  friend FIRSTDLL_EXPORT OdAnsiString operator+(const OdAnsiString& string1, const char* string2);
247  friend FIRSTDLL_EXPORT OdAnsiString operator+(const char* string1, const OdAnsiString& string2);
248 
264  int compare(const char* otherString) const
265  { ODA_ASSERT(odaIsValidString(otherString)); return odStrCmpA(m_pchData, otherString); } // MBCS/Unicode aware
266 
282  int iCompare(const char* otherString) const
283  { ODA_ASSERT(odaIsValidString(otherString)); return odStrICmpA(m_pchData, otherString); }
284 
293  OdAnsiString mid(int startIndex, int length) const;
294 
300  OdAnsiString mid(int startIndex) const;
301 
306  OdAnsiString left(int length) const;
307 
312  OdAnsiString right(int length) const;
313 
325  OdAnsiString spanIncluding(const char* charSet) const;
326 
338  OdAnsiString spanExcluding(const char* charSet) const;
339 
346  OdAnsiString& makeUpper();
347 
354  OdAnsiString& makeLower();
355 
362  OdAnsiString& makeReverse();
363 
364 
373  OdAnsiString& trimRight();
374 
383  OdAnsiString& trimLeft();
384 
397  OdAnsiString& trimRight(char whiteChar);
398 
409  OdAnsiString& trimRight(const char* whiteChars);
410 
421  OdAnsiString& trimLeft(char whiteChar);
422 
433  OdAnsiString& trimLeft(const char* whiteChars);
434 
444  int replace(char oldChar, char newChar);
445 
455  int replace(const char* oldString, const char* newString);
456 
465  int remove(char chRemove);
466 
479  int insert(int insertIndex, char insertChar);
480 
493  int insert(int insertIndex, const char* insertString);
494 
503  int deleteChars(int deleteIndex, int count = 1);
504 
505 
514  int find(char searchChar) const;
515 
524  int reverseFind(char searchChar) const;
525 
537  int find(char searchChar, int startIndex) const;
538 
547  int findOneOf(const char* charSet) const;
548 
557  int find(const char* searchString) const;
558 
568  int find(const char* searchString, int startIndex) const;
569 
577  OdAnsiString& format(const char* formatString, ...);
578 
587  OdAnsiString& formatV(const char* formatString, va_list argList);
588 
598  char* getBuffer(int minBufLength);
599 
606  void releaseBuffer(int newLength = -1);
607 
617  char* getBufferSetLength(int length);
618 
622  void freeExtra();
623 
627  char* lockBuffer();
628 
632  void unlockBuffer();
633 
634 public:
635  ~OdAnsiString();
636 
640  int getAllocLength() const
641  { return getData()->nAllocLength; }
642 
643 protected:
644  FIRSTDLL_EXPORT_STATIC static OdEmptyStringDataA kEmptyData;
645 
649  char* m_pchData;
650 
654  OdStringDataA* getData() const
655  { ODA_ASSERT(m_pchData != NULL); return ((OdStringDataA*)m_pchData)-1; }
656 
660  void init();
661 
672  void allocCopy(OdAnsiString& destString, int copyLength, int copyIndex, int extraLength) const;
673 
678  void allocBuffer(int length);
679 
689  void assignCopy(int sourceLength, const char* source);
690 
702  void concatCopy(int sourceLength1, const char* source1, int sourceLength2, const char* source2);
703 
713  void concatInPlace(int sourceLength, const char* source);
714 
722  void copyBeforeWrite();
723 
731  void allocBeforeWrite(int newLength);
732 
746  void release();
747 
748  static void ODA_PASCAL release(OdStringDataA* pStringData);
749 
756  static int ODA_PASCAL safeStrlen(const char* string)
757  { return (string == NULL) ? (int)0 : (int)odStrLenA(string); }
758 
763  static void freeData(OdStringDataA* pStringData);
764  friend class OdString;
765 };
766 
767 inline bool operator==(const OdAnsiString& s1, const OdAnsiString& s2)
768 { return s1.compare(s2) == 0; }
769 
770 inline bool operator==(const OdAnsiString& s1, const char* s2)
771 { return s1.compare(s2) == 0; }
772 
773 inline bool operator==(const char* s1, const OdAnsiString& s2)
774 { return s2.compare(s1) == 0; }
775 
776 inline bool operator!=(const OdAnsiString& s1, const OdAnsiString& s2)
777 { return s1.compare(s2) != 0; }
778 
779 inline bool operator!=(const OdAnsiString& s1, const char* s2)
780 { return s1.compare(s2) != 0; }
781 
782 inline bool operator!=(const char* s1, const OdAnsiString& s2)
783 { return s2.compare(s1) != 0; }
784 
785 inline bool operator<(const OdAnsiString& s1, const OdAnsiString& s2)
786 { return s1.compare(s2) < 0; }
787 
788 inline bool operator<(const OdAnsiString& s1, const char* s2)
789 { return s1.compare(s2) < 0; }
790 
791 inline bool operator<(const char* s1, const OdAnsiString& s2)
792 { return s2.compare(s1) > 0; }
793 
794 inline bool operator>(const OdAnsiString& s1, const OdAnsiString& s2)
795 { return s1.compare(s2) > 0; }
796 
797 inline bool operator>(const OdAnsiString& s1, const char* s2)
798 { return s1.compare(s2) > 0; }
799 
800 inline bool operator>(const char* s1, const OdAnsiString& s2)
801 { return s2.compare(s1) < 0; }
802 
803 inline bool operator<=(const OdAnsiString& s1, const OdAnsiString& s2)
804 { return s1.compare(s2) <= 0; }
805 
806 inline bool operator<=(const OdAnsiString& s1, const char* s2)
807 { return s1.compare(s2) <= 0; }
808 
809 inline bool operator<=(const char* s1, const OdAnsiString& s2)
810 { return s2.compare(s1) >= 0; }
811 
812 inline bool operator>=(const OdAnsiString& s1, const OdAnsiString& s2)
813 { return s1.compare(s2) >= 0; }
814 
815 inline bool operator>=(const OdAnsiString& s1, const char* s2)
816 { return s1.compare(s2) >= 0; }
817 
818 inline bool operator>=(const char* s1, const OdAnsiString& s2)
819 { return s2.compare(s1) <= 0; }
820 
821 typedef OdArray<OdAnsiString> OdAnsiStringArray;
822 
823 #include "TD_PackPop.h"
824 
825 #endif // TD_UNICODE
826 
827 #endif // __ODANSISTRING_H__
828 
829 
#define ODA_ASSERT(exp)
Definition: DebugStuff.h:49
#define NULL
Definition: GsProperties.h:177
OdCodePageId
Definition: OdCodePage.h:31
int OdRefCounter
Definition: OdMutex.h:436
#define odStrICmpA(str, str2)
Definition: OdPlatform.h:376
#define odStrCmpA(str, str2)
Definition: OdPlatform.h:252
#define odStrLenA(str)
Definition: OdPlatform.h:244
bool operator>=(const OdString &s1, const OdString &s2)
Definition: OdString.h:1351
#define odaIsValidString(lpch)
Definition: OdString.h:39
bool operator<=(const OdString &s1, const OdString &s2)
Definition: OdString.h:1329
bool operator<(const OdString &s1, const OdString &s2)
Definition: OdString.h:1284
bool operator>(const OdString &s1, const OdString &s2)
Definition: OdString.h:1307
#define FIRSTDLL_EXPORT
Definition: RootExport.h:39
#define FIRSTDLL_EXPORT_STATIC
Definition: RootExport.h:40
ODA_ASSUME(sizeof(OdRxValue)==32)
friend class OdAnsiString
Definition: OdString.h:1220
GLint GLenum GLsizei GLsizei GLint GLsizei const void * data
Definition: gles2_ext.h:110
GLsizei GLsizei * count
Definition: gles2_ext.h:276
GLsizei GLsizei GLchar * source
Definition: gles2_ext.h:282
GLuint GLsizei GLsizei * length
Definition: gles2_ext.h:274
GLint GLint GLint GLsizei GLsizei GLenum format
Definition: gles2_ext.h:111
bool DAI_EXPORT operator!=(const OdDAI::OdSelect &left, const OdDAI::OdSelect &right)
bool DAI_EXPORT operator==(const OdFileDescriptionAuto &left, const OdFileDescriptionAuto &right)