zjf
2023-03-06 392b76515f40376b6d36f40a114850ef63650384
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
/////////////////////////////////////////////////////////////////////////////// 
// Copyright (C) 2002-2016, Open Design Alliance (the "Alliance"). 
// All rights reserved. 
// 
// This software and its documentation and related materials are owned by 
// the Alliance. The software may only be incorporated into application 
// programs owned by members of the Alliance, subject to a signed 
// Membership Agreement and Supplemental Software License Agreement with the
// Alliance. The structure and organization of this software are the valuable  
// trade secrets of the Alliance and its suppliers. The software is also 
// protected by copyright law and international treaty provisions. Application  
// programs incorporating this software must include the following statement 
// with their copyright notices:
//   
//   This application incorporates Teigha(R) software pursuant to a license 
//   agreement with Open Design Alliance.
//   Teigha(R) Copyright (C) 2002-2016 by Open Design Alliance. 
//   All rights reserved.
//
// By use of this software, its documentation or related materials, you 
// acknowledge and accept the above terms.
///////////////////////////////////////////////////////////////////////////////
 
 
 
 
 
#ifndef __ODSTRING_H__
#define __ODSTRING_H__
 
#include <stdarg.h>
#include <stdio.h>
 
#include "OdMutex.h"
#include "OdPlatformSettings.h"
#include "OdCodePage.h"
#include "OdAnsiString.h"
 
#define odaIsValidString(lpch)    (true)
 
#include "TD_PackPush.h"
 
#ifdef sgi
#include <string>
using namespace std;  // va_XXXX items are in std namespace for newest SGI compiler
#endif
 
/** \details
    This structure contains string data used by OdString.
 
    \remarks
    An OdChar array (buffer) is allocated along with this structure, and
    is freed when this structure is freed.
    
    Library: TD_Root
    <group !!RECORDS_TD_APIRef>
*/
struct OdStringData
{            
  /** \details
    Number of references to this string.
  */
  OdRefCounter nRefs;      
 
  /** \details
    String length in characters, omitting the 0 terminator.
  */
  int nDataLength; 
 
  /** \details
    String allocation length in characters, omitting the 0 terminator. 
  */
  int nAllocLength;       
 
  /** \details
    Underlying OdChar array (buffer) of this StringData object.
  */
  OdChar* unicodeBuffer;
  
  /** \details
    Underlying char array (buffer) of this StringData object.
  */
  char* ansiString;
};
 
/** \details
    This class implements Teigha character String objects.
 
    \remarks
    OdString objects use zero-based indices to access string elements.
 
    <group Other_Classes>
*/
class FIRSTDLL_EXPORT OdString
{
public:
 
  FIRSTDLL_EXPORT_STATIC const static OdString kEmpty;
 
  OdString()
  { init(); }
 
  /** \param source [in]  Source.
  */
  OdString(const OdString& source);
 
  /** \param ch [in]  Character to repeat.
    \param length [in]  Number of characters.
  */
  OdString(OdChar ch, int length);
 
  OdString(const OdChar* source);
  OdString(const OdChar* source, int length);
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString(const __wchar_t* source);
  OdString(const __wchar_t* source, int length);
#endif
 
 
  OdString(const char* lpch, OdCodePageId codepage = CP_CNT);
  OdString(const char* lpch, int nLength, OdCodePageId codepage = CP_CNT);
  OdString(const OdAnsiString&);
protected:
  explicit OdString(OdStringData* pData);
public:
 
  /** \details
    Returns the number of characters in this String object.
  */
  int getLength() const
  { 
    if (isUnicodeNotInSync())
      syncUnicode();
    return getData()->nDataLength; 
  }
  int getLengthA() const;
 
  /** \details
    Returns true and only if this String object is empty.
  */
  bool isEmpty() const
  {
    return (getData()->nDataLength == 0 && 
      (getData()->ansiString == 0 || getAnsiString()->isEmpty()));
  }
 
  /** \details
    Sets this String object to the empty string.
  */
  void empty();
 
  /** \details
    Returns the single character of this String object at the specified position.
    \param charIndex [in]  Character index. 
  */
  OdChar getAt(int charIndex) const
  {
#ifdef TD_UNICODE
    if (isUnicodeNotInSync())
      syncUnicode();
#endif
    ODA_ASSERT(charIndex >= 0);
    ODA_ASSERT(charIndex < getData()->nDataLength);
    return getData()->unicodeBuffer[charIndex];
  }
 
