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
/////////////////////////////////////////////////////////////////////////////// 
// 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 __ODANSISTRING_H__
#define __ODANSISTRING_H__
 
#ifdef TD_UNICODE
#define ODA_CDECL 
#define ODA_PASCAL 
 
#include <stdarg.h>
#include <stdio.h>
 
#include "OdMutex.h"
#include "OdPlatform.h"
#include "OdArrayPreDef.h"
#include "OdCodePage.h"
 
#define odaIsValidString(lpch)    (true)
 
#include "TD_PackPush.h"
class OdString;
 
#ifdef sgi
#include <string>
 // va_XXXX items are in std namespace for newest SGI compiler
 
using namespace std; 
#endif
 
/** \details
This structure contains string data used by OdAnsiString.
 
\remarks
An char array (buffer) is allocated along with this structure, and
is freed when this structure is freed.
 
Library: TD_Root
<group !!RECORDS_TD_APIRef>
*/
struct OdStringDataA
{            
  /** \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;       
  
  OdCodePageId codepage;
 
  /** \details
  Returns the underlying char array (buffer) of this StringData object.
  */
  char* data()           
  { return (char*)(this+1); }
};
 
#ifdef _WIN32_WCE
ODA_ASSUME((sizeof(OdStringDataA)%8)==0);
#endif
 
/** \details
This structure represents empty strings used by OdAnsiString.
 
<group !!RECORDS_TD_APIRef>
*/
      struct OdEmptyStringDataA
{
  OdStringDataA  kStrData;
  char        kChar;
};
 
/** \details
This class implements Teigha single-byte character string objects.
 
\remarks
OdAnsiString objects use zero-based indices to access string elements.
 
<group Other_Classes>
*/
class FIRSTDLL_EXPORT OdAnsiString
{
public:
 
  OdAnsiString()
  { init(); }
 
  /** \param source [in]  Source.
  */
  OdAnsiString(const OdAnsiString& source);
 
  /** \param ch [in]  Character to repeat.
  \param length [in]  Number of characters.
  */
  OdAnsiString(char ch, int length);
 
  OdAnsiString(const char* source);
 
  OdAnsiString(const char* source, int length);
  OdAnsiString(const char* source, OdCodePageId);
  OdAnsiString(const char* source, int length, OdCodePageId);
  OdAnsiString(const OdString& , OdCodePageId);
 
  void setCodepage(OdCodePageId id);
  
  OdCodePageId codepage() const
  { return getData()->codepage; }
 
  /** \details
  Returns the number of characters in this String object.
  */
  int getLength() const
  { return getData()->nDataLength; }
 
  /** \details
  Returns true and only if this String object is empty.
  */
  bool isEmpty() const
  { return getData()->nDataLength == 0; }
 
  /** \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. 
  */
  char getAt(int charIndex) const
  {
    ODA_ASSERT(charIndex >= 0);
    ODA_ASSERT(charIndex < getData()->nDataLength);
    return m_pchData[charIndex];
  }
 
