Integration of OCCT 6.5.0 from SVN
[occt.git] / src / TCollection / TCollection_HAsciiString.cxx
CommitLineData
7fd59977 1
2//Copyright: Matra Datavision 1992,1993
3//Created By M. MERCIEN Dec,15 1992
4//
5
6#define OptJr 1
7
8#include <TCollection_HAsciiString.ixx>
9#include <TCollection_HExtendedString.hxx>
10#include <Standard_String.hxx>
11
12// ----------------------------------------------------------------------------
13// Create
14// ----------------------------------------------------------------------------
15TCollection_HAsciiString::TCollection_HAsciiString():myString(){}
16
17
18// ----------------------------------------------------------------------------
19// Create
20// ----------------------------------------------------------------------------
21TCollection_HAsciiString::TCollection_HAsciiString
22 (const Standard_CString message):myString(message)
23{}
24
25// ----------------------------------------------------------------------------
26// Create
27// ----------------------------------------------------------------------------
28TCollection_HAsciiString::TCollection_HAsciiString
29 (const TCollection_AsciiString& astring):myString(astring)
30{}
31
32// ----------------------------------------------------------------------------
33// Create
34// ----------------------------------------------------------------------------
35TCollection_HAsciiString::TCollection_HAsciiString
36 (const Standard_Character aChar):myString(aChar)
37{}
38
39// ----------------------------------------------------------------------------
40// Create
41// ----------------------------------------------------------------------------
42TCollection_HAsciiString::TCollection_HAsciiString
43 (const Standard_Integer length,const Standard_Character filler ):myString(length,filler)
44{}
45
46// ----------------------------------------------------------------------------
47// Create
48// ----------------------------------------------------------------------------
49TCollection_HAsciiString::TCollection_HAsciiString
50 (const Standard_Integer aValue):myString(aValue)
51{}
52
53// ----------------------------------------------------------------------------
54// Create
55// ----------------------------------------------------------------------------
56TCollection_HAsciiString::TCollection_HAsciiString
57 (const Standard_Real aValue):myString(aValue)
58{}
59
60// ----------------------------------------------------------------------------
61// Create
62// ----------------------------------------------------------------------------
63TCollection_HAsciiString::TCollection_HAsciiString
64 (const Handle(TCollection_HAsciiString)& astring):myString(astring->String())
65{
66}
67
68// ----------------------------------------------------------------------------
69// Create
70// ----------------------------------------------------------------------------
71TCollection_HAsciiString::TCollection_HAsciiString
72 (const Handle(TCollection_HExtendedString)& astring,
73 const Standard_Character replaceNonAscii)
74: myString(astring->String(), replaceNonAscii)
75{
76}
77
78
79// ---------------------------------------------------------------------------
80// Capitalize
81// ----------------------------------------------------------------------------
82void TCollection_HAsciiString::Capitalize()
83{
84 myString.Capitalize();
85}
86
87// ---------------------------------------------------------------------------
88// Cat
89// ----------------------------------------------------------------------------
90Handle(TCollection_HAsciiString)
91 TCollection_HAsciiString::Cat(const Standard_CString other) const
92{
93 return new TCollection_HAsciiString(myString.Cat(other));
94}
95
96// ---------------------------------------------------------------------------
97// Cat
98// ----------------------------------------------------------------------------
99Handle(TCollection_HAsciiString)
100 TCollection_HAsciiString::Cat(const Handle(TCollection_HAsciiString)& other)
101const
102{
103 return new TCollection_HAsciiString(myString.Cat(other->String() ) );
104}
105
106// ---------------------------------------------------------------------------
107// Center
108// ----------------------------------------------------------------------------
109void TCollection_HAsciiString::Center
110 (const Standard_Integer Width ,
111 const Standard_Character Filler)
112{
113 if (Width < 0) Standard_NegativeValue::Raise();
114 myString.Center(Width,Filler);
115}
116
117// ----------------------------------------------------------------------------
118// ChangeAll
119// ----------------------------------------------------------------------------
120void TCollection_HAsciiString::ChangeAll
121 (const Standard_Character aChar,
122 const Standard_Character NewChar,
123 const Standard_Boolean CaseSensitive)
124{
125 myString.ChangeAll(aChar,NewChar,CaseSensitive);
126}
127
128// ----------------------------------------------------------------------------
129// Clear
130// ----------------------------------------------------------------------------
131void TCollection_HAsciiString::Clear()
132{
133 myString.Clear();
134}
135
136// ----------------------------------------------------------------------------
137// FirstLocationInSet
138// ----------------------------------------------------------------------------
139Standard_Integer TCollection_HAsciiString::FirstLocationInSet
140 (const Handle(TCollection_HAsciiString)& Set,
141 const Standard_Integer FromIndex,
142 const Standard_Integer ToIndex) const
143{
144 if (Length() == 0 || Set->Length() == 0) return 0;
145 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
146 Standard_OutOfRange::Raise();
147 return (myString.FirstLocationInSet(Set->String(),FromIndex,ToIndex));
148}
149
150// ----------------------------------------------------------------------------
151// FirstLocationNotInSet
152// ----------------------------------------------------------------------------
153Standard_Integer TCollection_HAsciiString::FirstLocationNotInSet
154 (const Handle(TCollection_HAsciiString)& Set,
155 const Standard_Integer FromIndex,
156 const Standard_Integer ToIndex) const
157{
158 if (Length() == 0 || Set->Length() == 0) return 0;
159 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
160 Standard_OutOfRange::Raise();
161 return (myString.FirstLocationNotInSet(Set->String(),FromIndex,ToIndex));
162}
163
164// ----------------------------------------------------------------------------
165// Insert a Standard_Character before 'where'th Standard_Character
166// ----------------------------------------------------------------------------
167void TCollection_HAsciiString::Insert(const Standard_Integer where,
168 const Standard_Character what)
169{
170 myString.Insert(where,what);
171}
172
173// ----------------------------------------------------------------------------
174// Insert
175// ----------------------------------------------------------------------------
176void TCollection_HAsciiString::Insert(const Standard_Integer where,
177 const Standard_CString what)
178{
179 myString.Insert(where,what);
180}
181
182// ----------------------------------------------------------------------------
183// Insert
184// ----------------------------------------------------------------------------
185void TCollection_HAsciiString::Insert(const Standard_Integer where,
186 const Handle(TCollection_HAsciiString)& what)
187{
188 myString.Insert(where,what->String());
189}
190
191//------------------------------------------------------------------------
192// InsertAfter
193//------------------------------------------------------------------------
194void TCollection_HAsciiString::InsertAfter
195 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
196{
197 Standard_Integer size1 = Length();
198#ifndef NOBOUNDCHECK
199 if (Index < 0 || Index > size1) Standard_OutOfRange::Raise();
200#endif
201 myString.InsertAfter(Index,S->String());
202}
203
204//------------------------------------------------------------------------
205// InsertBefore
206//------------------------------------------------------------------------
207void TCollection_HAsciiString::InsertBefore
208 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
209{
210 Standard_Integer size1 = Length();
211#ifndef NOBOUNDCHECK
212 if (Index < 1 || Index > size1) Standard_OutOfRange::Raise();
213#endif
214 myString.InsertBefore(Index,S->String());
215}
216
217// ----------------------------------------------------------------------------
218// IsEmpty
219// ----------------------------------------------------------------------------
220Standard_Boolean TCollection_HAsciiString::IsEmpty() const
221{
222 return (myString.Length() == 0);
223}
224
225// ----------------------------------------------------------------------------
226// IsLess
227// ----------------------------------------------------------------------------
228Standard_Boolean
229TCollection_HAsciiString::IsLess(const Handle(TCollection_HAsciiString)& other) const
230{
231 return myString.IsLess(other->String());
232}
233
234// ----------------------------------------------------------------------------
235// IsGreater
236// ----------------------------------------------------------------------------
237Standard_Boolean
238TCollection_HAsciiString::IsGreater(const Handle(TCollection_HAsciiString)& other) const
239{
240 return myString.IsGreater(other->String());
241}
242
243// ----------------------------------------------------------------------------
244// IntegerValue
245// ----------------------------------------------------------------------------
246Standard_Integer TCollection_HAsciiString::IntegerValue() const
247{
248 return myString.IntegerValue();
249}
250
251// ----------------------------------------------------------------------------
252// IsIntegerValue
253// ----------------------------------------------------------------------------
254Standard_Boolean TCollection_HAsciiString::IsIntegerValue() const
255{
256 return myString.IsIntegerValue();
257}
258
259
260// ----------------------------------------------------------------------------
261// IsRealvalue
262// ----------------------------------------------------------------------------
263Standard_Boolean TCollection_HAsciiString::IsRealValue() const
264{
265 return myString.IsRealValue();
266}
267
268// ----------------------------------------------------------------------------
269// IsAscii
270// ----------------------------------------------------------------------------
271Standard_Boolean TCollection_HAsciiString::IsAscii() const
272{
273 return myString.IsAscii();
274}
275
276// ----------------------------------------------------------------------------
277// IsDifferent
278// ----------------------------------------------------------------------------
279Standard_Boolean TCollection_HAsciiString::IsDifferent
280 (const Handle(TCollection_HAsciiString)& S) const
281{
282
283 if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsDifferent");
284#if OptJr
285 if ( myString.Length() == S->Length() ) {
286 Standard_Boolean KEqual ;
287 ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() ,
288 myString.mylength , KEqual ) ;
289 return !KEqual ;
290 }
291 else
292 return Standard_True ;
293#else
294 return ( strcmp(myString.ToCString(), S->ToCString()) );
295#endif
296}
297
298// ----------------------------------------------------------------------------
299// IsSameString
300// ----------------------------------------------------------------------------
301Standard_Boolean TCollection_HAsciiString::IsSameString
302 (const Handle(TCollection_HAsciiString)& S) const
303{
304
305 if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString");
306#if OptJr
307 if ( myString.Length() == S->Length() ) {
308 Standard_Boolean KEqual ;
309 ASCIISTRINGEQUAL( myString.ToCString() , S->ToCString() ,
310 myString.mylength , KEqual ) ;
311 return KEqual ;
312 }
313 else
314 return Standard_False ;
315#else
316 return ( !strcmp(myString.ToCString(), S->ToCString()) );
317#endif
318}
319
320// ----------------------------------------------------------------------------
321// IsSameString
322// ----------------------------------------------------------------------------
323Standard_Boolean TCollection_HAsciiString::IsSameString
324 (const Handle(TCollection_HAsciiString)& S ,
325 const Standard_Boolean CaseSensitive) const
326{
327// Handle(TCollection_HAsciiString) H1,H2;
328// H1 = UpperCase(This);
329// H2 = UpperCase(S);
330// return ( H1 == H2));
331
332 if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString");
333
334 Standard_Integer size1 = Length();
335 if ( size1 != S->Length() ) return Standard_False;
336#if OptJr
337 if ( CaseSensitive ) {
338 Standard_Boolean KEqual ;
339 ASCIISTRINGEQUAL( myString.ToCString() , S->String().ToCString() ,
340 size1 , KEqual ) ;
341 return KEqual ;
342 }
343 else {
344 for ( Standard_Integer i = 1 ; i <= size1; i++) {
345 if ( toupper( Value(i) ) != toupper( S->Value(i) ) )
346 return Standard_False;
347 }
348 return Standard_True ;
349 }
350
351#else
352// Example of bad sequence of test : CaseSensitive does not change in the loop
353 Standard_Character C1,C2;
354 for( Standard_Integer i = 1 ; i <= size1; i++) {
355 if(CaseSensitive){
356 if (Value(i) != S->Value(i)) return Standard_False;
357 }
358 else {
359 C1 = Value(i);
360 C2 = S->Value(i);
361 if(toupper(C1) != toupper(C2)) return Standard_False;
362 }
363 }
364 return Standard_True;
365#endif
366}
367
368//------------------------------------------------------------------------
369// LeftAdjust
370//------------------------------------------------------------------------
371void TCollection_HAsciiString::LeftAdjust ()
372{
373 myString.LeftAdjust();
374}
375
376//------------------------------------------------------------------------
377// LeftJustify
378//------------------------------------------------------------------------
379void TCollection_HAsciiString::LeftJustify
380 (const Standard_Integer Width, const Standard_Character Filler)
381{
382 if (Width < 0) Standard_NegativeValue::Raise();
383 myString.LeftJustify(Width,Filler);
384}
385
386//------------------------------------------------------------------------
387// Location
388//------------------------------------------------------------------------
389Standard_Integer TCollection_HAsciiString::Location
390 (const Standard_Integer N, const Standard_Character C,
391 const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
392{
393 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
394 Standard_OutOfRange::Raise();
395 return myString.Location(N,C,FromIndex,ToIndex);
396}
397
398//------------------------------------------------------------------------
399// Location
400//------------------------------------------------------------------------
401Standard_Integer TCollection_HAsciiString::Location
402 (const Handle(TCollection_HAsciiString)& S, const Standard_Integer FromIndex,
403 const Standard_Integer ToIndex) const
404{
405 if (Length() == 0 || S->Length() == 0) return 0;
406 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
407 Standard_OutOfRange::Raise();
408 return myString.Location(S->String(),FromIndex,ToIndex);
409}
410
411// ----------------------------------------------------------------------------
412// LowerCase
413// ----------------------------------------------------------------------------
414void TCollection_HAsciiString::LowerCase()
415{
416 myString.LowerCase();
417}
418
419//------------------------------------------------------------------------
420// Prepend
421//------------------------------------------------------------------------
422void TCollection_HAsciiString::Prepend
423 (const Handle(TCollection_HAsciiString)& S)
424{
425 myString.Prepend(S->String());
426}
427
428//---------------------------------------------------------------------
429// Print
430//---------------------------------------------------------------------
431void TCollection_HAsciiString::Print(Standard_OStream& S) const
432{
433 myString.Print(S);
434}
435
436// ----------------------------------------------------------------------------
437// RealValue
438// ----------------------------------------------------------------------------
439Standard_Real TCollection_HAsciiString::RealValue() const
440{
441 return myString.RealValue();
442}
443
444// ----------------------------------------------------------------------------
445// RemoveAll
446// ----------------------------------------------------------------------------
447void TCollection_HAsciiString::RemoveAll
448 (const Standard_Character what,
449 const Standard_Boolean CaseSensitive)
450{
451 myString.RemoveAll(what,CaseSensitive);
452}
453
454// ----------------------------------------------------------------------------
455// RemoveAll
456// ----------------------------------------------------------------------------
457void TCollection_HAsciiString::RemoveAll(const Standard_Character what)
458{
459 myString.RemoveAll(what);
460}
461
462// ----------------------------------------------------------------------------
463// Remove
464// ----------------------------------------------------------------------------
465void TCollection_HAsciiString::Remove (const Standard_Integer where,
466 const Standard_Integer ahowmany)
467{
468 myString.Remove(where,ahowmany);
469}
470
471//------------------------------------------------------------------------
472// RightAdjust
473//------------------------------------------------------------------------
474void TCollection_HAsciiString::RightAdjust ()
475{
476 myString.RightAdjust();
477}
478
479//------------------------------------------------------------------------
480// RightJustify
481//------------------------------------------------------------------------
482void TCollection_HAsciiString::RightJustify
483 (const Standard_Integer Width, const Standard_Character Filler)
484{
485 if (Width < 0) Standard_NegativeValue::Raise();
486 myString.RightJustify(Width,Filler);
487}
488
489// ----------------------------------------------------------------------------
490// Search
491// ----------------------------------------------------------------------------
492Standard_Integer TCollection_HAsciiString::Search(const Standard_CString what)const
493{
494 return myString.Search(what);
495}
496
497// ----------------------------------------------------------------------------
498// Search
499// ----------------------------------------------------------------------------
500Standard_Integer TCollection_HAsciiString::Search
501 (const Handle(TCollection_HAsciiString)& what) const
502{
503 return myString.Search(what->String());
504}
505
506// ----------------------------------------------------------------------------
507// SearchFromEnd
508// ----------------------------------------------------------------------------
509Standard_Integer TCollection_HAsciiString::SearchFromEnd(const Standard_CString what)const
510{
511 return myString.SearchFromEnd(what);
512}
513
514// ----------------------------------------------------------------------------
515// SearchFromEnd
516// ----------------------------------------------------------------------------
517Standard_Integer TCollection_HAsciiString::SearchFromEnd
518 (const Handle(TCollection_HAsciiString)& what) const
519{
520 return myString.SearchFromEnd(what->String());
521}
522
523// ----------------------------------------------------------------------------
524// SetValue
525// ----------------------------------------------------------------------------
526void TCollection_HAsciiString::SetValue(const Standard_Integer where,
527 const Standard_Character what)
528{
529 myString.SetValue(where,what);
530}
531
532// ----------------------------------------------------------------------------
533// SetValue
534// ----------------------------------------------------------------------------
535void TCollection_HAsciiString::SetValue(const Standard_Integer where,const Standard_CString what)
536{
537 myString.SetValue(where,what);
538}
539
540// ----------------------------------------------------------------------------
541// SetValue
542// ---------------------------------------------------------------------------
543void TCollection_HAsciiString::SetValue(const Standard_Integer where,
544 const Handle(TCollection_HAsciiString)& what)
545{
546 myString.SetValue(where, what->String());
547}
548
549// ----------------------------------------------------------------------------
550// Split
551// ----------------------------------------------------------------------------
552Handle(TCollection_HAsciiString)
553 TCollection_HAsciiString::Split(const Standard_Integer where)
554{
555 return new TCollection_HAsciiString(myString.Split(where));
556}
557
558// ----------------------------------------------------------------------------
559// SubString
560// ----------------------------------------------------------------------------
561Handle(TCollection_HAsciiString)
562 TCollection_HAsciiString::SubString(const Standard_Integer FromIndex,
563 const Standard_Integer ToIndex) const
564{
565 return new TCollection_HAsciiString(myString.SubString(FromIndex,ToIndex));
566}
567
568
569// ----------------------------------------------------------------------------
570// Token
571// ----------------------------------------------------------------------------
572Handle(TCollection_HAsciiString) TCollection_HAsciiString::Token
573 (const Standard_CString separators,const Standard_Integer whichone) const
574{
575 return new TCollection_HAsciiString(myString.Token(separators,whichone));
576}
577
578// ----------------------------------------------------------------------------
579// Trunc
580// ----------------------------------------------------------------------------
581void TCollection_HAsciiString::Trunc(const Standard_Integer ahowmany)
582{
583 myString.Trunc(ahowmany);
584}
585
586// ----------------------------------------------------------------------------
587// UpperCase
588// ----------------------------------------------------------------------------
589void TCollection_HAsciiString::UpperCase()
590{
591 myString.UpperCase();
592}
593
594// ----------------------------------------------------------------------------
595// UsefullLength
596// ----------------------------------------------------------------------------
597Standard_Integer TCollection_HAsciiString::UsefullLength() const
598{
599 return myString.UsefullLength();
600}
601
602// ----------------------------------------------------------------------------
603// Value
604// ----------------------------------------------------------------------------
605Standard_Character TCollection_HAsciiString::Value(const Standard_Integer where) const
606{
607 return myString.Value(where);
608}
609
610// ----------------------------------------------------------------------------
611// ShallowCopy
612// ----------------------------------------------------------------------------
613Handle(TCollection_HAsciiString) TCollection_HAsciiString::ShallowCopy() const
614{
615// Handle(TCollection_HAsciiString) thecopy = new TCollection_HAsciiString;
616// for (Standard_Integer i = 1 ; i <= Length() ; i++)
617// thecopy->Insert(i,Value(i));
618// return thecopy;
619 return new TCollection_HAsciiString(*this);
620}
621
622//---------------------------------------------------------------------
623// ShallowDump
624//---------------------------------------------------------------------
625void TCollection_HAsciiString::ShallowDump(Standard_OStream& S) const
626{
627 S << "begin class HAsciiString "<<endl;
628 myString.Print(S);
629}
630
631// ----------------------------------------------------------------------------
632// IsSameState
633// ----------------------------------------------------------------------------
634Standard_Boolean TCollection_HAsciiString::IsSameState
635 (const Handle(TCollection_HAsciiString)& other) const
636 {
637
638#if OptJr
639 if ( myString.Length() == other->Length() ) {
640 Standard_Boolean KEqual ;
641 ASCIISTRINGEQUAL( myString.ToCString() , other->ToCString() ,
642 myString.mylength , KEqual ) ;
643 return KEqual ;
644 }
645 else
646 return Standard_False ;
647#else
648 return ( !strcmp(myString.mystring , other->ToCString() ));
649#endif
650 }
651