  /** \details
    Indexing Operator
    
    \remarks
    Returns the single character of this String object at the specified position.
    \param charIndex [in]  Character index. 
  */
  OdChar operator[](int charIndex) const
  {
    return getAt(charIndex);
  }
 
  /** \details
    Sets the single character of this String object at the specified position.
    \param charIndex [in]  Character index.
    \param ch [in]  Character.
    \note
    No range checking is performed.
  */
  void setAt(int charIndex, OdChar ch);
 
#if defined(_MSC_VER) && defined(_WIN32) && defined(_DEBUG) && defined(ODA_LINT)
#define UPDATECONSTSTRINGDIAGNISTIC
private:
  void updateConstStringDiagnostic(const OdChar* pAddr) const;
public:
#else
  #define updateConstStringDiagnostic(pAddr)
#endif
 
  /** \details
    Returns the underlying OdChar array (buffer) of this String object.
  */
  const OdChar* c_str() const
  { 
    if (isUnicodeNotInSync())
      syncUnicode();
    const OdChar* pRet = getData()->unicodeBuffer;
    updateConstStringDiagnostic(pRet);
    return pRet;
  }
 
  /** \details
    Returns the underlying character array (buffer) of this String object.
  */
  inline operator const OdChar*() const
  { 
    return c_str();
  }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  operator const __wchar_t*() const
  { 
    return reinterpret_cast<const __wchar_t*>(c_str());
  }
#endif
 
  operator const char*() const;
 
  OdString& operator=(const OdString& source);
 
  OdString& operator=(OdChar ch);
  
  OdString& operator=(const OdChar* source);
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString& operator=(const __wchar_t* source){ return operator=((const OdChar*)source); }
#endif
 
  OdString& operator=(const OdAnsiString& source);
 
  OdString& operator=(const char* source);
 
  /** \details
    Concatenation-Equals Operator.
    \remarks
    Sets this object to the concatenation of this String object with the 
    value on the right, and returns a reference to this String object.
  */
  OdString& operator+=(const OdString& string);
 
  OdString& operator+=(OdChar ch);
 
  OdString& operator+=(const OdChar* string);
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString& operator+=(const __wchar_t* string){ return operator+=((const OdChar*)string); }
#endif
 
  OdString& operator+=(const char* string);
 