  /** \details
  Indexing Operator
 
  \remarks
  Returns the single character of this String object at the specified position.
  \param charIndex [in]  Character index. 
  */
  char operator[](int charIndex) const
  {
    ODA_ASSERT(charIndex >= 0);
    ODA_ASSERT(charIndex < getData()->nDataLength);
    return m_pchData[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, char ch);
 
  /** \details
  Returns the underlying char array (buffer) of this String object.
  */
  const char* c_str() const
  { return m_pchData; }
 
  /** \details
  Returns the underlying char array (buffer) of this String object.
  */
  operator const char*() const
  { return m_pchData; }
 
  OdAnsiString& operator=(const OdAnsiString& source);
 
  OdAnsiString& operator=(char ch);
 
  OdAnsiString& operator=(const char* source);
 
  OdAnsiString& operator=(const OdString& 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.
  */
  OdAnsiString& operator+=(const OdAnsiString& string);
 
  OdAnsiString& operator+=(char ch);
 
  OdAnsiString& 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 OdAnsiString operator+(const OdAnsiString& string1, const OdAnsiString& string2);
  friend FIRSTDLL_EXPORT OdAnsiString operator+(const OdAnsiString& string, char ch);
  friend FIRSTDLL_EXPORT OdAnsiString operator+(char ch, const OdAnsiString& string);
 
  friend FIRSTDLL_EXPORT OdAnsiString operator+(const OdAnsiString& string1, const char* string2);
  friend FIRSTDLL_EXPORT OdAnsiString operator+(const char* string1, const OdAnsiString& 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 char* otherString) const
  { ODA_ASSERT(odaIsValidString(otherString)); return odStrCmpA(m_pchData, otherString); }    // MBCS/Unicode aware 
 
  /** \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 char* otherString) const
  { ODA_ASSERT(odaIsValidString(otherString)); return odStrICmpA(m_pchData, otherString); }   
 
  /** \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.
  */
  OdAnsiString mid(int startIndex, int length) const;
 
  OdAnsiString mid(int startIndex) const;
 
  /** \details
  Returns the leftmost substring of the specified length from this String object.
  \param length [in]  Length of substring. 
  */
  OdAnsiString left(int length) const;
 
  /** \details
  Returns the rightmost substring of the specified length from this String object.
  \param length [in]  Length of substring. 
  */
  OdAnsiString 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.
  */
  OdAnsiString spanIncluding(const char* charSet) const;
 
  /** \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.
  */
  OdAnsiString spanExcluding(const char* charSet) const;
 
  /** \details
  Converts this String object to upper case.
 
  \remarks
  Returns a reference to this String object.  
  */
  OdAnsiString& makeUpper();
 
  /** \details
  Converts this String object to lower case.
 
  \remarks
  Returns a reference to this String object.  
  */
  OdAnsiString& makeLower();
 
  /** \details
  Reverses this String object.
 
  \remarks
  Returns a reference to this String object.  
  */
  OdAnsiString& 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.  
  */
  OdAnsiString& 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.  
  */
  OdAnsiString& trimLeft();
 
  /** \param whiteChar [in]  Whitespace character.
  */
  OdAnsiString& trimRight(char whiteChar);
 
  /** \param whiteChars [in]  Whitespace characters.
  */
  OdAnsiString& trimRight(const char* whiteChars);
 
  /** \param whiteChar [in]  Whitespace character.
  */
  OdAnsiString& trimLeft(char whiteChar);
 
  /** \param whiteChars [in]  Whitespace characters.
  */
  OdAnsiString& trimLeft(const char* whiteChars);
 
  /** \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(char oldChar, char newChar);
 
  /** \param oldString [in]  Old string.
  \param newString [in]  New string.
  */
  int replace(const char* oldString, const char* newString);
 
  /** \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(char 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, char insertChar);
 
  /** \details
  \param insertString [in]  String to insert.
  */
  int insert(int insertIndex, const char* insertString);
 
  /** \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(char 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(char searchChar) const;
 
  /** \param startIndex [in]  Start index.
  */
  int find(char 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 char* charSet) const;
 
  int find(const char* searchString) const;
 
  /** \param searchString [in]  Search string.
  */
  int find(const char* searchString, int startIndex) const;
 
  /** \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.
  */
  OdAnsiString& format(const char* formatString, ...);
 
  /** \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.
  */
  OdAnsiString& formatV(const char* formatString, va_list argList); 
 
  /** \details
  Returns a modifiable C style char 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 OdAnsiString methods.
 
  The pointer returned by this function is not valid after releaseBuffer() is called.
  */
  char* 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 char 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 OdAnsiString methods.
 
  The pointer returned by this function is not valid after releaseBuffer() is called.
  */
  char* getBufferSetLength(int length);
 
  /** \details
  Releases any unused memory allocated by this String object.
  */
  void freeExtra();
 
  /** \details
  Enables reference counting for this String object.
  */
  char* lockBuffer();
 
  /** \details
  Disables reference counting for this String object.
  */
  void unlockBuffer();
 
public:
  ~OdAnsiString();
 
  /** \details
  Returns the number of characters allocated for the underlying char array (buffer) in this String object.
  */
  int getAllocLength() const
  { return getData()->nAllocLength; }
 
protected:
  FIRSTDLL_EXPORT_STATIC static OdEmptyStringDataA kEmptyData;
 
  /** \details
  Pointer to the underlying char array (buffer). 
  */
  char* m_pchData;  
 
  /** \details
  Returns the StringData for this String object.
  */
  OdStringDataA* getData() const
  { ODA_ASSERT(m_pchData != NULL); return ((OdStringDataA*)m_pchData)-1; }
 
  /** \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(OdAnsiString& 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.
  */
  void allocBuffer(int length);
 
  /** \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 char* 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 char* source1, int sourceLength2, const char* 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 char* 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 ODA_PASCAL release(OdStringDataA* 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 ODA_PASCAL safeStrlen(const char* string)
  { return (string == NULL) ? (int)0 : (int)odStrLenA(string); }
 
  /** \details
  Frees the specified StringData object.
  \param pStringData [in]  Pointer to the StringData object.
  */
  static void freeData(OdStringDataA* pStringData);
  friend class OdString;
};
 
inline bool operator==(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) == 0; }
 
inline bool operator==(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) == 0; }
 
inline bool operator==(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) == 0; }
 
inline bool operator!=(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) != 0; }
 
inline bool operator!=(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) != 0; }
 
inline bool operator!=(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) != 0; }
 
inline bool operator<(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) < 0; }
 
inline bool operator<(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) < 0; }
 
inline bool operator<(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) > 0; }
 
inline bool operator>(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) > 0; }
 
inline bool operator>(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) > 0; }
 
inline bool operator>(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) < 0; }
 
inline bool operator<=(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) <= 0; }
 
inline bool operator<=(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) <= 0; }
 
inline bool operator<=(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) >= 0; }
 
inline bool operator>=(const OdAnsiString& s1, const OdAnsiString& s2)
{ return s1.compare(s2) >= 0; }
 
inline bool operator>=(const OdAnsiString& s1, const char* s2)
{ return s1.compare(s2) >= 0; }
 
inline bool operator>=(const char* s1, const OdAnsiString& s2)
{ return s2.compare(s1) <= 0; }
 
typedef OdArray<OdAnsiString> OdAnsiStringArray;
 
#include "TD_PackPop.h"
 
#endif // TD_UNICODE
 
#endif // __ODANSISTRING_H__