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_Type.hxx>
19 #include <TCollection_HAsciiString.hxx>
20 #include <TCollection_HExtendedString.hxx>
22 IMPLEMENT_STANDARD_RTTIEXT(TCollection_HAsciiString,Standard_Transient)
24 // ----------------------------------------------------------------------------
26 // ----------------------------------------------------------------------------
27 TCollection_HAsciiString::TCollection_HAsciiString():myString(){}
30 // ----------------------------------------------------------------------------
32 // ----------------------------------------------------------------------------
33 TCollection_HAsciiString::TCollection_HAsciiString
34 (const Standard_CString message):myString(message)
37 // ----------------------------------------------------------------------------
39 // ----------------------------------------------------------------------------
40 TCollection_HAsciiString::TCollection_HAsciiString
41 (const TCollection_AsciiString& astring):myString(astring)
44 // ----------------------------------------------------------------------------
46 // ----------------------------------------------------------------------------
47 TCollection_HAsciiString::TCollection_HAsciiString
48 (const Standard_Character aChar):myString(aChar)
51 // ----------------------------------------------------------------------------
53 // ----------------------------------------------------------------------------
54 TCollection_HAsciiString::TCollection_HAsciiString
55 (const Standard_Integer length,const Standard_Character filler ):myString(length,filler)
58 // ----------------------------------------------------------------------------
60 // ----------------------------------------------------------------------------
61 TCollection_HAsciiString::TCollection_HAsciiString
62 (const Standard_Integer aValue):myString(aValue)
65 // ----------------------------------------------------------------------------
67 // ----------------------------------------------------------------------------
68 TCollection_HAsciiString::TCollection_HAsciiString
69 (const Standard_Real aValue):myString(aValue)
72 // ----------------------------------------------------------------------------
74 // ----------------------------------------------------------------------------
75 TCollection_HAsciiString::TCollection_HAsciiString
76 (const Handle(TCollection_HAsciiString)& astring):myString(astring->String())
80 // ----------------------------------------------------------------------------
82 // ----------------------------------------------------------------------------
83 TCollection_HAsciiString::TCollection_HAsciiString
84 (const Handle(TCollection_HExtendedString)& astring,
85 const Standard_Character replaceNonAscii)
86 : myString(astring->String(), replaceNonAscii)
91 // ---------------------------------------------------------------------------
93 // ----------------------------------------------------------------------------
94 void TCollection_HAsciiString::Capitalize()
96 myString.Capitalize();
99 // ---------------------------------------------------------------------------
101 // ----------------------------------------------------------------------------
102 Handle(TCollection_HAsciiString)
103 TCollection_HAsciiString::Cat(const Standard_CString other) const
105 return new TCollection_HAsciiString(myString.Cat(other));
108 // ---------------------------------------------------------------------------
110 // ----------------------------------------------------------------------------
111 Handle(TCollection_HAsciiString)
112 TCollection_HAsciiString::Cat(const Handle(TCollection_HAsciiString)& other)
115 return new TCollection_HAsciiString(myString.Cat(other->String() ) );
118 // ---------------------------------------------------------------------------
120 // ----------------------------------------------------------------------------
121 void TCollection_HAsciiString::Center
122 (const Standard_Integer Width ,
123 const Standard_Character Filler)
125 if (Width < 0) throw Standard_NegativeValue();
126 myString.Center(Width,Filler);
129 // ----------------------------------------------------------------------------
131 // ----------------------------------------------------------------------------
132 void TCollection_HAsciiString::ChangeAll
133 (const Standard_Character aChar,
134 const Standard_Character NewChar,
135 const Standard_Boolean CaseSensitive)
137 myString.ChangeAll(aChar,NewChar,CaseSensitive);
140 // ----------------------------------------------------------------------------
142 // ----------------------------------------------------------------------------
143 void TCollection_HAsciiString::Clear()
148 // ----------------------------------------------------------------------------
149 // FirstLocationInSet
150 // ----------------------------------------------------------------------------
151 Standard_Integer TCollection_HAsciiString::FirstLocationInSet
152 (const Handle(TCollection_HAsciiString)& Set,
153 const Standard_Integer FromIndex,
154 const Standard_Integer ToIndex) const
156 if (Length() == 0 || Set->Length() == 0) return 0;
157 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
158 throw Standard_OutOfRange();
159 return (myString.FirstLocationInSet(Set->String(),FromIndex,ToIndex));
162 // ----------------------------------------------------------------------------
163 // FirstLocationNotInSet
164 // ----------------------------------------------------------------------------
165 Standard_Integer TCollection_HAsciiString::FirstLocationNotInSet
166 (const Handle(TCollection_HAsciiString)& Set,
167 const Standard_Integer FromIndex,
168 const Standard_Integer ToIndex) const
170 if (Length() == 0 || Set->Length() == 0) return 0;
171 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
172 throw Standard_OutOfRange();
173 return (myString.FirstLocationNotInSet(Set->String(),FromIndex,ToIndex));
176 // ----------------------------------------------------------------------------
177 // Insert a Standard_Character before 'where'th Standard_Character
178 // ----------------------------------------------------------------------------
179 void TCollection_HAsciiString::Insert(const Standard_Integer where,
180 const Standard_Character what)
182 myString.Insert(where,what);
185 // ----------------------------------------------------------------------------
187 // ----------------------------------------------------------------------------
188 void TCollection_HAsciiString::Insert(const Standard_Integer where,
189 const Standard_CString what)
191 myString.Insert(where,what);
194 // ----------------------------------------------------------------------------
196 // ----------------------------------------------------------------------------
197 void TCollection_HAsciiString::Insert(const Standard_Integer where,
198 const Handle(TCollection_HAsciiString)& what)
200 myString.Insert(where,what->String());
203 //------------------------------------------------------------------------
205 //------------------------------------------------------------------------
206 void TCollection_HAsciiString::InsertAfter
207 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
209 Standard_Integer size1 = Length();
211 if (Index < 0 || Index > size1) throw Standard_OutOfRange();
213 myString.InsertAfter(Index,S->String());
216 //------------------------------------------------------------------------
218 //------------------------------------------------------------------------
219 void TCollection_HAsciiString::InsertBefore
220 (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S)
222 Standard_Integer size1 = Length();
224 if (Index < 1 || Index > size1) throw Standard_OutOfRange();
226 myString.InsertBefore(Index,S->String());
229 // ----------------------------------------------------------------------------
231 // ----------------------------------------------------------------------------
232 Standard_Boolean TCollection_HAsciiString::IsEmpty() const
234 return (myString.Length() == 0);
237 // ----------------------------------------------------------------------------
239 // ----------------------------------------------------------------------------
241 TCollection_HAsciiString::IsLess(const Handle(TCollection_HAsciiString)& other) const
243 return myString.IsLess(other->String());
246 // ----------------------------------------------------------------------------
248 // ----------------------------------------------------------------------------
250 TCollection_HAsciiString::IsGreater(const Handle(TCollection_HAsciiString)& other) const
252 return myString.IsGreater(other->String());
255 // ----------------------------------------------------------------------------
257 // ----------------------------------------------------------------------------
258 Standard_Integer TCollection_HAsciiString::IntegerValue() const
260 return myString.IntegerValue();
263 // ----------------------------------------------------------------------------
265 // ----------------------------------------------------------------------------
266 Standard_Boolean TCollection_HAsciiString::IsIntegerValue() const
268 return myString.IsIntegerValue();
272 // ----------------------------------------------------------------------------
274 // ----------------------------------------------------------------------------
275 Standard_Boolean TCollection_HAsciiString::IsRealValue() const
277 return myString.IsRealValue();
280 // ----------------------------------------------------------------------------
282 // ----------------------------------------------------------------------------
283 Standard_Boolean TCollection_HAsciiString::IsAscii() const
285 return myString.IsAscii();
288 // ----------------------------------------------------------------------------
290 // ----------------------------------------------------------------------------
291 Standard_Boolean TCollection_HAsciiString::IsDifferent
292 (const Handle(TCollection_HAsciiString)& S) const
294 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsDifferent");
295 if(S->Length() != myString.Length() ) return Standard_True;
296 return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) != 0 );
299 // ----------------------------------------------------------------------------
301 // ----------------------------------------------------------------------------
302 Standard_Boolean TCollection_HAsciiString::IsSameString
303 (const Handle(TCollection_HAsciiString)& S) const
305 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsSameString");
306 if ( myString.Length() == S->Length() )
307 return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) == 0 );
309 return Standard_False ;
312 // ----------------------------------------------------------------------------
314 // ----------------------------------------------------------------------------
315 Standard_Boolean TCollection_HAsciiString::IsSameString
316 (const Handle(TCollection_HAsciiString)& S ,
317 const Standard_Boolean CaseSensitive) const
319 if(S.IsNull()) throw Standard_NullObject("TCollection_HAsciiString::IsSameString");
320 return TCollection_AsciiString::IsSameString (myString, S->myString, CaseSensitive);
323 //------------------------------------------------------------------------
325 //------------------------------------------------------------------------
326 void TCollection_HAsciiString::LeftAdjust ()
328 myString.LeftAdjust();
331 //------------------------------------------------------------------------
333 //------------------------------------------------------------------------
334 void TCollection_HAsciiString::LeftJustify
335 (const Standard_Integer Width, const Standard_Character Filler)
337 if (Width < 0) throw Standard_NegativeValue();
338 myString.LeftJustify(Width,Filler);
341 //------------------------------------------------------------------------
343 //------------------------------------------------------------------------
344 Standard_Integer TCollection_HAsciiString::Location
345 (const Standard_Integer N, const Standard_Character C,
346 const Standard_Integer FromIndex, const Standard_Integer ToIndex) const
348 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
349 throw Standard_OutOfRange();
350 return myString.Location(N,C,FromIndex,ToIndex);
353 //------------------------------------------------------------------------
355 //------------------------------------------------------------------------
356 Standard_Integer TCollection_HAsciiString::Location
357 (const Handle(TCollection_HAsciiString)& S, const Standard_Integer FromIndex,
358 const Standard_Integer ToIndex) const
360 if (Length() == 0 || S->Length() == 0) return 0;
361 if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex )
362 throw Standard_OutOfRange();
363 return myString.Location(S->String(),FromIndex,ToIndex);
366 // ----------------------------------------------------------------------------
368 // ----------------------------------------------------------------------------
369 void TCollection_HAsciiString::LowerCase()
371 myString.LowerCase();
374 //------------------------------------------------------------------------
376 //------------------------------------------------------------------------
377 void TCollection_HAsciiString::Prepend
378 (const Handle(TCollection_HAsciiString)& S)
380 myString.Prepend(S->String());
383 //---------------------------------------------------------------------
385 //---------------------------------------------------------------------
386 void TCollection_HAsciiString::Print(Standard_OStream& S) const
391 // ----------------------------------------------------------------------------
393 // ----------------------------------------------------------------------------
394 Standard_Real TCollection_HAsciiString::RealValue() const
396 return myString.RealValue();
399 // ----------------------------------------------------------------------------
401 // ----------------------------------------------------------------------------
402 void TCollection_HAsciiString::RemoveAll
403 (const Standard_Character what,
404 const Standard_Boolean CaseSensitive)
406 myString.RemoveAll(what,CaseSensitive);
409 // ----------------------------------------------------------------------------
411 // ----------------------------------------------------------------------------
412 void TCollection_HAsciiString::RemoveAll(const Standard_Character what)
414 myString.RemoveAll(what);
417 // ----------------------------------------------------------------------------
419 // ----------------------------------------------------------------------------
420 void TCollection_HAsciiString::Remove (const Standard_Integer where,
421 const Standard_Integer ahowmany)
423 myString.Remove(where,ahowmany);
426 //------------------------------------------------------------------------
428 //------------------------------------------------------------------------
429 void TCollection_HAsciiString::RightAdjust ()
431 myString.RightAdjust();
434 //------------------------------------------------------------------------
436 //------------------------------------------------------------------------
437 void TCollection_HAsciiString::RightJustify
438 (const Standard_Integer Width, const Standard_Character Filler)
440 if (Width < 0) throw Standard_NegativeValue();
441 myString.RightJustify(Width,Filler);
444 // ----------------------------------------------------------------------------
446 // ----------------------------------------------------------------------------
447 Standard_Integer TCollection_HAsciiString::Search(const Standard_CString what)const
449 return myString.Search(what);
452 // ----------------------------------------------------------------------------
454 // ----------------------------------------------------------------------------
455 Standard_Integer TCollection_HAsciiString::Search
456 (const Handle(TCollection_HAsciiString)& what) const
458 return myString.Search(what->String());
461 // ----------------------------------------------------------------------------
463 // ----------------------------------------------------------------------------
464 Standard_Integer TCollection_HAsciiString::SearchFromEnd(const Standard_CString what)const
466 return myString.SearchFromEnd(what);
469 // ----------------------------------------------------------------------------
471 // ----------------------------------------------------------------------------
472 Standard_Integer TCollection_HAsciiString::SearchFromEnd
473 (const Handle(TCollection_HAsciiString)& what) const
475 return myString.SearchFromEnd(what->String());
478 // ----------------------------------------------------------------------------
480 // ----------------------------------------------------------------------------
481 void TCollection_HAsciiString::SetValue(const Standard_Integer where,
482 const Standard_Character what)
484 myString.SetValue(where,what);
487 // ----------------------------------------------------------------------------
489 // ----------------------------------------------------------------------------
490 void TCollection_HAsciiString::SetValue(const Standard_Integer where,const Standard_CString what)
492 myString.SetValue(where,what);
495 // ----------------------------------------------------------------------------
497 // ---------------------------------------------------------------------------
498 void TCollection_HAsciiString::SetValue(const Standard_Integer where,
499 const Handle(TCollection_HAsciiString)& what)
501 myString.SetValue(where, what->String());
504 // ----------------------------------------------------------------------------
506 // ----------------------------------------------------------------------------
507 Handle(TCollection_HAsciiString)
508 TCollection_HAsciiString::Split(const Standard_Integer where)
510 return new TCollection_HAsciiString(myString.Split(where));
513 // ----------------------------------------------------------------------------
515 // ----------------------------------------------------------------------------
516 Handle(TCollection_HAsciiString)
517 TCollection_HAsciiString::SubString(const Standard_Integer FromIndex,
518 const Standard_Integer ToIndex) const
520 return new TCollection_HAsciiString(myString.SubString(FromIndex,ToIndex));
524 // ----------------------------------------------------------------------------
526 // ----------------------------------------------------------------------------
527 Handle(TCollection_HAsciiString) TCollection_HAsciiString::Token
528 (const Standard_CString separators,const Standard_Integer whichone) const
530 return new TCollection_HAsciiString(myString.Token(separators,whichone));
533 // ----------------------------------------------------------------------------
535 // ----------------------------------------------------------------------------
536 void TCollection_HAsciiString::Trunc(const Standard_Integer ahowmany)
538 myString.Trunc(ahowmany);
541 // ----------------------------------------------------------------------------
543 // ----------------------------------------------------------------------------
544 void TCollection_HAsciiString::UpperCase()
546 myString.UpperCase();
549 // ----------------------------------------------------------------------------
551 // ----------------------------------------------------------------------------
552 Standard_Integer TCollection_HAsciiString::UsefullLength() const
554 return myString.UsefullLength();
557 // ----------------------------------------------------------------------------
559 // ----------------------------------------------------------------------------
560 Standard_Character TCollection_HAsciiString::Value(const Standard_Integer where) const
562 return myString.Value(where);
565 // ----------------------------------------------------------------------------
567 // ----------------------------------------------------------------------------
568 Standard_Boolean TCollection_HAsciiString::IsSameState
569 (const Handle(TCollection_HAsciiString)& other) const
571 if ( myString.Length() == other->Length() )
572 return ( strncmp( myString.mystring, other->ToCString(), myString.Length() ) == 0 );
574 return Standard_False ;