  /** \details
    Concatenation Operator.
    \remarks
    Returns the concatenation of this object on the left with the object on the right.
  */
  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string1, const OdString& string2);
  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string, OdChar ch);
  friend FIRSTDLL_EXPORT OdString operator+(OdChar ch, const OdString& string);
 
  friend FIRSTDLL_EXPORT OdString operator+(const OdString& string1, const OdChar* string2);
  friend FIRSTDLL_EXPORT OdString operator+(const OdChar* string1, const OdString& string2);
 
  /** \details
    Case sensitive string comparison.  
    
    \param otherString [in]  Other string.
    
    \remarks
    compare() returns one of the following:
    
    <table>
    Returns   Condition
    < 0       This String object < otherString. 
    0         This String object == otherString.
    > 0       This String object > otherString.
    </table>
  */
  int compare(const OdChar* otherString) const
  { 
    if (isUnicodeNotInSync())
      syncUnicode();
    return odStrCmp((const wchar_t*)getData()->unicodeBuffer, (const wchar_t*)otherString);
  }
 
  inline int compare(const OdString& otherString) const{ return compare(otherString.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  int compare(const __wchar_t* otherString) const { return compare((const OdChar*)otherString);}
#endif
 
  /** \details
  Case sensitive string comparison.  
 
  \param otherString [in]  Other string.
 
  \remarks
  compare() returns one of the following:
 
  <table>
  Returns   Condition
  < 0       This String object < otherString. 
  0         This String object == otherString.
  > 0       This String object > otherString.
  </table>
  */
  int compare(const char* otherString) const;
 
  /** \details
    Case insensitive string comparison.  
    
    \param otherString [in]  Other string.
    
    \remarks
    iCompare() returns one of the following:
    
    <table>
    Returns   Condition
    < 0       This String object < otherString. 
    0         This String object == otherString.
    > 0       This String object > otherString.
    </table>
  */
  int iCompare(const OdChar* otherString) const
  { 
    if (isUnicodeNotInSync())
      syncUnicode();
    return odStrICmp(getData()->unicodeBuffer, otherString); 
  }   
  inline int iCompare(const OdString& otherString) const{ return iCompare(otherString.c_str()); }
#if defined(_MSC_VER) && _MSC_VER >= 1300
  __forceinline int iCompare(const __wchar_t* otherString) const {return iCompare((const OdChar*)otherString);}
#endif   
 
  /** \details
    Returns the substring specified by a start index and a length from this String object.
    \param startIndex [in]  Starting index.
    \param length [in]  Length of substring. 
    
    \remarks
    If length is not specified, the remainder of this String object is returned.
  */
  OdString mid(int startIndex, int length) const;
 
  OdString mid(int startIndex) const;
 
  /** \details
    Returns the leftmost substring of the specified length from this String object.
    \param length [in]  Length of substring. 
  */
  OdString left(int length) const;
 
  /** \details
    Returns the rightmost substring of the specified length from this String object.
    \param length [in]  Length of substring. 
  */
  OdString right(int length) const;
 
  /** \details
    Returns the longest leftmost substring of this String object 
    that consists solely of characters that are
    contained in the specified character set.
 
    \param charSet [in]  Character set.
    
    \remarks
    If the first character in this String object is not in the specified character set,
    an empty string is returned.
  */
  OdString spanIncluding(const OdChar* charSet) const;
  
  inline OdString spanIncluding(const OdString& charSet) const { return spanIncluding(charSet.c_str()); }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString spanIncluding(const __wchar_t* charSet) const{return spanIncluding((const OdChar*)charSet);}
#endif
 
  /** \details
    Returns the longest leftmost substring of this String object 
    that consists solely of characters that are
    not contained in the specified character set.
 
    \param charSet [in]  Character set.
    
    \remarks
    If the first character in this String object in the specified character set,
    an empty string is returned.
  */
  OdString spanExcluding(const OdChar* charSet) const;
 
  inline OdString spanExcluding(const OdString& charSet) const{ return spanExcluding(charSet.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString spanExcluding(const __wchar_t* charSet) const{return spanExcluding((const OdChar*)charSet);}
#endif
  
  /** \details
    Converts this String object to upper case.
 
    \remarks
    Returns a reference to this String object.  
  */
  OdString& makeUpper();
 
  /** \details
    Converts this String object to lower case.
 
    \remarks
    Returns a reference to this String object.  
  */
  OdString& makeLower();
 
  /** \details
    Reverses this String object.
 
    \remarks
    Returns a reference to this String object.  
  */
  OdString& makeReverse();
 
 
  /** \details
    Removes all whitespace from the right side of this String object.
   
    \remarks
    Returns a reference to this String object.
    
    A space (' ') is used if no whitespace characters are specfied.  
  */
  OdString& trimRight();
 
  /** \details
    Removes all whitespace from the left side of this String object.
   
    \remarks
    Returns a reference to this String object.  
 
    A space (' ') is used if no other whitespace characters are specfied.  
  */
  OdString& trimLeft();
 
  /** \param whiteChar [in]  Whitespace character.
  */
  OdString& trimRight(OdChar whiteChar);
 
  /** \param whiteChars [in]  Whitespace characters.
  */
  OdString& trimRight(const OdChar* whiteChars);
 
  inline OdString& trimRight(const OdString& whiteChars){ return trimRight(whiteChars.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString& trimRight(const __wchar_t* whiteChars){return trimRight((const OdChar*)whiteChars);}
#endif
 
  /** \param whiteChar [in]  Whitespace character.
  */
  OdString& trimLeft(OdChar whiteChar);
 
  /** \param whiteChars [in]  Whitespace characters.
  */
  OdString& trimLeft(const OdChar* whiteChars);
  
  inline OdString& trimLeft(const OdString& whiteChars){ return trimLeft(whiteChars.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString& trimLeft(const __wchar_t* whiteChars){return trimLeft((const OdChar*)whiteChars);}
#endif
  /** \details
    Replaces all occurrences of the specified character or string in this String object.
 
    \param oldChar [in]  Old character.
    \param newChar [in]  New character.
    
    \remarks
    Returns the number of characters or strings replaced.
  */
  int replace(OdChar oldChar, OdChar newChar);
 
  /** \param oldString [in]  Old string.
    \param newString [in]  New string.
  */
  int replace(const OdChar* oldString, const OdChar* newString);
  
  inline int replace(const OdString& oldString, const OdString& newString){ return replace(oldString.c_str(), newString.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  int replace(const __wchar_t* oldString, const __wchar_t* newString){return replace((const OdChar*)oldString, (const OdChar*)newString);}
#endif
  /** \details
    Removes all occurrences of the specified character from this String object.
 
    \param removeChar [in]  Character to remove.
 
    \remarks
    Returns the number of characters removed.
  */
  int remove(OdChar chRemove);
 
  /** \details
    Inserts the specified character or string into this String object.
    
    \param insertChar [in]  Character to insert.
    \param insertIndex [in]  Insertion index.
  
    \remarks
    Returns the new length of this String object.
    
    If insertIndex exceeds the length of this String object, 
    this String object is lengthened as necessary to accommodate the insertion.
  */
  int insert(int insertIndex, OdChar insertChar);
 
  /** \details
    \param insertString [in]  String to insert.
  */
 
  int insert(int insertIndex, const OdChar* insertString);
 
  int insert(int insertIndex, const OdString& insertString){return insert(insertIndex, insertString.c_str());}
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  int insert(int insertIndex, const __wchar_t* insertString){return insert(insertIndex,(const OdChar*)insertString);}
#endif
  /** \details
    Deletes the specified number characters from this String object.
 
    \param deleteIndex [in]  Deletion index.
    \param count [in]  Number of characters to delete.
    \remarks
    Returns the new length of this String object.
  */
  int deleteChars(int deleteIndex, int count = 1);
 
 
  /** \details
    Returns the first occurrence of the specified character or string in this String object.
 
    \param searchChar [in]  Search character.
     
    \remarks
    Returns -1 if not found.
  */
  int find(OdChar searchChar) const;
 
  /** \details
    Returns the last occurrence of the specified character in this String object.
 
    \param searchChar [in]  Search character.
     
    \remarks
    Returns -1 if not found.
  */
  int reverseFind(OdChar searchChar) const;
 
  /** \details
    Returns the last occurrence of the specified character in this String object.
 
    \param searchChar [in]  Search character.
    \param startIndex [in]  An index from which to start searching back.
 
    \remarks
    Returns -1 if not found.
  */
  int reverseFind(OdChar searchChar, int startIndex) const;
 
  /** \param startIndex [in]  Start index.
  */
  int find(OdChar searchChar, int startIndex) const;
 
  /** \details
    Returns the first occurrence in this String object of any member of the specified character set. 
 
    \param charSet [in]  Character set.
     
    \remarks
    Returns -1 if not found.
  */
  int findOneOf(const OdChar* charSet) const;
 
  int find(const OdChar* searchString) const;
 
  /** \param searchString [in]  Search string.
  */
  int find(const OdChar* searchString, int startIndex) const;
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  int findOneOf(const __wchar_t* charSet) const{return findOneOf((const OdChar*)charSet);}
  int findOneOf(const OdString& charSet) const{return findOneOf((const OdChar*)charSet);}
 
  int find(const __wchar_t* searchString) const{return find((const OdChar*)searchString);}
 
  int find(const OdString& searchString) const{return find((const OdChar*)searchString);}
 
  int find(const __wchar_t* searchString, int startIndex) const{return find((const OdChar*)searchString,startIndex);}
 
  int find(const OdString& searchString, int startIndex) const{return find((const OdChar*)searchString,startIndex);}
#endif
  /** \details
    Assigns a value to this String object using a printf-style format string and 
    arguments.
    \param formatString [in]  Format string.
    \remarks
    Returns a reference to this String Object.
  */
  OdString& format(const OdChar* formatString, ...);
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  OdString& format(const __wchar_t* formatString, ...);
#endif
 
  /** \details
    Assigns a value to this String object using a vsprintf-style format string and 
    argument list.
    \param formatString [in]  Format string.
    \param argList [in]  Argument list.   
    \remarks
    Returns a reference to this String Object.
  */
  OdString& formatV(const OdChar* formatString, va_list argList); 
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
  inline OdString& formatV(const __wchar_t* formatString, va_list argList)
  {
    return formatV((const OdChar*)formatString, argList);
  }
#endif
                                                                
  /** \details
    Returns a modifiable C style OdChar array (buffer) of the specified minimum length for this String object.
    \param minBufferLength [in]  Minimum buffer length.
    
    \note
    releaseBuffer() should be called before using any other OdString methods.
    
    The pointer returned by this function is not valid after releaseBuffer() is called.
  */
  OdChar* getBuffer(int minBufLength);
 
  /** \details
    Releases a buffer obtained by getBuffer() or getBufferSetLength(), and sets its length.
    \param newLength [in]  New buffer length.
    \remarks
    If newLength == -1, the buffer is treated as 0 terminated.  
  */
  void releaseBuffer(int newLength = -1);
 
  /** \details
    Returns a modifiable C style OdChar array (buffer) of of the specified length for this String object.
    \param length [in]  buffer length.
    
    \note
    releaseBuffer() should be called before using any other OdString methods.
    
    The pointer returned by this function is not valid after releaseBuffer() is called.
  */
  OdChar* getBufferSetLength(int length);
 
  /** \details
    Releases any unused memory allocated by this String object.
  */
  void freeExtra();
 
  /** \details
    Enables reference counting for this String object.
  */
  OdChar* lockBuffer();
 
  /** \details
    Disables reference counting for this String object.
  */
  void unlockBuffer();
 
/*   disable wide char functionalities
   Constructor.  This OdString will receive a copy of the wide character string referenced
   by lpsz.
  OdString(const OdCharW* lpsz);
 
  Constructor. This OdString will receive a copy of the first nLength wide characters of
  the string referenced by lpch.
  OdString(const OdCharW* lpch, int nLength);
 
   Assignment operator.  This OdString is assigned the value of lpsz.
  const OdString& operator=(const OdCharW* lpsz);
 
*/
 
#ifdef NOT_IMPLEMENTED
 
  /*!DOM*/
  /** \details
    Case sensitive string comparison.  
    
    \param otherString [in]  Other string.
    
    \remarks
    collate() returns one of the following:
    
    <table>
    Returns   Condition
    < 0       This String object < otherString. 
    0         This String object == otherString.
    > 0       This String object > otherString.
    </table>
  */
  int collate(const OdChar* otherString) const;
 
  /*!DOM*/
  /** \details
    Case insensitive string comparison.  
    
    \param otherString [in]  Other string.
    
    \remarks
    icollate() returns one of the following:
    
    <table>
    Returns   Condition
    < 0       This String object < otherString. 
    0         This String object == otherString.
    > 0       This String object > otherString.
    </table>
  */
  int iCollate(const OdChar* otherString) const;
  /** \param formatID [in]  Format ID. 
  */
  OdString& ODA_CDECL format(unsigned int formatID, ...);
#endif
 
 
public:
  ~OdString();
 
  /** \details
    Returns the number of characters allocated for the underlying OdChar array (buffer) in this String object.
  */
  int getAllocLength() const
  { return getData()->nAllocLength; }
 
protected:
  FIRSTDLL_EXPORT_STATIC static OdStringData kEmptyData;
 
  /** \details
    Pointer to the underlying OdChar array (buffer). 
  */
  OdStringData* m_pData;  
  
  /** \details
    Returns the StringData for this String object.
  */
  OdStringData* getData() const
    { ODA_ASSERT(m_pData!= NULL); return m_pData; }
 
  /** \details
    Initializes this String object to an empty string.
  */
  void init();
 
  /** \details
    Copies the specified number of characters from this String object to the destination String object.
    \param destString [out]  Destination string.
    \param copyLength [in]  Number of characters to copy.
    \param copyIndex [in]  First byte to copy.
    \param extraLength [in]  Extra characters to allocate.
    
    \remarks
    This function calls allocBuffer(copyLength + extraLength)
  */
  void allocCopy(OdString& destString, int copyLength, int copyIndex, int extraLength) const;
 
  /** \details
    Allocates the specified number of characters for the character buffer of this String object.
    \param length [in]  buffer length.
    allocAlways - if true, allocates new OdStringData even for 0 length unicode buffer (for ansi string constructors)
  */
  void allocBuffer(int length, bool allocAlways = false);
 
  /** \details
    Copies the specified string to this String object.
    
    \param sourceLength [in]  Number of characters to copy.
    \param source [in]  Source string.
 
    \remarks
    If getAllocLength() < sourceLength, this function calls allocBuffer(sourceLength).
  */
    void assignCopy(int sourceLength, const OdChar* source);
 
  /** \details
    Concatenates and copies the specified strings to this String object.
    
    \param sourceLength1 [in]  Number of characters in first string to copy.
    \param sourceLength2 [in]  Number of characters in second string to copy.
    \param source1 [in]  First source string.
    \param source2 [in]  Second source string.
 
    \remarks
    If getAllocLength() < (sourceLength1 + sourceLength2), this function calls allocBuffer(sourceLength1 + sourceLength2).
  */
    void concatCopy(int sourceLength1, const OdChar* source1, int sourceLength2, const OdChar* source2);
 
  /** \details
    Concatenates the string to this String object.
    
    \param sourceLength [in]  Number of characters to copy.
    \param source [in]  Source string.
 
    \remarks
    If getAllocLength() < getLength() + sourceLength, this function calls allocBuffer(getLength()+ sourceLength2).
  */
    void concatInPlace(int sourceLength, const OdChar* source);
 
  /** \details
    Assures there are no multiple references to the StringData associated with this String object. 
    
    \remarks
    If there is more than one reference to the StringData object, it is released, and
    replaced with a copy thereof 
  */
  void copyBeforeWrite();
 
  /** \details
    Assures the character buffer of this String object is at least the specified size.
    \param newLength [in]  New length of buffer.
    
    \remarks
    If getAllocLength() < newLength, this function calls allocBuffer(newLength).
  */
  void allocBeforeWrite(int newLength);
 
  /** \details
    Releases the reference to the specified StringData object.
    
    \param pStringData [in]  Pointer to the StringData object.
    
    \remarks
    If pStringData is not specified, the StringData associated with
    this String object is released.
    
    Decrements the reference count of the StringData object.
        
    When its reference count reaches zero, the StringData object is freed.
  */
  void release();
 
  static void release(OdStringData* pStringData);
 
  /** \details
    Returns the length of the specified string.
    \param string [in]  0 terminated string or NULL.
    \remarks
    Returns 0 if string == NULL.
  */
  static int safeStrlen(const OdChar* string)
  { return (string == NULL) ? (int)0 : (int)odStrLen((const wchar_t*)string); }
 
  /** \details
    Frees the specified StringData object.
    \param pStringData [in]  Pointer to the StringData object.
  */
  static void freeData(OdStringData* pStringData);
 
  bool isUnicodeNotInSync() const
  {
    return !getData()->unicodeBuffer && getData()->ansiString;
  }
  void syncUnicode() const;
  OdAnsiString* getAnsiString() const
  {
    if (getData()->ansiString)
      return reinterpret_cast<OdAnsiString*>(&getData()->ansiString);
    else 
      return 0;
  }
  void freeAnsiString()const;
  friend class OdAnsiString;
};
 
typedef OdChar OdCharW;
typedef OdString OdString;
 
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline OdString operator+(const OdString& string1, const __wchar_t* string2)
{
  return operator+(string1, (const OdChar*)string2);
}
inline OdString operator+(const __wchar_t* string1, const OdString& string2)
{
  return operator+((const OdChar*)string1, string2);
}
#endif
 
inline bool operator==(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) == 0; }
 
inline bool operator==(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) == 0; }
 
inline bool operator==(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) == 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator==(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) == 0; }
 
inline bool operator==(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) == 0; }
#endif
 
inline bool operator==(const OdString& s1, const char* s2)
{ return s1.compare(s2) == 0; }
 
inline bool operator==(const char* s1, const OdString& s2)
{ return odStrCmpA((const char*)s2, s1) == 0; }
 
inline bool operator!=(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) != 0; }
 
inline bool operator!=(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) != 0; }
 
inline bool operator!=(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) != 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator!=(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) != 0; }
 
inline bool operator!=(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) != 0; }
#endif
 
inline bool operator!=(const OdString& s1, const char* s2)
{ return s1.compare(s2) != 0; }
 
inline bool operator!=(const char* s1, const OdString& s2)
{ return s2.compare(s1) != 0; }
 
inline bool operator<(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) < 0; }
 
