1 // Copyright (c) 1992-1999 Matra Datavision
2 // Copyright (c) 1999-2014 OPEN CASCADE SAS
4 // This file is part of Open CASCADE Technology software library.
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.
12 // Alternatively, this file may be used under the terms of Open CASCADE
13 // commercial license or contractual agreement.
16 #include <Standard_NegativeValue.hxx>
17 #include <Standard_NullObject.hxx>
18 #include <Standard_NumericError.hxx>
19 #include <Standard_OutOfRange.hxx>
20 #include <Standard_Type.hxx>
21 #include <TCollection_AsciiString.hxx>
22 #include <TCollection_HAsciiString.hxx>
23 #include <TCollection_HExtendedString.hxx>
25 IMPLEMENT_STANDARD_RTTIEXT(TCollection_HAsciiString,Standard_Transient)
27 // ----------------------------------------------------------------------------
29 // ----------------------------------------------------------------------------
30 TCollection_HAsciiString::TCollection_HAsciiString():myString(){}
33 // ----------------------------------------------------------------------------
35 // ----------------------------------------------------------------------------
36 TCollection_HAsciiString::TCollection_HAsciiString
37 (const Standard_CString message):myString(message)
40 // ----------------------------------------------------------------------------
42 // ----------------------------------------------------------------------------
43 TCollection_HAsciiString::TCollection_HAsciiString
44 (const TCollection_AsciiString& astring):myString(astring)
47 // ----------------------------------------------------------------------------
49 // ----------------------------------------------------------------------------
50 TCollection_HAsciiString::TCollection_HAsciiString
51 (const Standard_Character aChar):myString(aChar)
54 // ----------------------------------------------------------------------------
56 // ----------------------------------------------------------------------------
57 TCollection_HAsciiString::TCollection_HAsciiString
58 (const Standard_Integer length,const Standard_Character filler ):myString(length,filler)
61 // ----------------------------------------------------------------------------
63 // ----------------------------------------------------------------------------
64 TCollection_HAsciiString::TCollection_HAsciiString
65 (const Standard_Integer aValue):myString(aValue)
68 // ----------------------------------------------------------------------------
70 // ----------------------------------------------------------------------------
71 TCollection_HAsciiString::TCollection_HAsciiString
72 (const Standard_Real aValue):myString(aValue)
75 // ----------------------------------------------------------------------------
77 // ----------------------------------------------------------------------------
78 TCollection_HAsciiString::TCollection_HAsciiString
79 (const Handle(TCollection_HAsciiString)& astring):myString(astring->String())
83 // ----------------------------------------------------------------------------
85 // ----------------------------------------------------------------------------
86 TCollection_HAsciiString::TCollection_HAsciiString
87 (const Handle(TCollection_HExtendedString)& astring,
88 const Standard_Character replaceNonAscii)
89 : myString(astring->String(), replaceNonAscii)
94 // ---------------------------------------------------------------------------
96 // ----------------------------------------------------------------------------
97 void TCollection_HAsciiString::Capitalize()
99 myString.Capitalize();
102 // ---------------------------------------------------------------------------
104 // ----------------------------------------------------------------------------
105 Handle(TCollection_HAsciiString)
106 TCollection_HAsciiString::Cat(const Standard_CString other) const
108 return new TCollection_HAsciiString(myString.Cat(other));
111 // ---------------------------------------------------------------------------
113 // ----------------------------------------------------------------------------
114 Handle(TCollection_HAsciiString)
115 TCollection_HAsciiString::Cat(const Handle(TCollection_HAsciiString)& other)
118 return new TCollection_HAsciiString(myString.Cat(other->String() ) );
121 // ---------------------------------------------------------------------------
123 // ----------------------------------------------------------------------------
124 void TCollection_HAsciiString::Center
125 (const Standard_Integer Width ,
126 const Standard_Character Filler)
128 if (Width < 0) throw Standard_NegativeValue();
129 myString.Center(Width,Filler);
132 // ----------------------------------------------------------------------------
134 // ----------------------------------------------------------------------------
135 void TCollection_HAsciiString::ChangeAll
136 (const Standard_Character aChar,
137 const Standard_Character NewChar,
138 const Standard_Boolean CaseSensitive)
140 myString.ChangeAll(aChar,NewChar,CaseSensitive);
143 // ----------------------------------------------------------------------------
145 // ----------------------------------------------------------------------------
146 void TCollection_HAsciiString::Clear()
151 // ----------------------------------------------------------------------------
152 // FirstLocationInSet
153 // ----------------------------------------------------------------------------
154 Standard_Integer TCollection_HAsciiString::FirstLocationInSet
155 (const Handle(TCollection_HAsciiString)& Set,
156 const Standard_Integer FromIndex,
157 const Standard_Integer ToIndex) const
159 if (Length() == 0 || Set->Length() == 0) return 0;
160 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
161 throw Standard_OutOfRange();
162 return (myString.FirstLocationInSet(Set->String(),FromIndex,ToIndex));
165 // ----------------------------------------------------------------------------
166 // FirstLocationNotInSet
167 // ----------------------------------------------------------------------------
168 Standard_Integer TCollection_HAsciiString::FirstLocationNotInSet
169 (const Handle(TCollection_HAsciiString)& Set,
170 const Standard_Integer FromIndex,
171 const Standard_Integer ToIndex) const
173 if (Length() == 0 || Set->Length() == 0) return 0;
174 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
175 throw Standard_OutOfRange();
176 return (myString.FirstLocationNotInSet(Set->String(),FromIndex,ToIndex));
179 // ----------------------------------------------------------------------------
180 // Insert a Standard_Character before 'where'th Standard_Character
181 // ----------------------------------------------------------------------------
182 void TCollection_HAsciiString::Insert(const Standard_Integer where,
183 const Standard_Character what)
185 myString.Insert(where,what);
188 // ----------------------------------------------------------------------------
190 // ----------------------------------------------------------------------------
191 void TCollection_HAsciiString::Insert(const Standard_Integer where,
192 const Standard_CString what)
194 myString.Insert(where,what);
197 // ----------------------------------------------------------------------------
199 // ----------------------------------------------------------------------------
200 void TCollection_HAsciiString::Insert(const Standard_Integer where,
201 const Handle(TCollection_HAsciiString)& what)
203 myString.Insert(where,what->String());
206 //------------------------------------------------------------------------
208 //------------------------------------------------------------------------
209 void TCollection_HAsciiString::InsertAfter
210 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
212 Standard_Integer size1 = Length();
214 if (Index < 0 || Index > size1) throw Standard_OutOfRange();
216 myString.InsertAfter(Index,S->String());
219 //------------------------------------------------------------------------
221 //------------------------------------------------------------------------
222 void TCollection_HAsciiString::InsertBefore
223 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
225 Standard_Integer size1 = Length();
227 if (Index < 1 || Index > size1) throw Standard_OutOfRange();
229 myString.InsertBefore(Index,S->String());
232 // ----------------------------------------------------------------------------
234 // ----------------------------------------------------------------------------
235 Standard_Boolean TCollection_HAsciiString::IsEmpty() const
237 return (myString.Length() == 0);
240 // ----------------------------------------------------------------------------
242 // ----------------------------------------------------------------------------
244 TCollection_HAsciiString::IsLess(const Handle(TCollection_HAsciiString)& other) const
246 return myString.IsLess(other->String());
249 // ----------------------------------------------------------------------------
251 // ----------------------------------------------------------------------------
253 TCollection_HAsciiString::IsGreater(const Handle(TCollection_HAsciiString)& other) const
255 return myString.IsGreater(other->String());
258 // ----------------------------------------------------------------------------
260 // ----------------------------------------------------------------------------
261 Standard_Integer TCollection_HAsciiString::IntegerValue() const
263 return myString.IntegerValue();
266 // ----------------------------------------------------------------------------
268 // ----------------------------------------------------------------------------
269 Standard_Boolean TCollection_HAsciiString::IsIntegerValue() const
271 return myString.IsIntegerValue();
275 // ----------------------------------------------------------------------------
277 // ----------------------------------------------------------------------------
278 Standard_Boolean TCollection_HAsciiString::IsRealValue() const
280 return myString.IsRealValue();
283 // ----------------------------------------------------------------------------
285 // ----------------------------------------------------------------------------
286 Standard_Boolean TCollection_HAsciiString::IsAscii() const
288 return myString.IsAscii();
291 // ----------------------------------------------------------------------------
293 // ----------------------------------------------------------------------------
294 Standard_Boolean TCollection_HAsciiString::IsDifferent
295 (const Handle(TCollection_HAsciiString)& S) const
297 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsDifferent");
298 if(S->Length() != myString.Length() ) return Standard_True;
299 return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) != 0 );
302 // ----------------------------------------------------------------------------
304 // ----------------------------------------------------------------------------
305 Standard_Boolean TCollection_HAsciiString::IsSameString
306 (const Handle(TCollection_HAsciiString)& S) const
308 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsSameString");
309 if ( myString.Length() == S->Length() )
310 return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) == 0 );
312 return Standard_False ;
315 // ----------------------------------------------------------------------------
317 // ----------------------------------------------------------------------------
318 Standard_Boolean TCollection_HAsciiString::IsSameString
319 (const Handle(TCollection_HAsciiString)& S ,
320 const Standard_Boolean CaseSensitive) const
322 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsSameString");
323 return TCollection_AsciiString::IsSameString (myString, S->myString, CaseSensitive);
326 //------------------------------------------------------------------------
328 //------------------------------------------------------------------------
329 void TCollection_HAsciiString::LeftAdjust ()
331 myString.LeftAdjust();
334 //------------------------------------------------------------------------
336 //------------------------------------------------------------------------
337 void TCollection_HAsciiString::LeftJustify
338 (const Standard_Integer Width, const Standard_Character Filler)
340 if (Width < 0) throw Standard_NegativeValue();
341 myString.LeftJustify(Width,Filler);
344 //------------------------------------------------------------------------
346 //------------------------------------------------------------------------
347 Standard_Integer TCollection_HAsciiString::Location
348 (const Standard_Integer N, const Standard_Character C,
349 const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
351 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
352 throw Standard_OutOfRange();
353 return myString.Location(N,C,FromIndex,ToIndex);
356 //------------------------------------------------------------------------
358 //------------------------------------------------------------------------
359 Standard_Integer TCollection_HAsciiString::Location
360 (const Handle(TCollection_HAsciiString)& S, const Standard_Integer FromIndex,
361 const Standard_Integer ToIndex) const
363 if (Length() == 0 || S->Length() == 0) return 0;
364 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
365 throw Standard_OutOfRange();
366 return myString.Location(S->String(),FromIndex,ToIndex);
369 // ----------------------------------------------------------------------------
371 // ----------------------------------------------------------------------------
372 void TCollection_HAsciiString::LowerCase()
374 myString.LowerCase();
377 //------------------------------------------------------------------------
379 //------------------------------------------------------------------------
380 void TCollection_HAsciiString::Prepend
381 (const Handle(TCollection_HAsciiString)& S)
383 myString.Prepend(S->String());
386 //---------------------------------------------------------------------
388 //---------------------------------------------------------------------
389 void TCollection_HAsciiString::Print(Standard_OStream& S) const
394 // ----------------------------------------------------------------------------
396 // ----------------------------------------------------------------------------
397 Standard_Real TCollection_HAsciiString::RealValue() const
399 return myString.RealValue();
402 // ----------------------------------------------------------------------------
404 // ----------------------------------------------------------------------------
405 void TCollection_HAsciiString::RemoveAll
406 (const Standard_Character what,
407 const Standard_Boolean CaseSensitive)
409 myString.RemoveAll(what,CaseSensitive);
412 // ----------------------------------------------------------------------------
414 // ----------------------------------------------------------------------------
415 void TCollection_HAsciiString::RemoveAll(const Standard_Character what)
417 myString.RemoveAll(what);
420 // ----------------------------------------------------------------------------
422 // ----------------------------------------------------------------------------
423 void TCollection_HAsciiString::Remove (const Standard_Integer where,
424 const Standard_Integer ahowmany)
426 myString.Remove(where,ahowmany);
429 //------------------------------------------------------------------------
431 //------------------------------------------------------------------------
432 void TCollection_HAsciiString::RightAdjust ()
434 myString.RightAdjust();
437 //------------------------------------------------------------------------
439 //------------------------------------------------------------------------
440 void TCollection_HAsciiString::RightJustify
441 (const Standard_Integer Width, const Standard_Character Filler)
443 if (Width < 0) throw Standard_NegativeValue();
444 myString.RightJustify(Width,Filler);
447 // ----------------------------------------------------------------------------
449 // ----------------------------------------------------------------------------
450 Standard_Integer TCollection_HAsciiString::Search(const Standard_CString what)const
452 return myString.Search(what);
455 // ----------------------------------------------------------------------------
457 // ----------------------------------------------------------------------------
458 Standard_Integer TCollection_HAsciiString::Search
459 (const Handle(TCollection_HAsciiString)& what) const
461 return myString.Search(what->String());
464 // ----------------------------------------------------------------------------
466 // ----------------------------------------------------------------------------
467 Standard_Integer TCollection_HAsciiString::SearchFromEnd(const Standard_CString what)const
469 return myString.SearchFromEnd(what);
472 // ----------------------------------------------------------------------------
474 // ----------------------------------------------------------------------------
475 Standard_Integer TCollection_HAsciiString::SearchFromEnd
476 (const Handle(TCollection_HAsciiString)& what) const
478 return myString.SearchFromEnd(what->String());
481 // ----------------------------------------------------------------------------
483 // ----------------------------------------------------------------------------
484 void TCollection_HAsciiString::SetValue(const Standard_Integer where,
485 const Standard_Character what)
487 myString.SetValue(where,what);
490 // ----------------------------------------------------------------------------
492 // ----------------------------------------------------------------------------
493 void TCollection_HAsciiString::SetValue(const Standard_Integer where,const Standard_CString what)
495 myString.SetValue(where,what);
498 // ----------------------------------------------------------------------------
500 // ---------------------------------------------------------------------------
501 void TCollection_HAsciiString::SetValue(const Standard_Integer where,
502 const Handle(TCollection_HAsciiString)& what)
504 myString.SetValue(where, what->String());
507 // ----------------------------------------------------------------------------
509 // ----------------------------------------------------------------------------
510 Handle(TCollection_HAsciiString)
511 TCollection_HAsciiString::Split(const Standard_Integer where)
513 return new TCollection_HAsciiString(myString.Split(where));
516 // ----------------------------------------------------------------------------
518 // ----------------------------------------------------------------------------
519 Handle(TCollection_HAsciiString)
520 TCollection_HAsciiString::SubString(const Standard_Integer FromIndex,
521 const Standard_Integer ToIndex) const
523 return new TCollection_HAsciiString(myString.SubString(FromIndex,ToIndex));
527 // ----------------------------------------------------------------------------
529 // ----------------------------------------------------------------------------
530 Handle(TCollection_HAsciiString) TCollection_HAsciiString::Token
531 (const Standard_CString separators,const Standard_Integer whichone) const
533 return new TCollection_HAsciiString(myString.Token(separators,whichone));
536 // ----------------------------------------------------------------------------
538 // ----------------------------------------------------------------------------
539 void TCollection_HAsciiString::Trunc(const Standard_Integer ahowmany)
541 myString.Trunc(ahowmany);
544 // ----------------------------------------------------------------------------
546 // ----------------------------------------------------------------------------
547 void TCollection_HAsciiString::UpperCase()
549 myString.UpperCase();
552 // ----------------------------------------------------------------------------
554 // ----------------------------------------------------------------------------
555 Standard_Integer TCollection_HAsciiString::UsefullLength() const
557 return myString.UsefullLength();
560 // ----------------------------------------------------------------------------
562 // ----------------------------------------------------------------------------
563 Standard_Character TCollection_HAsciiString::Value(const Standard_Integer where) const
565 return myString.Value(where);
568 // ----------------------------------------------------------------------------
570 // ----------------------------------------------------------------------------
571 Standard_Boolean TCollection_HAsciiString::IsSameState
572 (const Handle(TCollection_HAsciiString)& other) const
574 if ( myString.Length() == other->Length() )
575 return ( strncmp( myString.mystring, other->ToCString(), myString.Length() ) == 0 );
577 return Standard_False ;