1 // Copyright (c) 1993-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
3 //
4 // This file is part of Open CASCADE Technology software library.
5 //
6 // This library is free software; you can redistribute it and/or modify it under
7 // the terms of the GNU Lesser General Public License version 2.1 as published
8 // by the Free Software Foundation, with special exception defined in the file
9 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
10 // distribution for complete text of the license and disclaimer of any warranty.
11 //
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
14
15 #include <TCollection_AsciiString.hxx>
16
17 #include <NCollection_UtfIterator.hxx>
18 #include <Standard.hxx>
19 #include <Standard_NegativeValue.hxx>
20 #include <Standard_NullObject.hxx>
21 #include <Standard_NumericError.hxx>
22 #include <Standard_OutOfRange.hxx>
23 #include <TCollection_ExtendedString.hxx>
24 #include <TCollection_HAsciiString.hxx>
25
26 #include <algorithm>
27 #include <cctype>
28 #include <cstdio>
29 #include <cstring>
30
31 // Shortcuts to standard allocate and reallocate functions
Allocate(const Standard_Size aLength)32 static inline Standard_PCharacter Allocate(const Standard_Size aLength)
33 {
34 return (Standard_PCharacter)Standard::Allocate (aLength);
35 }
Reallocate(Standard_Address aAddr,const Standard_Size aLength)36 static inline Standard_PCharacter Reallocate (Standard_Address aAddr,
37 const Standard_Size aLength)
38 {
39 return (Standard_PCharacter)Standard::Reallocate (aAddr, aLength);
40 }
Free(Standard_PCharacter aAddr)41 static inline void Free (Standard_PCharacter aAddr)
42 {
43 Standard_Address aPtr = aAddr;
44 Standard::Free (aPtr);
45 }
46
47 // ----------------------------------------------------------------------------
48 // Create an empty AsciiString
49 // ----------------------------------------------------------------------------
TCollection_AsciiString()50 TCollection_AsciiString::TCollection_AsciiString()
51 {
52 mylength = 0;
53
54 mystring = Allocate(mylength+1);
55 mystring[mylength] = '\0';
56 }
57
58
59 // ----------------------------------------------------------------------------
60 // Create an asciistring from a Standard_CString
61 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_CString theString)62 TCollection_AsciiString::TCollection_AsciiString (const Standard_CString theString)
63 : mystring(0),
64 mylength(0)
65 {
66 if (theString == NULL)
67 {
68 throw Standard_NullObject ("TCollection_AsciiString(): NULL pointer passed to constructor");
69 }
70
71 mylength = Standard_Integer (strlen (theString));
72 mystring = Allocate (mylength + 1);
73 memcpy (mystring, theString, mylength);
74 mystring[mylength] = '\0';
75 }
76
77
78 // ----------------------------------------------------------------------------
79 // Create an asciistring from a Standard_CString
80 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_CString theString,const Standard_Integer theLen)81 TCollection_AsciiString::TCollection_AsciiString (const Standard_CString theString,
82 const Standard_Integer theLen)
83 : mystring (NULL),
84 mylength (0)
85 {
86 if (theString == NULL)
87 {
88 throw Standard_NullObject ("TCollection_AsciiString(): NULL pointer passed to constructor");
89 }
90
91 for (; mylength < theLen && theString[mylength] != '\0'; ++mylength) {}
92 mystring = Allocate (mylength + 1);
93 memcpy (mystring, theString, mylength);
94 mystring[mylength] = '\0';
95 }
96
97 // ----------------------------------------------------------------------------
98 // Create an asciistring from a Standard_Character
99 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_Character aChar)100 TCollection_AsciiString::TCollection_AsciiString(const Standard_Character aChar)
101 : mystring(0)
102 {
103 if ( aChar != '\0' ) {
104 mylength = 1;
105 mystring = Allocate(2);
106 mystring[0] = aChar;
107 mystring[1] = '\0';
108 }
109 else {
110 mylength = 0;
111 mystring = Allocate(mylength+1);
112 mystring[mylength] = '\0';
113 }
114 }
115
116 // ----------------------------------------------------------------------------
117 // Create an AsciiString from a filler
118 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_Integer length,const Standard_Character filler)119 TCollection_AsciiString::TCollection_AsciiString(const Standard_Integer length,
120 const Standard_Character filler )
121 {
122 mystring = Allocate(length+1);
123 mylength = length;
124 for (int i = 0 ; i < length ; i++) mystring[i] = filler;
125 mystring[length] = '\0';
126 }
127
128 // ----------------------------------------------------------------------------
129 // Create an AsciiString from an Integer
130 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_Integer aValue)131 TCollection_AsciiString::TCollection_AsciiString(const Standard_Integer aValue)
132 : mystring(0)
133 {
134 char t [13];
135 mylength = Sprintf( t,"%d",aValue);
136 mystring = Allocate(mylength+1);
137 memcpy (mystring, t, mylength);
138 mystring[mylength] = '\0';
139 }
140
141 // ----------------------------------------------------------------------------
142 // Create an asciistring from a real
143 // ----------------------------------------------------------------------------
TCollection_AsciiString(const Standard_Real aValue)144 TCollection_AsciiString::TCollection_AsciiString(const Standard_Real aValue)
145 : mystring(0)
146 {
147 char t [50];
148 mylength = Sprintf( t,"%g",aValue);
149 mystring = Allocate(mylength+1);
150 memcpy (mystring, t, mylength);
151 mystring[mylength] = '\0';
152 }
153
154 // ----------------------------------------------------------------------------
155 // Create an asciistring from an asciistring
156 // ----------------------------------------------------------------------------
TCollection_AsciiString(const TCollection_AsciiString & theString)157 TCollection_AsciiString::TCollection_AsciiString (const TCollection_AsciiString& theString)
158 : mystring (Allocate (theString.mylength + 1)),
159 mylength (theString.mylength)
160 {
161 if (mylength != 0)
162 {
163 memcpy (mystring, theString.mystring, mylength);
164 }
165 mystring[mylength] = '\0';
166 }
167
168 // ----------------------------------------------------------------------------
169 // Create an asciistring from a character
170 // ----------------------------------------------------------------------------
TCollection_AsciiString(const TCollection_AsciiString & theString,const Standard_Character theChar)171 TCollection_AsciiString::TCollection_AsciiString (const TCollection_AsciiString& theString,
172 const Standard_Character theChar)
173 : mystring (NULL),
174 mylength (theString.mylength + 1)
175 {
176 mystring = Allocate (mylength + 1);
177 if (theString.mylength != 0)
178 {
179 memcpy (mystring, theString.mystring, theString.mylength);
180 }
181 mystring[mylength - 1] = theChar;
182 mystring[mylength] = '\0';
183 }
184
185 // ----------------------------------------------------------------------------
186 // Create an asciistring from an asciistring
187 // ----------------------------------------------------------------------------
TCollection_AsciiString(const TCollection_AsciiString & theString1,const Standard_CString theString2)188 TCollection_AsciiString::TCollection_AsciiString (const TCollection_AsciiString& theString1,
189 const Standard_CString theString2)
190 : mystring (0)
191 {
192 const Standard_Integer aStr2Len = Standard_Integer (theString2 ? strlen (theString2) : 0);
193 mylength = theString1.mylength + aStr2Len;
194 mystring = Allocate (mylength + 1);
195 if (theString1.mylength != 0)
196 {
197 memcpy (mystring, theString1.mystring, theString1.mylength);
198 }
199 if (aStr2Len != 0)
200 {
201 memcpy (mystring + theString1.mylength, theString2, aStr2Len);
202 }
203 mystring[mylength] = '\0';
204 }
205
206 // ----------------------------------------------------------------------------
207 // Create an asciistring from an asciistring
208 // ----------------------------------------------------------------------------
TCollection_AsciiString(const TCollection_AsciiString & theString1,const TCollection_AsciiString & theString2)209 TCollection_AsciiString::TCollection_AsciiString (const TCollection_AsciiString& theString1,
210 const TCollection_AsciiString& theString2)
211 : mystring (0),
212 mylength (theString1.mylength + theString2.mylength)
213 {
214 mystring = Allocate (mylength + 1);
215 if (theString1.mylength)
216 {
217 memcpy (mystring, theString1.mystring, theString1.mylength);
218 }
219 if (theString2.mylength != 0)
220 {
221 memcpy (mystring + theString1.mylength, theString2.mystring, theString2.mylength);
222 }
223 mystring[mylength] = '\0';
224 }
225
226 //---------------------------------------------------------------------------
227 // Create an asciistring from an ExtendedString
228 //---------------------------------------------------------------------------
TCollection_AsciiString(const TCollection_ExtendedString & astring,const Standard_Character replaceNonAscii)229 TCollection_AsciiString::TCollection_AsciiString(const TCollection_ExtendedString& astring,
230 const Standard_Character replaceNonAscii)
231 : mystring (0)
232 {
233 if (replaceNonAscii)
234 {
235 mylength = astring.Length();
236 mystring = Allocate(mylength+1);
237 for(int i = 0; i < mylength; i++) {
238 Standard_ExtCharacter c = astring.Value(i+1);
239 mystring[i] = ( IsAnAscii(c) ? ToCharacter(c) : replaceNonAscii );
240 }
241 mystring[mylength] = '\0';
242 }
243 else {
244 // create UTF-8 string
245 mylength = astring.LengthOfCString();
246 mystring = Allocate(mylength+1);
247 astring.ToUTF8CString(mystring);
248 }
249 }
250
251 //---------------------------------------------------------------------------
252 // Create an TCollection_AsciiString from a Standard_WideChar
253 //---------------------------------------------------------------------------
TCollection_AsciiString(const Standard_WideChar * theStringUtf)254 TCollection_AsciiString::TCollection_AsciiString (const Standard_WideChar* theStringUtf)
255 : mystring (NULL),
256 mylength (0)
257 {
258 for (NCollection_UtfWideIter anIter (theStringUtf); *anIter != 0; ++anIter)
259 {
260 mylength += anIter.AdvanceBytesUtf8();
261 }
262
263 mystring = Allocate (mylength + 1);
264 mystring[mylength] = '\0';
265 NCollection_UtfWideIter anIterRead (theStringUtf);
266 for (Standard_Utf8Char* anIterWrite = mystring; *anIterRead != 0; ++anIterRead)
267 {
268 anIterWrite = anIterRead.GetUtf(anIterWrite);
269 }
270 }
271
272 // ----------------------------------------------------------------------------
273 // AssignCat
274 // ----------------------------------------------------------------------------
AssignCat(const Standard_Integer other)275 void TCollection_AsciiString::AssignCat(const Standard_Integer other)
276 {
277
278 AssignCat(TCollection_AsciiString(other));
279
280 }
281
282 // ----------------------------------------------------------------------------
283 // AssignCat
284 // ----------------------------------------------------------------------------
AssignCat(const Standard_Real other)285 void TCollection_AsciiString::AssignCat(const Standard_Real other)
286 {
287
288 AssignCat(TCollection_AsciiString(other));
289
290 }
291
292 // ----------------------------------------------------------------------------
293 // AssignCat
294 // ----------------------------------------------------------------------------
AssignCat(const Standard_Character other)295 void TCollection_AsciiString::AssignCat(const Standard_Character other)
296 {
297 if (other != '\0') {
298 mystring = Reallocate (mystring, mylength + 2);
299 mystring[mylength] = other ;
300 mylength += 1;
301 mystring[mylength] = '\0';
302 }
303 }
304
305 // ----------------------------------------------------------------------------
306 // AssignCat
307 // ----------------------------------------------------------------------------
AssignCat(const Standard_CString theOther)308 void TCollection_AsciiString::AssignCat (const Standard_CString theOther)
309 {
310 if (theOther == NULL)
311 {
312 throw Standard_NullObject("TCollection_AsciiString::Operator += parameter other");
313 }
314
315 Standard_Integer anOtherLen = Standard_Integer (strlen (theOther));
316 if (anOtherLen != 0)
317 {
318 const Standard_Integer aNewLen = mylength + anOtherLen;
319 mystring = Reallocate (mystring, aNewLen + 1);
320 memcpy (mystring + mylength, theOther, anOtherLen + 1);
321 mylength = aNewLen;
322 }
323 }
324
325 // ----------------------------------------------------------------------------
326 // AssignCat
327 // ----------------------------------------------------------------------------
AssignCat(const TCollection_AsciiString & theOther)328 void TCollection_AsciiString::AssignCat (const TCollection_AsciiString& theOther)
329 {
330 if (theOther.mylength != 0)
331 {
332 const Standard_Integer aNewLen = mylength + theOther.mylength;
333 mystring = Reallocate (mystring, aNewLen + 1);
334 memcpy (mystring + mylength, theOther.mystring, theOther.mylength + 1);
335 mylength = aNewLen;
336 }
337 }
338
339 // ---------------------------------------------------------------------------
340 // Capitalize
341 // ----------------------------------------------------------------------------
Capitalize()342 void TCollection_AsciiString::Capitalize()
343 {
344 if ( mylength ) mystring[0] = ::UpperCase(mystring[0]);
345 for (int i = 1; i < mylength; i++ )
346 mystring[i] = ::LowerCase(mystring[i]);
347 }
348
349 // ---------------------------------------------------------------------------
350 // Center
351 // ----------------------------------------------------------------------------
Center(const Standard_Integer Width,const Standard_Character Filler)352 void TCollection_AsciiString::Center(const Standard_Integer Width ,
353 const Standard_Character Filler)
354 {
355 if(Width > mylength) {
356 Standard_Integer newlength = mylength + ((Width - mylength)/2);
357 LeftJustify(newlength,Filler);
358 RightJustify(Width,Filler);
359 }
360 else if (Width < 0) {
361 throw Standard_NegativeValue();
362 }
363 }
364
365 // ----------------------------------------------------------------------------
366 // ChangeAll
367 // ----------------------------------------------------------------------------
ChangeAll(const Standard_Character aChar,const Standard_Character NewChar,const Standard_Boolean CaseSensitive)368 void TCollection_AsciiString::ChangeAll(const Standard_Character aChar,
369 const Standard_Character NewChar,
370 const Standard_Boolean CaseSensitive)
371 {
372 if (CaseSensitive){
373 for (int i=0; i < mylength; i++)
374 if (mystring[i] == aChar) mystring[i] = NewChar;
375 }
376 else{
377 Standard_Character anUpperChar = ::UpperCase(aChar);
378 for (int i=0; i < mylength; i++)
379 if (::UpperCase(mystring[i]) == anUpperChar) mystring[i] = NewChar;
380 }
381 }
382
383 // ----------------------------------------------------------------------------
384 // Clear
385 // ----------------------------------------------------------------------------
Clear()386 void TCollection_AsciiString::Clear()
387 {
388 if ( mylength > 0 )
389 {
390 Free (mystring);
391 mylength = 0;
392 mystring = Allocate(mylength+1);
393 mystring[mylength] = '\0';
394 }
395 }
396
397 // ----------------------------------------------------------------------------
398 // Copy
399 // ----------------------------------------------------------------------------
Copy(const Standard_CString fromwhere)400 void TCollection_AsciiString::Copy(const Standard_CString fromwhere)
401 {
402 if (fromwhere) {
403 mylength = Standard_Integer( strlen( fromwhere ));
404 mystring = Reallocate (mystring, mylength + 1);
405 memcpy (mystring, fromwhere, mylength + 1);
406 }
407 else {
408 mylength = 0;
409 mystring[mylength] = '\0';
410 }
411 }
412
413 // ----------------------------------------------------------------------------
414 // Copy
415 // ----------------------------------------------------------------------------
Copy(const TCollection_AsciiString & fromwhere)416 void TCollection_AsciiString::Copy(const TCollection_AsciiString& fromwhere)
417 {
418 if (fromwhere.mystring) {
419 mylength = fromwhere.mylength;
420 mystring = Reallocate (mystring, mylength + 1);
421 memcpy (mystring, fromwhere.mystring, mylength + 1);
422 }
423 else {
424 mylength = 0;
425 mystring[mylength] = '\0';
426 }
427 }
428
429 // ----------------------------------------------------------------------------
430 // Swap
431 // ----------------------------------------------------------------------------
Swap(TCollection_AsciiString & theOther)432 void TCollection_AsciiString::Swap (TCollection_AsciiString& theOther)
433 {
434 std::swap (mystring, theOther.mystring);
435 std::swap (mylength, theOther.mylength);
436 }
437
438 // ----------------------------------------------------------------------------
439 // Destroy
440 // ----------------------------------------------------------------------------
~TCollection_AsciiString()441 TCollection_AsciiString::~TCollection_AsciiString()
442 {
443 if (mystring)
444 Free (mystring);
445 mystring = 0L;
446 }
447
448 // ----------------------------------------------------------------------------
449 // FirstLocationInSet
450 // ----------------------------------------------------------------------------
FirstLocationInSet(const TCollection_AsciiString & Set,const Standard_Integer FromIndex,const Standard_Integer ToIndex) const451 Standard_Integer TCollection_AsciiString::FirstLocationInSet
452 (const TCollection_AsciiString& Set,
453 const Standard_Integer FromIndex,
454 const Standard_Integer ToIndex) const
455 {
456 if (mylength == 0 || Set.mylength == 0) return 0;
457 if (FromIndex > 0 && ToIndex <= mylength && FromIndex <= ToIndex ) {
458 for(int i = FromIndex-1 ; i < ToIndex; i++)
459 for(int j = 0; j < Set.mylength; j++)
460 if (mystring[i] == Set.mystring[j]) return i+1;
461 return 0;
462 }
463 throw Standard_OutOfRange();
464 }
465
466 // ----------------------------------------------------------------------------
467 // FirstLocationNotInSet
468 // ----------------------------------------------------------------------------
FirstLocationNotInSet(const TCollection_AsciiString & Set,const Standard_Integer FromIndex,const Standard_Integer ToIndex) const469 Standard_Integer TCollection_AsciiString::FirstLocationNotInSet
470 (const TCollection_AsciiString& Set,
471 const Standard_Integer FromIndex,
472 const Standard_Integer ToIndex) const
473 {
474 if (mylength == 0 || Set.mylength == 0) return 0;
475 if (FromIndex > 0 && ToIndex <= mylength && FromIndex <= ToIndex ) {
476 Standard_Boolean find;
477 for (int i = FromIndex-1 ; i < ToIndex; i++) {
478 find = Standard_False;
479 for(int j = 0; j < Set.mylength; j++)
480 if (mystring[i] == Set.mystring[j]) find = Standard_True;
481 if (!find) return i+1;
482 }
483 return 0;
484 }
485 throw Standard_OutOfRange();
486 }
487
488 //----------------------------------------------------------------------------
489 // Insert a character before 'where'th character
490 // ----------------------------------------------------------------------------
Insert(const Standard_Integer where,const Standard_Character what)491 void TCollection_AsciiString::Insert(const Standard_Integer where,
492 const Standard_Character what)
493 {
494 if (where > mylength + 1 ) throw Standard_OutOfRange("TCollection_AsciiString::Insert : Parameter where is too big");
495 if (where < 1) throw Standard_OutOfRange("TCollection_AsciiString::Insert : Parameter where is too small");
496
497 mystring = Reallocate (mystring, mylength + 2);
498 if (where != mylength +1) {
499 for (int i=mylength-1; i >= where-1; i--)
500 mystring[i+1] = mystring[i];
501 }
502 mystring[where-1] = what;
503 mylength++;
504 mystring[mylength] = '\0';
505 }
506
507 // ----------------------------------------------------------------------------
508 // Insert
509 // ----------------------------------------------------------------------------
Insert(const Standard_Integer where,const Standard_CString what)510 void TCollection_AsciiString::Insert(const Standard_Integer where,
511 const Standard_CString what)
512 {
513 if (where <= mylength + 1 && where > 0) {
514 if(what) {
515 Standard_Integer whatlength = Standard_Integer( strlen( what ) );
516 Standard_Integer newlength = mylength + whatlength;
517
518 mystring = Reallocate (mystring, newlength + 1);
519 if (where != mylength +1) {
520 for (int i=mylength-1; i >= where-1; i--)
521 mystring[i+whatlength] = mystring[i];
522 }
523 for (int i=0; i < whatlength; i++)
524 mystring[where-1+i] = what[i];
525
526 mylength = newlength;
527 mystring[mylength] = '\0';
528 }
529 }
530 else {
531 throw Standard_OutOfRange("TCollection_AsciiString::Insert : "
532 "Parameter where is invalid");
533 }
534 }
535
536 // ----------------------------------------------------------------------------
537 // Insert
538 // ----------------------------------------------------------------------------
Insert(const Standard_Integer where,const TCollection_AsciiString & what)539 void TCollection_AsciiString::Insert(const Standard_Integer where,
540 const TCollection_AsciiString& what)
541 {
542 Standard_CString swhat = what.mystring;
543 if (where <= mylength + 1) {
544 Standard_Integer whatlength = what.mylength;
545 if(whatlength) {
546 Standard_Integer newlength = mylength + whatlength;
547
548 mystring = Reallocate (mystring, newlength + 1);
549
550 if (where != mylength +1) {
551 for (int i=mylength-1; i >= where-1; i--)
552 mystring[i+whatlength] = mystring[i];
553 }
554 for (int i=0; i < whatlength; i++)
555 mystring[where-1+i] = swhat[i];
556
557 mylength = newlength;
558 mystring[mylength] = '\0';
559 }
560 }
561 else {
562 throw Standard_OutOfRange("TCollection_AsciiString::Insert : "
563 "Parameter where is too big");
564 }
565 }
566
567 //------------------------------------------------------------------------
568 // InsertAfter
569 //------------------------------------------------------------------------
InsertAfter(const Standard_Integer Index,const TCollection_AsciiString & what)570 void TCollection_AsciiString::InsertAfter(const Standard_Integer Index,
571 const TCollection_AsciiString& what)
572 {
573 if (Index < 0 || Index > mylength) throw Standard_OutOfRange();
574 Insert(Index+1,what);
575 }
576
577 //------------------------------------------------------------------------
578 // InsertBefore
579 //------------------------------------------------------------------------
InsertBefore(const Standard_Integer Index,const TCollection_AsciiString & what)580 void TCollection_AsciiString::InsertBefore(const Standard_Integer Index,
581 const TCollection_AsciiString& what)
582 {
583 if (Index < 1 || Index > mylength) throw Standard_OutOfRange();
584 Insert(Index,what);
585 }
586
587 // ----------------------------------------------------------------------------
588 // IsEqual
589 // ----------------------------------------------------------------------------
IsEqual(const Standard_CString other) const590 Standard_Boolean TCollection_AsciiString::IsEqual
591 (const Standard_CString other)const
592 {
593 if (other) {
594 return ( strncmp( other, mystring, mylength+1 ) == 0 );
595 }
596 throw Standard_NullObject("TCollection_AsciiString::Operator == "
597 "Parameter 'other'");
598 }
599
600 // ----------------------------------------------------------------------------
601 // IsEqual
602 // ----------------------------------------------------------------------------
IsEqual(const TCollection_AsciiString & other) const603 Standard_Boolean TCollection_AsciiString::IsEqual
604 (const TCollection_AsciiString& other)const
605 {
606 if (mylength != other.mylength) return Standard_False;
607 return ( strncmp( other.mystring, mystring, mylength ) == 0 );
608 }
609
610 // ----------------------------------------------------------------------------
611 // IsSameString
612 // ----------------------------------------------------------------------------
IsSameString(const TCollection_AsciiString & theString1,const TCollection_AsciiString & theString2,const Standard_Boolean theIsCaseSensitive)613 Standard_Boolean TCollection_AsciiString::IsSameString (const TCollection_AsciiString& theString1,
614 const TCollection_AsciiString& theString2,
615 const Standard_Boolean theIsCaseSensitive)
616 {
617 const Standard_Integer aSize1 = theString1.Length();
618 if (aSize1 != theString2.Length())
619 {
620 return Standard_False;
621 }
622
623 if (theIsCaseSensitive)
624 {
625 return (strncmp (theString1.ToCString(), theString2.ToCString(), aSize1) == 0);
626 }
627
628 for (Standard_Integer aCharIter = 1; aCharIter <= aSize1; ++aCharIter)
629 {
630 if (toupper (theString1.Value (aCharIter)) != toupper (theString2.Value (aCharIter)))
631 {
632 return Standard_False;
633 }
634 }
635 return Standard_True;
636 }
637
638 // ----------------------------------------------------------------------------
639 // IsDifferent
640 // ----------------------------------------------------------------------------
IsDifferent(const Standard_CString other) const641 Standard_Boolean TCollection_AsciiString::IsDifferent
642 (const Standard_CString other)const
643 {
644 if (other) {
645 return ( strncmp( other, mystring, mylength+1 ) != 0 );
646 }
647 throw Standard_NullObject("TCollection_AsciiString::Operator != "
648 "Parameter 'other'");
649 }
650
651 // ----------------------------------------------------------------------------
652 // IsDifferent
653 // ----------------------------------------------------------------------------
IsDifferent(const TCollection_AsciiString & other) const654 Standard_Boolean TCollection_AsciiString::IsDifferent
655 (const TCollection_AsciiString& other)const
656 {
657
658 if (mylength != other.mylength) return Standard_True;
659 return ( strncmp( other.mystring, mystring, mylength ) != 0 );
660 }
661
662 // ----------------------------------------------------------------------------
663 // IsLess
664 // ----------------------------------------------------------------------------
IsLess(const Standard_CString other) const665 Standard_Boolean TCollection_AsciiString::IsLess
666 (const Standard_CString other)const
667 {
668 if (other) {
669 return ( strncmp( mystring, other, mylength+1 ) < 0 );
670 }
671 throw Standard_NullObject("TCollection_AsciiString::Operator < "
672 "Parameter 'other'");
673 }
674
675 // ----------------------------------------------------------------------------
676 // IsLess
677 // ----------------------------------------------------------------------------
IsLess(const TCollection_AsciiString & other) const678 Standard_Boolean TCollection_AsciiString::IsLess
679 (const TCollection_AsciiString& other)const
680 {
681 return ( strncmp( mystring, other.mystring, mylength+1 ) < 0 );
682 }
683
684 // ----------------------------------------------------------------------------
685 // IsGreater
686 // ----------------------------------------------------------------------------
IsGreater(const Standard_CString other) const687 Standard_Boolean TCollection_AsciiString::IsGreater
688 (const Standard_CString other)const
689 {
690 if (other) {
691 return ( strncmp( mystring, other, mylength+1 ) > 0 );
692 }
693 throw Standard_NullObject("TCollection_AsciiString::Operator > "
694 "Parameter 'other'");
695 }
696
697 // ----------------------------------------------------------------------------
698 // IsGreater
699 // ----------------------------------------------------------------------------
IsGreater(const TCollection_AsciiString & other) const700 Standard_Boolean TCollection_AsciiString::IsGreater
701 (const TCollection_AsciiString& other)const
702 {
703 return ( strncmp( mystring, other.mystring, mylength+1 ) > 0 );
704 }
705
706 // ----------------------------------------------------------------------------
707 // StartsWith
708 // ----------------------------------------------------------------------------
StartsWith(const TCollection_AsciiString & theStartString) const709 Standard_Boolean TCollection_AsciiString::StartsWith (const TCollection_AsciiString& theStartString) const
710 {
711 if (this == &theStartString)
712 {
713 return true;
714 }
715
716 return mylength >= theStartString.mylength
717 && strncmp (theStartString.mystring, mystring, theStartString.mylength) == 0;
718 }
719
720 // ----------------------------------------------------------------------------
721 // EndsWith
722 // ----------------------------------------------------------------------------
EndsWith(const TCollection_AsciiString & theEndString) const723 Standard_Boolean TCollection_AsciiString::EndsWith (const TCollection_AsciiString& theEndString) const
724 {
725 if (this == &theEndString)
726 {
727 return true;
728 }
729
730 return mylength >= theEndString.mylength
731 && strncmp (theEndString.mystring, mystring + mylength - theEndString.mylength, theEndString.mylength) == 0;
732 }
733
734 // ----------------------------------------------------------------------------
735 // IntegerValue
736 // ----------------------------------------------------------------------------
IntegerValue() const737 Standard_Integer TCollection_AsciiString::IntegerValue()const
738 {
739 char *ptr;
740 Standard_Integer value = (Standard_Integer)strtol(mystring,&ptr,10);
741 if (ptr != mystring) return value;
742
743 throw Standard_NumericError("TCollection_AsciiString::IntegerValue");
744 }
745
746 // ----------------------------------------------------------------------------
747 // IsIntegerValue
748 // ----------------------------------------------------------------------------
IsIntegerValue() const749 Standard_Boolean TCollection_AsciiString::IsIntegerValue()const
750 {
751 char *ptr;
752 strtol(mystring,&ptr,10);
753
754 if (ptr != mystring) {
755 for (int i=int(ptr-mystring); i < mylength; i++) {
756 if (mystring[i] == '.') return Standard_False; // what about 'e','x',etc ???
757 }
758 return Standard_True;
759 }
760 return Standard_False;
761 }
762
763 // ----------------------------------------------------------------------------
764 // IsRealValue
765 // ----------------------------------------------------------------------------
IsRealValue(Standard_Boolean theToCheckFull) const766 Standard_Boolean TCollection_AsciiString::IsRealValue (Standard_Boolean theToCheckFull)const
767 {
768 char *ptr;
769 Strtod(mystring,&ptr);
770 if (theToCheckFull)
771 {
772 return (ptr[0] == '\0');
773 }
774 else
775 {
776 return (ptr != mystring);
777 }
778 }
779
780 // ----------------------------------------------------------------------------
781 // IsAscii
782 // ----------------------------------------------------------------------------
IsAscii() const783 Standard_Boolean TCollection_AsciiString::IsAscii()const
784 {
785 // LD : Debuggee le 26/11/98
786 // Cette fonction retournait TOUJOURS Standard_True !
787 for (int i=0; i < mylength; i++)
788 if (mystring[i] >= 127 || mystring[i] < ' ') return Standard_False;
789 return Standard_True;
790 }
791
792 //------------------------------------------------------------------------
793 // LeftAdjust
794 //------------------------------------------------------------------------
LeftAdjust()795 void TCollection_AsciiString::LeftAdjust ()
796 {
797 Standard_Integer i ;
798 for( i = 0 ; i < mylength ; i ++) if(!IsSpace(mystring[i])) break;
799 if( i > 0 ) Remove(1,i);
800 }
801
802 //------------------------------------------------------------------------
803 // LeftJustify
804 //------------------------------------------------------------------------
LeftJustify(const Standard_Integer Width,const Standard_Character Filler)805 void TCollection_AsciiString::LeftJustify(const Standard_Integer Width,
806 const Standard_Character Filler)
807 {
808 if (Width > mylength) {
809 mystring = Reallocate (mystring, Width + 1);
810 for (int i = mylength; i < Width ; i++) mystring[i] = Filler;
811 mylength = Width;
812 mystring[mylength] = '\0';
813 }
814 else if (Width < 0) {
815 throw Standard_NegativeValue();
816 }
817 }
818
819 //------------------------------------------------------------------------
820 // Location
821 //------------------------------------------------------------------------
Location(const Standard_Integer N,const Standard_Character C,const Standard_Integer FromIndex,const Standard_Integer ToIndex) const822 Standard_Integer TCollection_AsciiString::Location
823 (const Standard_Integer N ,
824 const Standard_Character C ,
825 const Standard_Integer FromIndex,
826 const Standard_Integer ToIndex ) const
827 {
828 if (FromIndex > 0 && ToIndex <= mylength && FromIndex <= ToIndex ) {
829 for(int i = FromIndex-1, count = 0; i <= ToIndex-1; i++) {
830 if(mystring[i] == C) {
831 count++;
832 if ( count == N ) return i+1;
833 }
834 }
835 return 0 ;
836 }
837 throw Standard_OutOfRange();
838 }
839
840 //------------------------------------------------------------------------
841 // Location
842 //------------------------------------------------------------------------
Location(const TCollection_AsciiString & what,const Standard_Integer FromIndex,const Standard_Integer ToIndex) const843 Standard_Integer TCollection_AsciiString::Location
844 (const TCollection_AsciiString& what,
845 const Standard_Integer FromIndex,
846 const Standard_Integer ToIndex) const
847 {
848 if (mylength == 0 || what.mylength == 0) return 0;
849 if (ToIndex <= mylength && FromIndex > 0 && FromIndex <= ToIndex ) {
850 Standard_Integer i = FromIndex-1;
851 Standard_Integer k = 1;
852 Standard_Integer l = FromIndex-2;
853 Standard_Boolean Find = Standard_False;
854 while (!Find && i < ToIndex) {
855 if (mystring[i] == what.Value(k)) {
856 k++;
857 if ( k > what.mylength) Find = Standard_True;
858 }
859 else {
860 if (k > 1) i--; // si on est en cours de recherche
861 k = 1;
862 l = i;
863 }
864 i++;
865 }
866 if (Find) return l+2;
867 else return 0;
868 }
869 throw Standard_OutOfRange();
870 }
871
872 // ----------------------------------------------------------------------------
873 // LowerCase
874 // ----------------------------------------------------------------------------
LowerCase()875 void TCollection_AsciiString::LowerCase()
876 {
877 for (int i=0; i < mylength; i++)
878 mystring[i] = ::LowerCase(mystring[i]);
879 }
880
881 //------------------------------------------------------------------------
882 // Prepend
883 //------------------------------------------------------------------------
Prepend(const TCollection_AsciiString & what)884 void TCollection_AsciiString::Prepend(const TCollection_AsciiString& what)
885 {
886 Insert(1,what);
887 }
888
889 // ----------------------------------------------------------------------------
890 // RealValue
891 // ----------------------------------------------------------------------------
RealValue() const892 Standard_Real TCollection_AsciiString::RealValue()const
893 {
894 char *ptr;
895 Standard_Real value = Strtod(mystring,&ptr);
896 if (ptr != mystring) return value;
897
898 throw Standard_NumericError("TCollection_AsciiString::RealValue");
899 }
900
901 // ----------------------------------------------------------------------------
902 // Read
903 //--------------------------------------------------------------------------
Read(Standard_IStream & astream)904 void TCollection_AsciiString::Read(Standard_IStream& astream)
905 {
906 // get characters from astream
907 const Standard_Integer bufSize = 8190;
908 Standard_Character buffer[bufSize];
909 std::streamsize oldWidth = astream.width (bufSize);
910 astream >> buffer;
911 astream.width( oldWidth );
912
913 // put to string
914 mylength = Standard_Integer( strlen( buffer ));
915 mystring = Reallocate (mystring, mylength + 1);
916 memcpy (mystring, buffer, mylength);
917 mystring[mylength] = '\0';
918 }
919
920
921 //---------------------------------------------------------------------------
operator >>(Standard_IStream & astream,TCollection_AsciiString & astring)922 Standard_IStream& operator >> (Standard_IStream& astream,
923 TCollection_AsciiString& astring)
924 {
925 astring.Read(astream);
926 return astream;
927 }
928
929
930 // ----------------------------------------------------------------------------
931 // Print
932 // ----------------------------------------------------------------------------
Print(Standard_OStream & astream) const933 void TCollection_AsciiString::Print(Standard_OStream& astream)const
934 {
935 if(mystring) astream << mystring;
936 }
937
938
939 // ----------------------------------------------------------------------------
operator <<(Standard_OStream & astream,const TCollection_AsciiString & astring)940 Standard_OStream& operator << (Standard_OStream& astream,
941 const TCollection_AsciiString& astring)
942 {
943 astring.Print(astream);
944 return astream;
945 }
946
947 // ----------------------------------------------------------------------------
948 // RemoveAll
949 // ----------------------------------------------------------------------------
RemoveAll(const Standard_Character what,const Standard_Boolean CaseSensitive)950 void TCollection_AsciiString::RemoveAll(const Standard_Character what,
951 const Standard_Boolean CaseSensitive)
952 {
953 if (mylength == 0) return;
954 int c = 0;
955 if (CaseSensitive) {
956 for (int i=0; i < mylength; i++)
957 if (mystring[i] != what) mystring[c++] = mystring[i];
958 }
959 else {
960 Standard_Character upperwhat = ::UpperCase(what);
961 for (int i=0; i < mylength; i++) {
962 if (::UpperCase(mystring[i]) != upperwhat) mystring[c++] = mystring[i];
963 }
964 }
965 mylength = c;
966 mystring[mylength] = '\0';
967 }
968
969 // ----------------------------------------------------------------------------
970 // RemoveAll
971 // ----------------------------------------------------------------------------
RemoveAll(const Standard_Character what)972 void TCollection_AsciiString::RemoveAll(const Standard_Character what)
973 {
974 if (mylength == 0) return;
975 int c = 0;
976 for (int i=0; i < mylength; i++)
977 if (mystring[i] != what) mystring[c++] = mystring[i];
978 mylength = c;
979 mystring[mylength] = '\0';
980 }
981
982 // ----------------------------------------------------------------------------
983 // Remove
984 // ----------------------------------------------------------------------------
Remove(const Standard_Integer where,const Standard_Integer ahowmany)985 void TCollection_AsciiString::Remove (const Standard_Integer where,
986 const Standard_Integer ahowmany)
987 {
988 if (where+ahowmany <= mylength+1) {
989 int i,j;
990 for(i = where+ahowmany-1, j = where-1; i < mylength; i++, j++)
991 mystring[j] = mystring[i];
992 mylength -= ahowmany;
993 mystring[mylength] = '\0';
994 }
995 else {
996 throw Standard_OutOfRange("TCollection_AsciiString::Remove: "
997 "Too many characters to erase or invalid "
998 "starting value.");
999 }
1000 }
1001
1002 //------------------------------------------------------------------------
1003 // RightAdjust
1004 //------------------------------------------------------------------------
RightAdjust()1005 void TCollection_AsciiString::RightAdjust ()
1006 {
1007 Standard_Integer i ;
1008 for ( i = mylength-1 ; i >= 0 ; i--)
1009 if(!IsSpace(mystring[i]))
1010 break;
1011 if( i < mylength-1 )
1012 Remove(i+2,mylength-(i+2)+1);
1013 }
1014
1015 //------------------------------------------------------------------------
1016 // RightJustify
1017 //------------------------------------------------------------------------
RightJustify(const Standard_Integer Width,const Standard_Character Filler)1018 void TCollection_AsciiString::RightJustify(const Standard_Integer Width,
1019 const Standard_Character Filler)
1020 {
1021 Standard_Integer i ;
1022 Standard_Integer k ;
1023 if (Width > mylength) {
1024 mystring = Reallocate (mystring, Width + 1);
1025
1026 for ( i = mylength-1, k = Width-1 ; i >= 0 ; i--, k--)
1027 mystring[k] = mystring[i];
1028 for(; k >= 0 ; k--) mystring[k] = Filler;
1029 mylength = Width;
1030 mystring[mylength] = '\0';
1031 }
1032 else if (Width < 0) {
1033 throw Standard_NegativeValue();
1034 }
1035 }
1036
1037 // ----------------------------------------------------------------------------
1038 // Search
1039 // ----------------------------------------------------------------------------
Search(const Standard_CString what) const1040 Standard_Integer TCollection_AsciiString::Search
1041 (const Standard_CString what)const
1042 {
1043 Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 );
1044 if (size) {
1045 int k,j;
1046 int i = 0;
1047 while ( i < mylength-size+1 ) {
1048 k = i++;
1049 j = 0;
1050 while (j < size && mystring[k++] == what[j++])
1051 if (j == size) return i;
1052 }
1053 }
1054 return -1;
1055 }
1056
1057
1058 // ----------------------------------------------------------------------------
1059 // Search
1060 // ----------------------------------------------------------------------------
Search(const TCollection_AsciiString & what) const1061 Standard_Integer TCollection_AsciiString::Search
1062 (const TCollection_AsciiString& what) const
1063 {
1064 Standard_Integer size = what.mylength;
1065 Standard_CString swhat = what.mystring;
1066 if (size) {
1067 int k,j;
1068 int i = 0;
1069 while ( i < mylength-size+1 ) {
1070 k = i++;
1071 j = 0;
1072 while (j < size && mystring[k++] == swhat[j++])
1073 if (j == size) return i;
1074 }
1075 }
1076 return -1;
1077 }
1078
1079
1080 // ----------------------------------------------------------------------------
1081 // SearchFromEnd
1082 // ----------------------------------------------------------------------------
SearchFromEnd(const Standard_CString what) const1083 Standard_Integer TCollection_AsciiString::SearchFromEnd
1084 (const Standard_CString what)const
1085 {
1086 Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 );
1087 if (size) {
1088 int k,j;
1089 int i = mylength-1;
1090 while ( i >= size-1 ) {
1091 k = i--;
1092 j = size-1;
1093 while (j >= 0 && mystring[k--] == what[j--])
1094 if (j == -1) return i-size+3;
1095 }
1096 }
1097 return -1;
1098 }
1099
1100
1101 // ----------------------------------------------------------------------------
1102 // SearchFromEnd
1103 // ----------------------------------------------------------------------------
SearchFromEnd(const TCollection_AsciiString & what) const1104 Standard_Integer TCollection_AsciiString::SearchFromEnd
1105 (const TCollection_AsciiString& what)const
1106 {
1107 int size = what.mylength;
1108 if (size) {
1109 Standard_CString swhat = what.mystring;
1110 int k,j;
1111 int i = mylength-1;
1112 while ( i >= size-1 ) {
1113 k = i--;
1114 j = size-1;
1115 while (j >= 0 && mystring[k--] == swhat[j--])
1116 if (j == -1) return i-size+3;
1117 }
1118 }
1119 return -1;
1120 }
1121
1122 // ----------------------------------------------------------------------------
1123 // SetValue
1124 // ----------------------------------------------------------------------------
SetValue(const Standard_Integer theWhere,const Standard_Character theWhat)1125 void TCollection_AsciiString::SetValue (const Standard_Integer theWhere,
1126 const Standard_Character theWhat)
1127 {
1128 if (theWhere <= 0 || theWhere > mylength)
1129 {
1130 throw Standard_OutOfRange ("TCollection_AsciiString::SetValue(): out of range location");
1131 }
1132 else if (theWhat == '\0')
1133 {
1134 throw Standard_OutOfRange ("TCollection_AsciiString::SetValue(): NULL terminator is passed");
1135 }
1136 mystring[theWhere - 1] = theWhat;
1137 }
1138
1139 // ----------------------------------------------------------------------------
1140 // SetValue
1141 // ----------------------------------------------------------------------------
SetValue(const Standard_Integer where,const Standard_CString what)1142 void TCollection_AsciiString::SetValue(const Standard_Integer where,
1143 const Standard_CString what)
1144 {
1145 if (where > 0 && where <= mylength+1) {
1146 Standard_Integer size = Standard_Integer( what ? strlen( what ) : 0 );
1147 size += (where - 1);
1148 if (size >= mylength) {
1149 mystring = Reallocate (mystring, size + 1);
1150 mylength = size;
1151 }
1152 for (int i = where-1; i < size; i++)
1153 mystring[i] = what[i-(where-1)];
1154 mystring[mylength] = '\0';
1155 }
1156 else {
1157 throw Standard_OutOfRange("TCollection_AsciiString::SetValue : "
1158 "parameter where");
1159 }
1160 }
1161
1162 // ----------------------------------------------------------------------------
1163 // SetValue
1164 // ----------------------------------------------------------------------------
SetValue(const Standard_Integer where,const TCollection_AsciiString & what)1165 void TCollection_AsciiString::SetValue(const Standard_Integer where,
1166 const TCollection_AsciiString& what)
1167 {
1168 if (where > 0 && where <= mylength+1) {
1169 Standard_Integer size = what.mylength;
1170 Standard_CString swhat = what.mystring;
1171 size += (where - 1);
1172 if (size >= mylength) {
1173 mystring = Reallocate (mystring, size + 1);
1174 mylength = size;
1175 }
1176 for (int i = where-1; i < size; i++)
1177 mystring[i] = swhat[i-(where-1)];
1178 mystring[mylength] = '\0';
1179 }
1180 else {
1181 throw Standard_OutOfRange("TCollection_AsciiString::SetValue : "
1182 "parameter where");
1183 }
1184 }
1185
1186 // ----------------------------------------------------------------------------
1187 // Split
1188 // Private
1189 // ----------------------------------------------------------------------------
Split(const Standard_Integer where,TCollection_AsciiString & res)1190 void TCollection_AsciiString::Split(const Standard_Integer where,
1191 TCollection_AsciiString& res)
1192 {
1193 if (where >= 0 && where <= mylength) {
1194 res = &mystring[where] ;
1195 Trunc(where);
1196 return ;
1197 }
1198 throw Standard_OutOfRange("TCollection_AsciiString::Split index");
1199 return ;
1200 }
1201
1202 // ----------------------------------------------------------------------------
1203 // Split
1204 // ----------------------------------------------------------------------------
Split(const Standard_Integer where)1205 TCollection_AsciiString TCollection_AsciiString::Split
1206 (const Standard_Integer where)
1207 {
1208 if (where >= 0 && where <= mylength) {
1209 TCollection_AsciiString res( &mystring[where] , mylength - where );
1210 Trunc(where);
1211 return res;
1212 }
1213 throw Standard_OutOfRange("TCollection_AsciiString::Split index");
1214 }
1215
1216 // ----------------------------------------------------------------------------
1217 // SubString
1218 // Private
1219 // ----------------------------------------------------------------------------
SubString(const Standard_Integer FromIndex,const Standard_Integer ToIndex,TCollection_AsciiString & res) const1220 void TCollection_AsciiString::SubString(const Standard_Integer FromIndex,
1221 const Standard_Integer ToIndex,
1222 TCollection_AsciiString& res) const
1223 {
1224
1225 if (ToIndex > mylength || FromIndex <= 0 || FromIndex > ToIndex )
1226 {
1227 throw Standard_OutOfRange();
1228 }
1229
1230 Standard_Integer newlength = ToIndex-FromIndex+1;
1231 res.mystring =Reallocate (res.mystring, newlength + 1);
1232 memcpy (res.mystring, mystring + FromIndex - 1, newlength);
1233 res.mystring[newlength] = '\0';
1234 res.mylength = newlength;
1235 return ;
1236 }
1237
1238 // ----------------------------------------------------------------------------
1239 // Token
1240 // Private
1241 // ----------------------------------------------------------------------------
Token(const Standard_CString separators,const Standard_Integer whichone,TCollection_AsciiString & res) const1242 void TCollection_AsciiString::Token(const Standard_CString separators,
1243 const Standard_Integer whichone,
1244 TCollection_AsciiString& res)const
1245 {
1246 res = Token( separators , whichone ) ;
1247 }
1248
1249 // ----------------------------------------------------------------------------
1250 // Token
1251 // ----------------------------------------------------------------------------
Token(const Standard_CString separators,const Standard_Integer whichone) const1252 TCollection_AsciiString TCollection_AsciiString::Token
1253 (const Standard_CString separators,
1254 const Standard_Integer whichone) const
1255 {
1256 if (!separators)
1257 throw Standard_NullObject("TCollection_AsciiString::Token : "
1258 "parameter 'separators'");
1259
1260 Standard_Integer theOne ;
1261 Standard_Integer StringIndex = 0 ;
1262 Standard_Integer SeparatorIndex ;
1263 Standard_Integer BeginIndex=0 ;
1264 Standard_Integer EndIndex=0 ;
1265
1266 // std::cout << "'" << mystring << "'" << std::endl ;
1267 for ( theOne = 0 ; theOne < whichone ; theOne++ ) {
1268 BeginIndex = 0 ;
1269 EndIndex = 0 ;
1270 // std::cout << "theOne " << theOne << std::endl ;
1271 if ( StringIndex == mylength )
1272 break ;
1273 for (; StringIndex < mylength && EndIndex == 0 ; StringIndex++ ) {
1274 SeparatorIndex = 0 ;
1275 // std::cout << "StringIndex " << StringIndex << std::endl ;
1276 while ( separators [ SeparatorIndex ] ) {
1277 if ( mystring [ StringIndex ] == separators [ SeparatorIndex ] ) {
1278 break ;
1279 }
1280 SeparatorIndex += 1 ;
1281 }
1282 if ( separators [ SeparatorIndex ] != '\0' ) { // We have a Separator
1283 if ( BeginIndex && EndIndex == 0 ) {
1284 EndIndex = StringIndex ;
1285 // std::cout << "EndIndex " << EndIndex << " '" << SubString( BeginIndex , EndIndex ).ToCString() << "'" << std::endl ;
1286 break ;
1287 }
1288 }
1289 else if ( BeginIndex == 0 ) { // We have not a Separator
1290 BeginIndex = StringIndex + 1 ;
1291 // std::cout << "BeginIndex " << BeginIndex << std::endl ;
1292 }
1293 }
1294 // std::cout << "BeginIndex " << BeginIndex << " EndIndex " << EndIndex << std::endl ;
1295 }
1296 if ( BeginIndex == 0 )
1297 return TCollection_AsciiString("",0) ;
1298 if ( EndIndex == 0 )
1299 EndIndex = mylength ;
1300 // std::cout << "'" << SubString( BeginIndex , EndIndex ).ToCString() << "'" << std::endl ;
1301 return TCollection_AsciiString( &mystring [ BeginIndex - 1 ] ,
1302 EndIndex - BeginIndex + 1 ) ;
1303 }
1304
1305 // ----------------------------------------------------------------------------
1306 // Trunc
1307 // ----------------------------------------------------------------------------
Trunc(const Standard_Integer ahowmany)1308 void TCollection_AsciiString::Trunc(const Standard_Integer ahowmany)
1309 {
1310 if (ahowmany < 0 || ahowmany > mylength)
1311 throw Standard_OutOfRange("TCollection_AsciiString::Trunc : "
1312 "parameter 'ahowmany'");
1313 mylength = ahowmany;
1314 mystring[mylength] = '\0';
1315 }
1316
1317 // ----------------------------------------------------------------------------
1318 // UpperCase
1319 // ----------------------------------------------------------------------------
UpperCase()1320 void TCollection_AsciiString::UpperCase()
1321 {
1322 for (int i=0; i < mylength; i++)
1323 mystring[i] = ::UpperCase(mystring[i]);
1324 }
1325
1326 //------------------------------------------------------------------------
1327 // UsefullLength
1328 //------------------------------------------------------------------------
UsefullLength() const1329 Standard_Integer TCollection_AsciiString::UsefullLength () const
1330 {
1331 Standard_Integer i ;
1332 for ( i = mylength -1 ; i >= 0 ; i--)
1333 if (IsGraphic(mystring[i])) break;
1334 return i+1;
1335 }
1336
1337 // ----------------------------------------------------------------------------
1338 // Value
1339 // ----------------------------------------------------------------------------
Value(const Standard_Integer where) const1340 Standard_Character TCollection_AsciiString::Value
1341 (const Standard_Integer where)const
1342 {
1343 if (where > 0 && where <= mylength) {
1344 return mystring[where-1];
1345 }
1346 throw Standard_OutOfRange("TCollection_AsciiString::Value : parameter where");
1347 }
1348