inline bool operator<(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) < 0; }
 
inline bool operator<(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) > 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator<(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) < 0; }
 
inline bool operator<(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) > 0; }
#endif
 
inline bool operator<(const OdString& s1, const char* s2)
{ return s1.compare(s2) < 0; }
 
inline bool operator<(const char* s1, const OdString& s2)
{ return s2.compare(s1) > 0; }
 
inline bool operator>(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) > 0; }
 
inline bool operator>(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) > 0; }
 
inline bool operator>(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) < 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator>(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) > 0; }
inline bool operator>(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) < 0; }
#endif
 
inline bool operator>(const OdString& s1, const char* s2)
{ return s1.compare(s2) > 0; }
 
inline bool operator>(const char* s1, const OdString& s2)
{ return s2.compare(s1) < 0; }
 
inline bool operator<=(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) <= 0; }
 
inline bool operator<=(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) <= 0; }
 
inline bool operator<=(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) >= 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator<=(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) <= 0; }
inline bool operator<=(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) >= 0; }
#endif
 
inline bool operator<=(const OdString& s1, const char* s2)
{ return s1.compare(s2) <= 0; }
 
inline bool operator<=(const char* s1, const OdString& s2)
{ return s2.compare(s1) >= 0; }
 
inline bool operator>=(const OdString& s1, const OdString& s2)
  { return s1.compare(s2) >= 0; }
 
