b311480e |
1 | // Copyright (c) 1992-1999 Matra Datavision |
973c2be1 |
2 | // Copyright (c) 1999-2014 OPEN CASCADE SAS |
b311480e |
3 | // |
973c2be1 |
4 | // This file is part of Open CASCADE Technology software library. |
b311480e |
5 | // |
d5f74e42 |
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 |
973c2be1 |
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. |
7fd59977 |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
42cf5bc1 |
15 | |
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> |
7fd59977 |
23 | #include <TCollection_HExtendedString.hxx> |
7fd59977 |
24 | |
92efcf78 |
25 | IMPLEMENT_STANDARD_RTTIEXT(TCollection_HAsciiString,MMgt_TShared) |
26 | |
7fd59977 |
27 | // ---------------------------------------------------------------------------- |
28 | // Create |
29 | // ---------------------------------------------------------------------------- |
30 | TCollection_HAsciiString::TCollection_HAsciiString():myString(){} |
31 | |
32 | |
33 | // ---------------------------------------------------------------------------- |
34 | // Create |
35 | // ---------------------------------------------------------------------------- |
36 | TCollection_HAsciiString::TCollection_HAsciiString |
37 | (const Standard_CString message):myString(message) |
38 | {} |
39 | |
40 | // ---------------------------------------------------------------------------- |
41 | // Create |
42 | // ---------------------------------------------------------------------------- |
43 | TCollection_HAsciiString::TCollection_HAsciiString |
44 | (const TCollection_AsciiString& astring):myString(astring) |
45 | {} |
46 | |
47 | // ---------------------------------------------------------------------------- |
48 | // Create |
49 | // ---------------------------------------------------------------------------- |
50 | TCollection_HAsciiString::TCollection_HAsciiString |
51 | (const Standard_Character aChar):myString(aChar) |
52 | {} |
53 | |
54 | // ---------------------------------------------------------------------------- |
55 | // Create |
56 | // ---------------------------------------------------------------------------- |
57 | TCollection_HAsciiString::TCollection_HAsciiString |
58 | (const Standard_Integer length,const Standard_Character filler ):myString(length,filler) |
59 | {} |
60 | |
61 | // ---------------------------------------------------------------------------- |
62 | // Create |
63 | // ---------------------------------------------------------------------------- |
64 | TCollection_HAsciiString::TCollection_HAsciiString |
65 | (const Standard_Integer aValue):myString(aValue) |
66 | {} |
67 | |
68 | // ---------------------------------------------------------------------------- |
69 | // Create |
70 | // ---------------------------------------------------------------------------- |
71 | TCollection_HAsciiString::TCollection_HAsciiString |
72 | (const Standard_Real aValue):myString(aValue) |
73 | {} |
74 | |
75 | // ---------------------------------------------------------------------------- |
76 | // Create |
77 | // ---------------------------------------------------------------------------- |
78 | TCollection_HAsciiString::TCollection_HAsciiString |
79 | (const Handle(TCollection_HAsciiString)& astring):myString(astring->String()) |
80 | { |
81 | } |
82 | |
83 | // ---------------------------------------------------------------------------- |
84 | // Create |
85 | // ---------------------------------------------------------------------------- |
86 | TCollection_HAsciiString::TCollection_HAsciiString |
87 | (const Handle(TCollection_HExtendedString)& astring, |
88 | const Standard_Character replaceNonAscii) |
89 | : myString(astring->String(), replaceNonAscii) |
90 | { |
91 | } |
92 | |
93 | |
94 | // --------------------------------------------------------------------------- |
95 | // Capitalize |
96 | // ---------------------------------------------------------------------------- |
97 | void TCollection_HAsciiString::Capitalize() |
98 | { |
99 | myString.Capitalize(); |
100 | } |
101 | |
102 | // --------------------------------------------------------------------------- |
103 | // Cat |
104 | // ---------------------------------------------------------------------------- |
105 | Handle(TCollection_HAsciiString) |
106 | TCollection_HAsciiString::Cat(const Standard_CString other) const |
107 | { |
108 | return new TCollection_HAsciiString(myString.Cat(other)); |
109 | } |
110 | |
111 | // --------------------------------------------------------------------------- |
112 | // Cat |
113 | // ---------------------------------------------------------------------------- |
114 | Handle(TCollection_HAsciiString) |
115 | TCollection_HAsciiString::Cat(const Handle(TCollection_HAsciiString)& other) |
116 | const |
117 | { |
118 | return new TCollection_HAsciiString(myString.Cat(other->String() ) ); |
119 | } |
120 | |
121 | // --------------------------------------------------------------------------- |
122 | // Center |
123 | // ---------------------------------------------------------------------------- |
124 | void TCollection_HAsciiString::Center |
125 | (const Standard_Integer Width , |
126 | const Standard_Character Filler) |
127 | { |
128 | if (Width < 0) Standard_NegativeValue::Raise(); |
129 | myString.Center(Width,Filler); |
130 | } |
131 | |
132 | // ---------------------------------------------------------------------------- |
133 | // ChangeAll |
134 | // ---------------------------------------------------------------------------- |
135 | void TCollection_HAsciiString::ChangeAll |
136 | (const Standard_Character aChar, |
137 | const Standard_Character NewChar, |
138 | const Standard_Boolean CaseSensitive) |
139 | { |
140 | myString.ChangeAll(aChar,NewChar,CaseSensitive); |
141 | } |
142 | |
143 | // ---------------------------------------------------------------------------- |
144 | // Clear |
145 | // ---------------------------------------------------------------------------- |
146 | void TCollection_HAsciiString::Clear() |
147 | { |
148 | myString.Clear(); |
149 | } |
150 | |
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 |
158 | { |
159 | if (Length() == 0 || Set->Length() == 0) return 0; |
160 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
161 | Standard_OutOfRange::Raise(); |
162 | return (myString.FirstLocationInSet(Set->String(),FromIndex,ToIndex)); |
163 | } |
164 | |
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 |
172 | { |
173 | if (Length() == 0 || Set->Length() == 0) return 0; |
174 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
175 | Standard_OutOfRange::Raise(); |
176 | return (myString.FirstLocationNotInSet(Set->String(),FromIndex,ToIndex)); |
177 | } |
178 | |
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) |
184 | { |
185 | myString.Insert(where,what); |
186 | } |
187 | |
188 | // ---------------------------------------------------------------------------- |
189 | // Insert |
190 | // ---------------------------------------------------------------------------- |
191 | void TCollection_HAsciiString::Insert(const Standard_Integer where, |
192 | const Standard_CString what) |
193 | { |
194 | myString.Insert(where,what); |
195 | } |
196 | |
197 | // ---------------------------------------------------------------------------- |
198 | // Insert |
199 | // ---------------------------------------------------------------------------- |
200 | void TCollection_HAsciiString::Insert(const Standard_Integer where, |
201 | const Handle(TCollection_HAsciiString)& what) |
202 | { |
203 | myString.Insert(where,what->String()); |
204 | } |
205 | |
206 | //------------------------------------------------------------------------ |
207 | // InsertAfter |
208 | //------------------------------------------------------------------------ |
209 | void TCollection_HAsciiString::InsertAfter |
210 | (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S) |
211 | { |
212 | Standard_Integer size1 = Length(); |
213 | #ifndef NOBOUNDCHECK |
214 | if (Index < 0 || Index > size1) Standard_OutOfRange::Raise(); |
215 | #endif |
216 | myString.InsertAfter(Index,S->String()); |
217 | } |
218 | |
219 | //------------------------------------------------------------------------ |
220 | // InsertBefore |
221 | //------------------------------------------------------------------------ |
222 | void TCollection_HAsciiString::InsertBefore |
223 | (const Standard_Integer Index, const Handle(TCollection_HAsciiString)& S) |
224 | { |
225 | Standard_Integer size1 = Length(); |
226 | #ifndef NOBOUNDCHECK |
227 | if (Index < 1 || Index > size1) Standard_OutOfRange::Raise(); |
228 | #endif |
229 | myString.InsertBefore(Index,S->String()); |
230 | } |
231 | |
232 | // ---------------------------------------------------------------------------- |
233 | // IsEmpty |
234 | // ---------------------------------------------------------------------------- |
235 | Standard_Boolean TCollection_HAsciiString::IsEmpty() const |
236 | { |
237 | return (myString.Length() == 0); |
238 | } |
239 | |
240 | // ---------------------------------------------------------------------------- |
241 | // IsLess |
242 | // ---------------------------------------------------------------------------- |
243 | Standard_Boolean |
244 | TCollection_HAsciiString::IsLess(const Handle(TCollection_HAsciiString)& other) const |
245 | { |
246 | return myString.IsLess(other->String()); |
247 | } |
248 | |
249 | // ---------------------------------------------------------------------------- |
250 | // IsGreater |
251 | // ---------------------------------------------------------------------------- |
252 | Standard_Boolean |
253 | TCollection_HAsciiString::IsGreater(const Handle(TCollection_HAsciiString)& other) const |
254 | { |
255 | return myString.IsGreater(other->String()); |
256 | } |
257 | |
258 | // ---------------------------------------------------------------------------- |
259 | // IntegerValue |
260 | // ---------------------------------------------------------------------------- |
261 | Standard_Integer TCollection_HAsciiString::IntegerValue() const |
262 | { |
263 | return myString.IntegerValue(); |
264 | } |
265 | |
266 | // ---------------------------------------------------------------------------- |
267 | // IsIntegerValue |
268 | // ---------------------------------------------------------------------------- |
269 | Standard_Boolean TCollection_HAsciiString::IsIntegerValue() const |
270 | { |
271 | return myString.IsIntegerValue(); |
272 | } |
273 | |
274 | |
275 | // ---------------------------------------------------------------------------- |
276 | // IsRealvalue |
277 | // ---------------------------------------------------------------------------- |
278 | Standard_Boolean TCollection_HAsciiString::IsRealValue() const |
279 | { |
280 | return myString.IsRealValue(); |
281 | } |
282 | |
283 | // ---------------------------------------------------------------------------- |
284 | // IsAscii |
285 | // ---------------------------------------------------------------------------- |
286 | Standard_Boolean TCollection_HAsciiString::IsAscii() const |
287 | { |
288 | return myString.IsAscii(); |
289 | } |
290 | |
291 | // ---------------------------------------------------------------------------- |
292 | // IsDifferent |
293 | // ---------------------------------------------------------------------------- |
294 | Standard_Boolean TCollection_HAsciiString::IsDifferent |
295 | (const Handle(TCollection_HAsciiString)& S) const |
296 | { |
7fd59977 |
297 | if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsDifferent"); |
29cb310a |
298 | if(S->Length() != myString.Length() ) return Standard_True; |
299 | return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) != 0 ); |
7fd59977 |
300 | } |
301 | |
302 | // ---------------------------------------------------------------------------- |
303 | // IsSameString |
304 | // ---------------------------------------------------------------------------- |
305 | Standard_Boolean TCollection_HAsciiString::IsSameString |
306 | (const Handle(TCollection_HAsciiString)& S) const |
307 | { |
7fd59977 |
308 | if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString"); |
29cb310a |
309 | if ( myString.Length() == S->Length() ) |
310 | return ( strncmp( myString.ToCString(), S->ToCString(), myString.Length() ) == 0 ); |
7fd59977 |
311 | else |
312 | return Standard_False ; |
7fd59977 |
313 | } |
314 | |
315 | // ---------------------------------------------------------------------------- |
316 | // IsSameString |
317 | // ---------------------------------------------------------------------------- |
318 | Standard_Boolean TCollection_HAsciiString::IsSameString |
319 | (const Handle(TCollection_HAsciiString)& S , |
320 | const Standard_Boolean CaseSensitive) const |
321 | { |
7fd59977 |
322 | if(S.IsNull()) Standard_NullObject::Raise("TCollection_HAsciiString::IsSameString"); |
26d9c835 |
323 | return TCollection_AsciiString::IsSameString (myString, S->myString, CaseSensitive); |
7fd59977 |
324 | } |
325 | |
326 | //------------------------------------------------------------------------ |
327 | // LeftAdjust |
328 | //------------------------------------------------------------------------ |
329 | void TCollection_HAsciiString::LeftAdjust () |
330 | { |
331 | myString.LeftAdjust(); |
332 | } |
333 | |
334 | //------------------------------------------------------------------------ |
335 | // LeftJustify |
336 | //------------------------------------------------------------------------ |
337 | void TCollection_HAsciiString::LeftJustify |
338 | (const Standard_Integer Width, const Standard_Character Filler) |
339 | { |
340 | if (Width < 0) Standard_NegativeValue::Raise(); |
341 | myString.LeftJustify(Width,Filler); |
342 | } |
343 | |
344 | //------------------------------------------------------------------------ |
345 | // Location |
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 |
350 | { |
351 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
352 | Standard_OutOfRange::Raise(); |
353 | return myString.Location(N,C,FromIndex,ToIndex); |
354 | } |
355 | |
356 | //------------------------------------------------------------------------ |
357 | // Location |
358 | //------------------------------------------------------------------------ |
359 | Standard_Integer TCollection_HAsciiString::Location |
360 | (const Handle(TCollection_HAsciiString)& S, const Standard_Integer FromIndex, |
361 | const Standard_Integer ToIndex) const |
362 | { |
363 | if (Length() == 0 || S->Length() == 0) return 0; |
364 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
365 | Standard_OutOfRange::Raise(); |
366 | return myString.Location(S->String(),FromIndex,ToIndex); |
367 | } |
368 | |
369 | // ---------------------------------------------------------------------------- |
370 | // LowerCase |
371 | // ---------------------------------------------------------------------------- |
372 | void TCollection_HAsciiString::LowerCase() |
373 | { |
374 | myString.LowerCase(); |
375 | } |
376 | |
377 | //------------------------------------------------------------------------ |
378 | // Prepend |
379 | //------------------------------------------------------------------------ |
380 | void TCollection_HAsciiString::Prepend |
381 | (const Handle(TCollection_HAsciiString)& S) |
382 | { |
383 | myString.Prepend(S->String()); |
384 | } |
385 | |
386 | //--------------------------------------------------------------------- |
387 | // Print |
388 | //--------------------------------------------------------------------- |
389 | void TCollection_HAsciiString::Print(Standard_OStream& S) const |
390 | { |
391 | myString.Print(S); |
392 | } |
393 | |
394 | // ---------------------------------------------------------------------------- |
395 | // RealValue |
396 | // ---------------------------------------------------------------------------- |
397 | Standard_Real TCollection_HAsciiString::RealValue() const |
398 | { |
399 | return myString.RealValue(); |
400 | } |
401 | |
402 | // ---------------------------------------------------------------------------- |
403 | // RemoveAll |
404 | // ---------------------------------------------------------------------------- |
405 | void TCollection_HAsciiString::RemoveAll |
406 | (const Standard_Character what, |
407 | const Standard_Boolean CaseSensitive) |
408 | { |
409 | myString.RemoveAll(what,CaseSensitive); |
410 | } |
411 | |
412 | // ---------------------------------------------------------------------------- |
413 | // RemoveAll |
414 | // ---------------------------------------------------------------------------- |
415 | void TCollection_HAsciiString::RemoveAll(const Standard_Character what) |
416 | { |
417 | myString.RemoveAll(what); |
418 | } |
419 | |
420 | // ---------------------------------------------------------------------------- |
421 | // Remove |
422 | // ---------------------------------------------------------------------------- |
423 | void TCollection_HAsciiString::Remove (const Standard_Integer where, |
424 | const Standard_Integer ahowmany) |
425 | { |
426 | myString.Remove(where,ahowmany); |
427 | } |
428 | |
429 | //------------------------------------------------------------------------ |
430 | // RightAdjust |
431 | //------------------------------------------------------------------------ |
432 | void TCollection_HAsciiString::RightAdjust () |
433 | { |
434 | myString.RightAdjust(); |
435 | } |
436 | |
437 | //------------------------------------------------------------------------ |
438 | // RightJustify |
439 | //------------------------------------------------------------------------ |
440 | void TCollection_HAsciiString::RightJustify |
441 | (const Standard_Integer Width, const Standard_Character Filler) |
442 | { |
443 | if (Width < 0) Standard_NegativeValue::Raise(); |
444 | myString.RightJustify(Width,Filler); |
445 | } |
446 | |
447 | // ---------------------------------------------------------------------------- |
448 | // Search |
449 | // ---------------------------------------------------------------------------- |
450 | Standard_Integer TCollection_HAsciiString::Search(const Standard_CString what)const |
451 | { |
452 | return myString.Search(what); |
453 | } |
454 | |
455 | // ---------------------------------------------------------------------------- |
456 | // Search |
457 | // ---------------------------------------------------------------------------- |
458 | Standard_Integer TCollection_HAsciiString::Search |
459 | (const Handle(TCollection_HAsciiString)& what) const |
460 | { |
461 | return myString.Search(what->String()); |
462 | } |
463 | |
464 | // ---------------------------------------------------------------------------- |
465 | // SearchFromEnd |
466 | // ---------------------------------------------------------------------------- |
467 | Standard_Integer TCollection_HAsciiString::SearchFromEnd(const Standard_CString what)const |
468 | { |
469 | return myString.SearchFromEnd(what); |
470 | } |
471 | |
472 | // ---------------------------------------------------------------------------- |
473 | // SearchFromEnd |
474 | // ---------------------------------------------------------------------------- |
475 | Standard_Integer TCollection_HAsciiString::SearchFromEnd |
476 | (const Handle(TCollection_HAsciiString)& what) const |
477 | { |
478 | return myString.SearchFromEnd(what->String()); |
479 | } |
480 | |
481 | // ---------------------------------------------------------------------------- |
482 | // SetValue |
483 | // ---------------------------------------------------------------------------- |
484 | void TCollection_HAsciiString::SetValue(const Standard_Integer where, |
485 | const Standard_Character what) |
486 | { |
487 | myString.SetValue(where,what); |
488 | } |
489 | |
490 | // ---------------------------------------------------------------------------- |
491 | // SetValue |
492 | // ---------------------------------------------------------------------------- |
493 | void TCollection_HAsciiString::SetValue(const Standard_Integer where,const Standard_CString what) |
494 | { |
495 | myString.SetValue(where,what); |
496 | } |
497 | |
498 | // ---------------------------------------------------------------------------- |
499 | // SetValue |
500 | // --------------------------------------------------------------------------- |
501 | void TCollection_HAsciiString::SetValue(const Standard_Integer where, |
502 | const Handle(TCollection_HAsciiString)& what) |
503 | { |
504 | myString.SetValue(where, what->String()); |
505 | } |
506 | |
507 | // ---------------------------------------------------------------------------- |
508 | // Split |
509 | // ---------------------------------------------------------------------------- |
510 | Handle(TCollection_HAsciiString) |
511 | TCollection_HAsciiString::Split(const Standard_Integer where) |
512 | { |
513 | return new TCollection_HAsciiString(myString.Split(where)); |
514 | } |
515 | |
516 | // ---------------------------------------------------------------------------- |
517 | // SubString |
518 | // ---------------------------------------------------------------------------- |
519 | Handle(TCollection_HAsciiString) |
520 | TCollection_HAsciiString::SubString(const Standard_Integer FromIndex, |
521 | const Standard_Integer ToIndex) const |
522 | { |
523 | return new TCollection_HAsciiString(myString.SubString(FromIndex,ToIndex)); |
524 | } |
525 | |
526 | |
527 | // ---------------------------------------------------------------------------- |
528 | // Token |
529 | // ---------------------------------------------------------------------------- |
530 | Handle(TCollection_HAsciiString) TCollection_HAsciiString::Token |
531 | (const Standard_CString separators,const Standard_Integer whichone) const |
532 | { |
533 | return new TCollection_HAsciiString(myString.Token(separators,whichone)); |
534 | } |
535 | |
536 | // ---------------------------------------------------------------------------- |
537 | // Trunc |
538 | // ---------------------------------------------------------------------------- |
539 | void TCollection_HAsciiString::Trunc(const Standard_Integer ahowmany) |
540 | { |
541 | myString.Trunc(ahowmany); |
542 | } |
543 | |
544 | // ---------------------------------------------------------------------------- |
545 | // UpperCase |
546 | // ---------------------------------------------------------------------------- |
547 | void TCollection_HAsciiString::UpperCase() |
548 | { |
549 | myString.UpperCase(); |
550 | } |
551 | |
552 | // ---------------------------------------------------------------------------- |
553 | // UsefullLength |
554 | // ---------------------------------------------------------------------------- |
555 | Standard_Integer TCollection_HAsciiString::UsefullLength() const |
556 | { |
557 | return myString.UsefullLength(); |
558 | } |
559 | |
560 | // ---------------------------------------------------------------------------- |
561 | // Value |
562 | // ---------------------------------------------------------------------------- |
563 | Standard_Character TCollection_HAsciiString::Value(const Standard_Integer where) const |
564 | { |
565 | return myString.Value(where); |
566 | } |
567 | |
7fd59977 |
568 | // ---------------------------------------------------------------------------- |
569 | // IsSameState |
570 | // ---------------------------------------------------------------------------- |
571 | Standard_Boolean TCollection_HAsciiString::IsSameState |
572 | (const Handle(TCollection_HAsciiString)& other) const |
29cb310a |
573 | { |
574 | if ( myString.Length() == other->Length() ) |
575 | return ( strncmp( myString.mystring, other->ToCString(), myString.Length() ) == 0 ); |
7fd59977 |
576 | else |
577 | return Standard_False ; |
29cb310a |
578 | } |
7fd59977 |
579 | |