b311480e |
1 | // Copyright (c) 1998-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. |
b311480e |
11 | // |
973c2be1 |
12 | // Alternatively, this file may be used under the terms of Open CASCADE |
13 | // commercial license or contractual agreement. |
7fd59977 |
14 | |
15 | #include <PCollection_HAsciiString.ixx> |
16 | #include <PCollection_HExtendedString.hxx> |
17 | #include <TCollection_HAsciiString.hxx> |
18 | #include <Standard_NumericError.hxx> |
19 | #include <Standard_NegativeValue.hxx> |
20 | #include <Standard_OutOfRange.hxx> |
21 | |
7fd59977 |
22 | #include <stdio.h> |
7fd59977 |
23 | |
24 | //------------------------------------ |
25 | // Conversion functions and variables |
26 | //------------------------------------ |
27 | |
28 | #define MAXLENGTH 80 |
29 | static char cnvbuf[MAXLENGTH]; |
30 | static Standard_Integer cnvint; |
31 | static Standard_Real cnvreal; |
32 | |
33 | //----------------------------------------------------------------------- |
34 | // intstr |
35 | //----------------------------------------------------------------------- |
36 | static int intstr(Standard_Integer V,Standard_CString F) |
37 | { |
38 | sprintf(cnvbuf,F,V); |
7dc9e047 |
39 | return (int)strlen(cnvbuf); |
7fd59977 |
40 | } |
41 | |
42 | //----------------------------------------------------------------------- |
43 | // realstr |
44 | //---------------------------------------------------------------------- |
45 | static int realstr(Standard_Real V, Standard_CString F) |
46 | { |
47 | sprintf(cnvbuf,F,V); |
7dc9e047 |
48 | return (int)strlen(cnvbuf); |
7fd59977 |
49 | } |
50 | |
51 | //----------------------------------------------------------------------- |
52 | // Create : from a CString |
53 | //----------------------------------------------------------------------- |
54 | PCollection_HAsciiString::PCollection_HAsciiString(const Standard_CString S) |
60be1f9b |
55 | : Data((Standard_Integer) strlen(S)) |
7fd59977 |
56 | { |
57 | for( Standard_Integer i = 0 ; i < Data.Length() ; i++) |
58 | Data.SetValue(i, S[i]) ; |
59 | } |
60 | |
61 | //------------------------------------------------------------------------ |
62 | // Create from an AsciiString of TCollection |
63 | //------------------------------------------------------------------------ |
64 | PCollection_HAsciiString::PCollection_HAsciiString |
65 | (const TCollection_AsciiString& S):Data(S.Length()) |
66 | { |
67 | for( Standard_Integer i = 1; i <= Data.Length() ; i++) |
68 | Data.SetValue(i-1, S.Value(i)) ; |
69 | } |
70 | |
71 | //------------------------------------------------------------------------ |
72 | // Create from a Character |
73 | //------------------------------------------------------------------------ |
74 | PCollection_HAsciiString::PCollection_HAsciiString(const Standard_Character C) |
75 | : Data(1) |
76 | { |
77 | Data.SetValue(0, C); |
78 | } |
79 | |
80 | //------------------------------------------------------------------------ |
81 | // Create from a range of an HAsciiString of PCollection |
82 | //------------------------------------------------------------------------ |
83 | PCollection_HAsciiString::PCollection_HAsciiString |
84 | (const Handle(PCollection_HAsciiString)& S, |
85 | const Standard_Integer FromIndex, const Standard_Integer ToIndex) : Data(ToIndex-FromIndex+1) |
86 | { |
87 | for( Standard_Integer i = 0 , k = FromIndex; i < Data.Length() ; i++, k++) |
88 | Data.SetValue(i, S->Value(k)); |
89 | } |
90 | |
91 | //------------------------------------------------------------------------ |
92 | // Create from an HExtendedString from PCollection |
93 | //------------------------------------------------------------------------ |
94 | PCollection_HAsciiString::PCollection_HAsciiString |
95 | (const Handle(PCollection_HExtendedString)& S) : Data(S->Length()) |
96 | { |
97 | if (!S->IsAscii()) Standard_OutOfRange::Raise(); |
98 | for( Standard_Integer i = 1; i <= Data.Length() ; i++) { |
99 | // convert the character i of S |
100 | Standard_Character val = ToCharacter(S->Value(i)) ; |
101 | Data.SetValue(i-1,val ) ; |
102 | } |
103 | } |
104 | |
105 | //------------------------------------------------------------------------ |
106 | // Create from a Real by converting it |
107 | //------------------------------------------------------------------------ |
108 | PCollection_HAsciiString::PCollection_HAsciiString |
109 | (const Standard_Real R , const Standard_CString F) : Data(realstr(R,F)) |
110 | { |
111 | for( Standard_Integer i =0 ; i < Data.Length() ; i++) |
112 | Data.SetValue(i,cnvbuf[i] ); |
113 | } |
114 | |
115 | //------------------------------------------------------------------------ |
116 | // Create from an Integer by converting it |
117 | //------------------------------------------------------------------------ |
118 | PCollection_HAsciiString::PCollection_HAsciiString |
119 | (const Standard_Integer I, const Standard_CString F) : Data(intstr(I,F)) |
120 | { |
121 | for( Standard_Integer i = 0 ; i < Data.Length() ; i++) |
122 | Data.SetValue(i,cnvbuf[i]) ; |
123 | } |
124 | |
125 | |
126 | //------------------------------------------------------------------------ |
127 | // Append |
128 | //------------------------------------------------------------------------ |
129 | void PCollection_HAsciiString::Append |
130 | (const Handle(PCollection_HAsciiString)& S) |
131 | { |
132 | InsertAfter(Length(),S); |
133 | } |
134 | |
135 | //------------------------------------------------------------------------ |
136 | // Capitalize |
137 | //------------------------------------------------------------------------ |
138 | void PCollection_HAsciiString::Capitalize () |
139 | { |
140 | for (Standard_Integer i = 0 ; i < Length() ; i++) { |
141 | if( i == 0) Data.SetValue(i, UpperCase(Data(i)) ); |
142 | else Data.SetValue(i, LowerCase(Data(i)) ); |
143 | } |
144 | } |
145 | |
146 | //------------------------------------------------------------------------ |
147 | // Center |
148 | //------------------------------------------------------------------------ |
149 | void PCollection_HAsciiString::Center |
150 | (const Standard_Integer Width, const Standard_Character Filler) |
151 | { |
152 | if (Width < 0) Standard_NegativeValue::Raise(); |
153 | Standard_Integer size1 = Length(); |
154 | if(Width > size1) { |
155 | Standard_Integer size2 = size1 + ((Width - size1)/2); |
156 | LeftJustify(size2,Filler); |
157 | RightJustify(Width,Filler); |
158 | } |
159 | } |
160 | |
161 | //------------------------------------------------------------------------ |
162 | // ChangeAll |
163 | //------------------------------------------------------------------------ |
164 | void PCollection_HAsciiString::ChangeAll |
165 | (const Standard_Character C, const Standard_Character NewC, const Standard_Boolean CaseSensitive) |
166 | { |
167 | for( Standard_Integer i = 0 ; i < Data.Length(); i++) { |
168 | if (CaseSensitive) { |
169 | if(Data(i) == C) Data.SetValue(i, NewC); |
170 | } |
171 | else { |
172 | if(UpperCase(Data(i)) == UpperCase(C)) Data.SetValue(i, NewC); |
173 | } |
174 | } |
175 | } |
176 | |
177 | //------------------------------------------------------------------------ |
178 | // Clear |
179 | //------------------------------------------------------------------------ |
180 | void PCollection_HAsciiString::Clear () |
181 | { |
182 | Data.Resize(0); |
183 | } |
184 | |
185 | //------------------------------------------------------------------------ |
186 | // Convert |
187 | //------------------------------------------------------------------------ |
188 | TCollection_AsciiString PCollection_HAsciiString::Convert() const |
189 | { |
190 | Standard_Integer L = Length(); |
191 | TCollection_AsciiString TString (L,' '); |
192 | for (Standard_Integer i = 1 ; i <= L ; i++) { |
193 | TString.SetValue(i,Value(i)); |
194 | } |
195 | return TString; |
196 | } |
197 | |
198 | //------------------------------------------------------------------------ |
199 | // FirstLocationInSet |
200 | //------------------------------------------------------------------------ |
201 | Standard_Integer PCollection_HAsciiString::FirstLocationInSet |
202 | (const Handle(PCollection_HAsciiString)& Set, |
203 | const Standard_Integer FromIndex, |
204 | const Standard_Integer ToIndex) const |
205 | { |
206 | if (Length() == 0 || Set->Length() == 0) return 0; |
207 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
208 | Standard_OutOfRange::Raise(); |
209 | for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++) |
210 | for(Standard_Integer j = 1; j <= Set->Length(); j++) |
211 | if(Data(i) == Set->Value(j)) return (i+1); |
212 | return 0; |
213 | } |
214 | |
215 | //------------------------------------------------------------------------ |
216 | // FirstLocationNotInset |
217 | //------------------------------------------------------------------------ |
218 | Standard_Integer PCollection_HAsciiString::FirstLocationNotInSet |
219 | (const Handle(PCollection_HAsciiString)& Set, const Standard_Integer FromIndex, |
220 | const Standard_Integer ToIndex) const |
221 | { |
222 | if (Length() == 0 || Set->Length() == 0) return 0; |
223 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
224 | Standard_OutOfRange::Raise(); |
225 | Standard_Boolean find; |
226 | for(Standard_Integer i = FromIndex-1 ; i <= ToIndex-1; i++) { |
227 | find = Standard_False; |
228 | for(Standard_Integer j = 1; j <= Set->Length(); j++) { |
229 | if (Data(i) == Set->Value(j)) find = Standard_True; |
230 | } |
231 | if (!find) return (i+1); |
232 | } |
233 | return 0; |
234 | } |
235 | |
236 | //------------------------------------------------------------------------ |
237 | // InsertAfter |
238 | //------------------------------------------------------------------------ |
239 | void PCollection_HAsciiString::InsertAfter |
240 | (const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S) |
241 | { |
242 | Standard_Integer i ; |
243 | Standard_Integer size1 = Length(); |
244 | Standard_Integer size2 = S->Length(); |
245 | #ifndef NOBOUNDCHECK |
246 | if (Index < 0 || Index > size1) Standard_OutOfRange::Raise(); |
247 | #endif |
248 | Data.Resize(size1+size2); |
249 | for( i = size1-1 ; i >= Index; i--) Data.SetValue(size2+i,Data(i)); |
250 | for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-1,S->Value(i)); |
251 | } |
252 | |
253 | //------------------------------------------------------------------------ |
254 | // InsertBefore |
255 | //------------------------------------------------------------------------ |
256 | void PCollection_HAsciiString::InsertBefore |
257 | (const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S) |
258 | { |
259 | Standard_Integer i ; |
260 | Standard_Integer size1 = Length(); |
261 | Standard_Integer size2 = S->Length(); |
262 | #ifndef NOBOUNDCHECK |
263 | if (Index < 0 || Index > size1) Standard_OutOfRange::Raise(); |
264 | #endif |
265 | Data.Resize(size1+size2); |
266 | for( i = size1-1 ; i >= Index-1 ; i--) |
267 | Data.SetValue(size2+i,Data(i)); |
268 | for( i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i)); |
269 | } |
270 | |
271 | //------------------------------------------------------------------------ |
272 | // IntegerValue |
273 | //------------------------------------------------------------------------ |
274 | Standard_Integer PCollection_HAsciiString::IntegerValue () const |
275 | { |
276 | if (!IsIntegerValue()) Standard_NumericError::Raise(); |
277 | return cnvint; |
278 | } |
279 | |
280 | //------------------------------------------------------------------------ |
281 | // IsDifferent |
282 | //------------------------------------------------------------------------ |
283 | Standard_Boolean PCollection_HAsciiString::IsDifferent |
284 | (const Handle(PCollection_HAsciiString)& S) const |
285 | { |
286 | Standard_Integer size = Length(); |
287 | if( size != S->Length()) return Standard_True; |
288 | Standard_Integer i = 1 ; |
289 | Standard_Boolean different = Standard_False; |
290 | while (i <= size && !different) { |
291 | if (Data(i-1) != S->Value(i)) different = Standard_True; |
292 | i++; |
293 | } |
294 | return different; |
295 | } |
296 | |
297 | //------------------------------------------------------------------------ |
298 | // IsEmpty |
299 | //------------------------------------------------------------------------ |
300 | Standard_Boolean PCollection_HAsciiString::IsEmpty () const |
301 | { |
302 | return (Data.Length() == 0); |
303 | } |
304 | |
305 | //------------------------------------------------------------------------ |
306 | // IsGreater |
307 | //------------------------------------------------------------------------ |
308 | Standard_Boolean PCollection_HAsciiString::IsGreater |
309 | (const Handle(PCollection_HAsciiString)& S) const |
310 | { |
311 | TCollection_AsciiString TMe = Convert(); |
312 | TCollection_AsciiString TS = S->Convert(); |
313 | return TMe.IsGreater(TS); |
314 | } |
315 | |
316 | //------------------------------------------------------------------------ |
317 | // IsIntegervalue |
318 | //------------------------------------------------------------------------ |
319 | Standard_Boolean PCollection_HAsciiString::IsIntegerValue () const |
320 | { |
321 | Standard_Integer i ; |
322 | #if defined(__osf__) || defined(DECOSF1) |
323 | #ifdef OBJS |
324 | #pragma pointer_size (save) |
325 | #pragma pointer_size (long) |
326 | char *ptr; |
327 | #pragma pointer_size (restore) |
328 | #else |
329 | char *ptr; |
330 | #endif |
331 | #else |
332 | char *ptr; |
333 | #endif |
334 | #ifndef NOBOUNDCHECK |
335 | if ( Data.Length() > MAXLENGTH ) return Standard_False; |
336 | #endif |
337 | Handle(TCollection_HAsciiString) astring; |
338 | astring = new TCollection_HAsciiString (this->Convert()); |
339 | astring->LeftAdjust(); |
340 | astring->RightAdjust(); |
341 | for(i = 0; i < astring->Length(); i++) |
342 | cnvbuf[i] = astring->Value(i+1); |
343 | cnvbuf[i] = 0; |
344 | cnvint = strtol(cnvbuf,&ptr,10); |
345 | if (ptr < cnvbuf+astring->Length()) return Standard_False; |
346 | else return Standard_True; |
347 | } |
348 | |
349 | //------------------------------------------------------------------------ |
350 | // Isless |
351 | //------------------------------------------------------------------------ |
352 | Standard_Boolean PCollection_HAsciiString::IsLess |
353 | (const Handle(PCollection_HAsciiString)& S) const |
354 | { |
355 | TCollection_AsciiString TMe = Convert(); |
356 | TCollection_AsciiString TS = S->Convert(); |
357 | return TMe.IsLess(TS); |
358 | } |
359 | |
360 | //------------------------------------------------------------------------ |
361 | // IsRealValue |
362 | //------------------------------------------------------------------------ |
363 | Standard_Boolean PCollection_HAsciiString::IsRealValue () const |
364 | { |
365 | Standard_Integer i ; |
366 | #if defined(__osf__) || defined(DECOSF1) |
367 | #ifdef OBJS |
368 | #pragma pointer_size (save) |
369 | #pragma pointer_size (long) |
370 | char *ptr; |
371 | #pragma pointer_size (restore) |
372 | #else |
373 | char *ptr; |
374 | #endif |
375 | #else |
376 | char *ptr; |
377 | #endif |
378 | #ifndef NOBOUNDCHECK |
379 | if ( Data.Length() > MAXLENGTH ) return Standard_False; |
380 | #endif |
381 | Handle(TCollection_HAsciiString) astring; |
382 | astring = new TCollection_HAsciiString (this->Convert()); |
383 | astring->LeftAdjust(); |
384 | astring->RightAdjust(); |
385 | for(i = 0; i < astring->Length(); i++) |
386 | cnvbuf[i] = astring->Value(i+1); |
387 | cnvbuf[i] = 0; |
91322f44 |
388 | cnvreal = Strtod(cnvbuf,&ptr); |
7fd59977 |
389 | if (ptr < cnvbuf+astring->Length()) return Standard_False; |
390 | else return Standard_True; |
391 | } |
392 | |
393 | //------------------------------------------------------------------------ |
394 | // IsSameString |
395 | //------------------------------------------------------------------------ |
396 | Standard_Boolean PCollection_HAsciiString::IsSameString |
397 | (const Handle(PCollection_HAsciiString)& S) const |
398 | { |
399 | Standard_Integer i ; |
400 | Standard_Integer size1 = Length(); |
401 | if( size1 != S->Length()) return Standard_False; |
402 | for( i = 1 ; i <= size1; i++) { |
403 | if(Data(i-1) != S->Value(i)) return Standard_False; |
404 | } |
405 | return Standard_True; |
406 | } |
407 | |
408 | //------------------------------------------------------------------------ |
409 | // IsSameString |
410 | //------------------------------------------------------------------------ |
411 | Standard_Boolean PCollection_HAsciiString::IsSameString |
412 | (const Handle(PCollection_HAsciiString)& S, const Standard_Boolean CaseSensitive) const |
413 | { |
414 | Standard_Integer size1 = Length(); |
415 | if( size1 != S->Length()) return Standard_False; |
416 | for( Standard_Integer i = 1 ; i <= size1; i++) { |
417 | if(CaseSensitive){ |
418 | if(Data(i-1) != S->Value(i)) return Standard_False; |
419 | } |
420 | else { |
421 | if(UpperCase(Data(i-1)) != UpperCase(S->Value(i))) return Standard_False; |
422 | } |
423 | } |
424 | return Standard_True; |
425 | } |
426 | |
427 | //------------------------------------------------------------------------ |
428 | // LeftAdjust |
429 | //------------------------------------------------------------------------ |
430 | void PCollection_HAsciiString::LeftAdjust () |
431 | { |
432 | Standard_Integer i ; |
433 | for(i = 0 ; i < Data.Length() ; i ++) if(!IsSpace(Data(i))) break; |
434 | if( i > 0 ) Remove(1,i); |
435 | } |
436 | |
437 | //------------------------------------------------------------------------ |
438 | // LeftJustify |
439 | //------------------------------------------------------------------------ |
440 | void PCollection_HAsciiString::LeftJustify |
441 | (const Standard_Integer Width, const Standard_Character Filler) |
442 | { |
443 | if (Width < 0) Standard_NegativeValue::Raise(); |
444 | Standard_Integer size1 = Length(); |
445 | if(Width > size1) { |
446 | Data.Resize(Width); |
447 | for(Standard_Integer i = size1; i < Width ; i++) Data.SetValue(i, Filler); |
448 | } |
449 | } |
450 | |
451 | //------------------------------------------------------------------------ |
452 | // Length |
453 | //------------------------------------------------------------------------ |
454 | Standard_Integer PCollection_HAsciiString::Length () const |
455 | { |
456 | return Data.Length(); |
457 | } |
458 | |
459 | //------------------------------------------------------------------------ |
460 | // Location |
461 | //------------------------------------------------------------------------ |
462 | Standard_Integer PCollection_HAsciiString::Location |
463 | (const Standard_Integer N, const Standard_Character C, |
464 | const Standard_Integer FromIndex, const Standard_Integer ToIndex) const |
465 | { |
466 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
467 | Standard_OutOfRange::Raise(); |
75259fc5 |
468 | for(Standard_Integer i = FromIndex-1, aCount = 0; i <= ToIndex-1; i++) |
7fd59977 |
469 | if(Data(i) == C) { |
75259fc5 |
470 | aCount++; |
471 | if ( aCount == N ) return (i+1); |
7fd59977 |
472 | } |
473 | return 0 ; |
474 | } |
475 | |
476 | //------------------------------------------------------------------------ |
477 | // Location |
478 | //------------------------------------------------------------------------ |
479 | Standard_Integer PCollection_HAsciiString::Location |
480 | (const Handle(PCollection_HAsciiString)& S, const Standard_Integer FromIndex, |
481 | const Standard_Integer ToIndex) const |
482 | { |
483 | if (Length() == 0 || S->Length() == 0) return 0; |
484 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
485 | Standard_OutOfRange::Raise(); |
486 | for(Standard_Integer i = FromIndex-1, k = 1, l = FromIndex-2; i < ToIndex; i++){ |
487 | if(Data(i) == S->Value(k)) { |
488 | k++; |
489 | if ( k > S->Length()) return l + 2; |
490 | } |
491 | else { |
492 | k = 1; |
493 | l = i; |
494 | } |
495 | } |
496 | return 0; |
497 | } |
498 | |
499 | //------------------------------------------------------------------------ |
500 | // Lowercase |
501 | //------------------------------------------------------------------------ |
502 | void PCollection_HAsciiString::Lowercase () |
503 | { |
504 | for( Standard_Integer i = 0 ; i < Data.Length() ; i++) { |
505 | Data.SetValue(i, LowerCase(Data(i))); |
506 | } |
507 | } |
508 | |
509 | //------------------------------------------------------------------------ |
510 | // Prepend |
511 | //------------------------------------------------------------------------ |
512 | void PCollection_HAsciiString::Prepend |
513 | (const Handle(PCollection_HAsciiString)& S) |
514 | { |
515 | InsertAfter(0,S); |
516 | } |
517 | |
518 | |
519 | //------------------------------------------------------------------------ |
520 | // Print |
521 | //------------------------------------------------------------------------ |
522 | void PCollection_HAsciiString::Print (Standard_OStream& S) const |
523 | { |
524 | Standard_Integer len = Data.Length() ; |
525 | for(Standard_Integer i = 0; i < len ; i++) { |
526 | S << Data(i); |
527 | } |
528 | } |
529 | |
530 | //------------------------------------------------------------------------ |
531 | // RealValue |
532 | //------------------------------------------------------------------------ |
533 | Standard_Real PCollection_HAsciiString::RealValue () const |
534 | { |
535 | if(!IsRealValue()) Standard_NumericError::Raise(); |
536 | return cnvreal; |
537 | } |
538 | |
539 | //------------------------------------------------------------------------ |
540 | // Remove |
541 | //------------------------------------------------------------------------ |
542 | void PCollection_HAsciiString::Remove (const Standard_Integer Index) |
543 | { |
544 | if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise(); |
545 | Remove(Index,Index); |
546 | } |
547 | |
548 | //------------------------------------------------------------------------ |
549 | // Remove |
550 | //------------------------------------------------------------------------ |
551 | void PCollection_HAsciiString::Remove |
552 | (const Standard_Integer FromIndex, const Standard_Integer ToIndex) |
553 | { |
554 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
555 | Standard_OutOfRange::Raise(); |
556 | Standard_Integer size1 = Length(); |
557 | for( Standard_Integer i = ToIndex, j = FromIndex-1; i < size1 ; i++, j++) |
558 | Data.SetValue(j,Data(i)); |
559 | Data.Resize(size1-(ToIndex-FromIndex+1)); |
560 | } |
561 | |
562 | //------------------------------------------------------------------------ |
563 | // RemoveAll |
564 | //------------------------------------------------------------------------ |
565 | void PCollection_HAsciiString::RemoveAll |
566 | (const Standard_Character C, const Standard_Boolean CaseSensitive) |
567 | { |
568 | Standard_Integer i ; |
569 | Standard_Integer j ; |
570 | Standard_Integer size1 = Length(); |
571 | for( i = 0, j = 0; i < size1 ; i++){ |
572 | if(CaseSensitive){ |
573 | if(Data(i) == C) continue; |
574 | } |
575 | else { |
576 | if(UpperCase(Data(i)) == UpperCase(C)) continue; |
577 | } |
578 | Data.SetValue(j++, Data(i)); |
579 | } |
580 | Data.Resize(j); |
581 | } |
582 | |
583 | //------------------------------------------------------------------------ |
584 | // RightAdjust |
585 | //------------------------------------------------------------------------ |
586 | void PCollection_HAsciiString::RightAdjust () |
587 | { |
588 | Standard_Integer i ; |
589 | for( i = Data.Length()-1 ; i >= 0 ; i--) if(!IsSpace(Data(i))) break; |
590 | if( i < Data.Length()-1 ) Remove(i+2,Data.Length()); |
591 | } |
592 | |
593 | //------------------------------------------------------------------------ |
594 | // RightJustify |
595 | //------------------------------------------------------------------------ |
596 | void PCollection_HAsciiString::RightJustify |
597 | (const Standard_Integer Width, const Standard_Character Filler) |
598 | { |
599 | Standard_Integer i ; |
600 | Standard_Integer k ; |
601 | if (Width < 0) Standard_NegativeValue::Raise(); |
602 | Standard_Integer size1 = Length(); |
603 | if(Width > size1) { |
604 | Data.Resize(Width); |
605 | for ( i = size1-1, k = Width-1 ; i >= 0 ; i--, k--) |
606 | Data.SetValue(k, Data(i)); |
607 | for(; k >= 0 ; k--) Data.SetValue(k, Filler); |
608 | } |
609 | } |
610 | |
611 | //------------------------------------------------------------------------ |
612 | // SetValue |
613 | //------------------------------------------------------------------------ |
614 | void PCollection_HAsciiString::SetValue |
615 | (const Standard_Integer Index, const Handle(PCollection_HAsciiString)& S) |
616 | { |
617 | |
618 | Standard_Integer size1 = Length(); |
619 | Standard_Integer size2 = S->Length(); |
620 | Standard_Integer size3 = size2 + Index - 1; |
621 | #ifndef NOBOUNDCHECK |
622 | if (Index < 0 || Index > size1) Standard_OutOfRange::Raise(); |
623 | #endif |
624 | if(size1 != size3) Data.Resize(size3); |
625 | for( Standard_Integer i = 1 ; i <= size2; i++) Data.SetValue(Index+i-2, S->Value(i)); |
626 | } |
627 | |
628 | //------------------------------------------------------------------------ |
629 | // SetValue |
630 | //------------------------------------------------------------------------ |
631 | void PCollection_HAsciiString::SetValue |
632 | (const Standard_Integer Index, const Standard_Character C) |
633 | { |
634 | if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise(); |
635 | Data(Index-1) = C; |
636 | } |
637 | |
638 | //------------------------------------------------------------------------ |
639 | // Split |
640 | //------------------------------------------------------------------------ |
641 | Handle(PCollection_HAsciiString) PCollection_HAsciiString::Split |
642 | (const Standard_Integer Index) |
643 | { |
644 | if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise(); |
645 | Handle(PCollection_HAsciiString) S2; |
646 | if (Index != Length()) { |
647 | S2 = SubString(Index+1,Length()); |
648 | Data.Resize(Index); |
649 | } |
650 | else { |
651 | #ifndef OBJS |
652 | S2 = new PCollection_HAsciiString(""); |
653 | #else |
654 | S2 = new (os_segment::of(this)) PCollection_HAsciiString(""); |
655 | #endif |
656 | } |
657 | return S2; |
658 | } |
659 | |
660 | //------------------------------------------------------------------------ |
661 | // SubString |
662 | //------------------------------------------------------------------------ |
663 | Handle(PCollection_HAsciiString) PCollection_HAsciiString::SubString |
664 | (const Standard_Integer FromIndex, const Standard_Integer ToIndex) const |
665 | { |
666 | if (ToIndex > Length() || FromIndex <= 0 || FromIndex > ToIndex ) |
667 | Standard_OutOfRange::Raise(); |
668 | Handle(PCollection_HAsciiString) S1; |
669 | Handle(PCollection_HAsciiString) S2; |
670 | S2 = this; |
671 | #ifndef OBJS |
672 | S1 = new PCollection_HAsciiString(S2,FromIndex,ToIndex); |
673 | #else |
674 | S1 = new (os_segment::of(this)) PCollection_HAsciiString(S2,FromIndex,ToIndex); |
675 | |
676 | #endif |
677 | return S1; |
678 | } |
679 | |
680 | //------------------------------------------------------------------------ |
681 | // Token |
682 | //------------------------------------------------------------------------ |
683 | Handle(PCollection_HAsciiString) PCollection_HAsciiString::Token |
684 | (const Standard_CString separators , |
685 | const Standard_Integer whichone) const |
686 | { |
687 | TCollection_AsciiString TMe = Convert(); |
688 | Handle(PCollection_HAsciiString) |
689 | #ifndef OBJS |
690 | TheToken = new PCollection_HAsciiString(TMe.Token(separators,whichone)); |
691 | #else |
692 | TheToken = new (os_segment::of(this)) PCollection_HAsciiString(TMe.Token(separators,whichone)); |
693 | #endif |
694 | return TheToken; |
695 | } |
696 | |
697 | //------------------------------------------------------------------------ |
698 | // Uppercase |
699 | //------------------------------------------------------------------------ |
700 | void PCollection_HAsciiString::Uppercase () |
701 | { |
702 | for( Standard_Integer i = 0 ; i < Data.Length() ; i++) |
703 | Data.SetValue(i, UpperCase(Data(i))); |
704 | } |
705 | |
706 | //------------------------------------------------------------------------ |
707 | // UsefullLength |
708 | //------------------------------------------------------------------------ |
709 | Standard_Integer PCollection_HAsciiString::UsefullLength () const |
710 | { |
711 | Standard_Integer i ; |
712 | for( i = Data.Length() -1 ; i >= 0 ; i--) |
713 | if(IsGraphic(Data(i))) break; |
714 | return (i+1) ; |
715 | } |
716 | |
717 | //------------------------------------------------------------------------ |
718 | // value |
719 | //------------------------------------------------------------------------ |
720 | Standard_Character PCollection_HAsciiString::Value (const Standard_Integer Index) const |
721 | { |
722 | if (Index < 0 || Index > Length()) Standard_OutOfRange::Raise(); |
723 | return Data(Index-1); |
724 | } |
725 | |
726 | |
727 | |
728 | //------------------------------------------------------------------------ |
729 | // Assign |
730 | //------------------------------------------------------------------------ |
731 | void PCollection_HAsciiString::Assign(const DBC_VArrayOfCharacter& TheField) |
732 | |
733 | { |
734 | Data = TheField; |
735 | } |