inline bool operator>=(const OdString& s1, const OdChar* s2)
  { return s1.compare(s2) >= 0; }
 
inline bool operator>=(const OdChar* s1, const OdString& s2)
  { return s2.compare(s1) <= 0; }
 
#if defined(_MSC_VER) && _MSC_VER >= 1300
inline bool operator>=(const OdString& s1, const __wchar_t* s2)
{ return s1.compare((const OdChar*)s2) >= 0; }
 
inline bool operator>=(const __wchar_t* s1, const OdString& s2)
{ return s2.compare((const OdChar*)s1) <= 0; }
#endif
 
inline bool operator>=(const OdString& s1, const char* s2)
{ return s1.compare(s2) >= 0; }
 
inline bool operator>=(const char* s1, const OdString& s2)
{ return s2.compare(s1) <= 0; }
 
#if defined(ODA_UNIXOS)
/** <group Other_Classes>
*/
class OdW2US
{
  OdUInt16* _buf;
public:
  OdW2US(const wchar_t* pStr)
  {
    size_t len = Od_wcslen(pStr);
    _buf = new OdUInt16[len+1];
    for (size_t i = 0; i < len; i++)
    {
      _buf[i] = (OdUInt16)pStr[i];
    }
    _buf[len] = 0;
  }
  ~OdW2US() 
  {
    delete _buf;
  }
  operator const OdUInt16*() const { return _buf; }
};
 
/** \details
    <group Other_Classes>
*/
class OdUS2W
{
  wchar_t* _buf;
public:
  OdUS2W(const OdUInt16* pStr)
  {
    size_t len = 0;
    if (const OdUInt16* p = pStr)
    {
      while (*p++)
        len++;
    }
    _buf = new wchar_t[len+1];
    for (size_t i = 0; i < len; i++)
    {
      _buf[i] = (wchar_t)pStr[i];
    }
    _buf[len] = 0;
  }
  ~OdUS2W() 
  {
    delete _buf;
  }
  operator const wchar_t*() const { return _buf; }
};
 
#else
 
#define OdUS2W(a) (const wchar_t*)(a)
#define OdW2US(a) (const OdUInt16*)(a)
 
#endif
 
//////////////////////////////////////////////////////////////////////////
 
/** \details
    <group Other_Classes>
*/
class FIRSTDLL_EXPORT OdConstString : public OdString
{
public:
  OdConstString(const OdChar* pSource = NULL);
  // Destructor of base class OdString is not virtual (critical for performance).
  // Therefore ~OdConstString is missing
 
  OdConstString& operator=(const OdConstString& pSource);
  OdString& operator=(const OdString& pSource);
  OdString& operator=(OdChar ch);
  OdString& operator=(const OdChar* pSource);
  OdString& operator=(const OdAnsiString& pSource);
  OdString& operator=(const char* pSource);
  operator const OdChar*() const;
 
protected:
  OdStringData m_data;  
};
 
//////////////////////////////////////////////////////////////////////////
 
#include "TD_PackPop.h"
 
#endif // __ODSTRING_H__