1 /*****************************************************************************/
2 /* Software Testing Automation Framework (STAF) */
3 /* (C) Copyright IBM Corp. 2001 */
4 /* */
5 /* This software is licensed under the Eclipse Public License (EPL) V1.0. */
6 /*****************************************************************************/
7
8 #ifndef STAF_StringInlImpl
9 #define STAF_StringInlImpl
10
11 #include "STAF.h"
12 #include <cstdio>
13 #include "STAFString.h"
14 #include "STAF_iostream.h"
15 #include "STAFRefPtr.h"
16 #include "STAFException.h"
17
STAFString()18 STAF_INLINE STAFString::STAFString() : fStringImpl(0)
19 {
20 unsigned int osRC = 0;
21 STAFRC_t rc = STAFStringConstruct(&fStringImpl, 0, 0, &osRC);
22
23 STAFException::checkRC(rc, "STAFStringConstruct", osRC);
24 }
25
26
STAFString(const char * buffer,unsigned int length,CodePageType cpType)27 STAF_INLINE STAFString::STAFString(const char *buffer, unsigned int length,
28 CodePageType cpType) : fStringImpl(0)
29 {
30 unsigned int osRC = 0;
31 STAFRC_t rc = kSTAFOk;
32
33 if (cpType == kCurrent)
34 {
35 // We must compute the length first.
36 // Note: Solaris 5.6 had core dump issues if we
37 // computed the length in one of the args while
38 // calling STAFStringConstructFromCurrentCodePage
39 unsigned int computeLen = length;
40 if (computeLen == 0xFFFFFFFF)
41 computeLen = strlen(buffer);
42
43 rc = STAFStringConstructFromCurrentCodePage(&fStringImpl, buffer,
44 computeLen, &osRC);
45 }
46 else
47 {
48 rc = STAFStringConstruct(&fStringImpl, buffer, length, &osRC);
49 }
50
51 STAFException::checkRC(rc, "STAFStringConstruct[FromCurrentCodePage]", osRC);
52 }
53
STAFString(unsigned int fromValue,unsigned int base)54 STAF_INLINE STAFString::STAFString(unsigned int fromValue, unsigned int base)
55 : fStringImpl(0)
56 {
57 unsigned int osRC = 0;
58 STAFRC_t rc = STAFStringConstructFromUInt(
59 &fStringImpl, fromValue, base, &osRC);
60
61 STAFException::checkRC(rc, "STAFStringConstructFromUInt", osRC);
62 }
63
STAFString(int fromValue,unsigned int base)64 STAF_INLINE STAFString::STAFString(int fromValue, unsigned int base)
65 : fStringImpl(0)
66 {
67 unsigned int osRC = 0;
68 STAFRC_t rc = STAFStringConstructFromInt64(
69 &fStringImpl, static_cast<STAFInt64_t>(fromValue), base, &osRC);
70
71 STAFException::checkRC(rc, "STAFStringConstructFromInt64", osRC);
72 }
73
STAFString(unsigned short fromValue,unsigned int base)74 STAF_INLINE STAFString::STAFString(unsigned short fromValue, unsigned int base)
75 : fStringImpl(0)
76 {
77 unsigned int osRC = 0;
78 STAFRC_t rc = STAFStringConstructFromUInt64(
79 &fStringImpl, static_cast<STAFUInt64_t>(fromValue), base, &osRC);
80
81 STAFException::checkRC(rc, "STAFStringConstructFromUInt64", osRC);
82 }
83
STAFString(short fromValue,unsigned int base)84 STAF_INLINE STAFString::STAFString(short fromValue, unsigned int base)
85 : fStringImpl(0)
86 {
87 unsigned int osRC = 0;
88 STAFRC_t rc = STAFStringConstructFromInt64(
89 &fStringImpl, static_cast<STAFInt64_t>(fromValue), base, &osRC);
90
91 STAFException::checkRC(rc, "STAFStringConstructFromInt64", osRC);
92 }
93
94 // On 64-bit Unix machines, an unsigned long is the same as a STAFUInt64_t
95 // and a long is the same as a STAFInt64_t, so can't define STAFString
96 // constructors for both
97
98 #if !defined(STAF_OS_64BIT)
STAFString(unsigned long fromValue,unsigned int base)99 STAF_INLINE STAFString::STAFString(unsigned long fromValue, unsigned int base)
100 : fStringImpl(0)
101 {
102 unsigned int osRC = 0;
103 STAFRC_t rc = STAFStringConstructFromUInt64(
104 &fStringImpl, static_cast<STAFUInt64_t>(fromValue), base, &osRC);
105
106 STAFException::checkRC(rc, "STAFStringConstructFromUInt64", osRC);
107 }
108
STAFString(long fromValue,unsigned int base)109 STAF_INLINE STAFString::STAFString(long fromValue, unsigned int base)
110 : fStringImpl(0)
111 {
112 unsigned int osRC = 0;
113 STAFRC_t rc = STAFStringConstructFromInt64(
114 &fStringImpl, static_cast<STAFInt64_t>(fromValue), base, &osRC);
115
116 STAFException::checkRC(rc, "STAFStringConstructFromInt64", osRC);
117 }
118 #endif
119
STAFString(STAFUInt64_t fromValue,unsigned int base)120 STAF_INLINE STAFString::STAFString(STAFUInt64_t fromValue, unsigned int base)
121 : fStringImpl(0)
122 {
123 unsigned int osRC = 0;
124 STAFRC_t rc = STAFStringConstructFromUInt64(
125 &fStringImpl, fromValue, base, &osRC);
126
127 STAFException::checkRC(rc, "STAFStringConstructFromUInt64", osRC);
128 }
129
STAFString(STAFInt64_t fromValue,unsigned int base)130 STAF_INLINE STAFString::STAFString(STAFInt64_t fromValue, unsigned int base)
131 : fStringImpl(0)
132 {
133 unsigned int osRC = 0;
134 STAFRC_t rc = STAFStringConstructFromInt64(
135 &fStringImpl, fromValue, base, &osRC);
136
137 STAFException::checkRC(rc, "STAFStringConstructFromInt64", osRC);
138 }
139
STAFString(const STAFString & from)140 STAF_INLINE STAFString::STAFString(const STAFString &from) : fStringImpl(0)
141 {
142 unsigned int osRC = 0;
143 STAFRC_t rc = STAFStringConstructCopy(&fStringImpl, from.fStringImpl,
144 &osRC);
145
146 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
147 }
148
149
STAFString(STAFStringConst_t from)150 STAF_INLINE STAFString::STAFString(STAFStringConst_t from)
151 {
152 unsigned int osRC = 0;
153 STAFRC_t rc = kSTAFOk;
154
155 // if from is null, then construct an empty string, else
156 // construct either a shallow or deep copy
157
158 if (from == 0)
159 rc = STAFStringConstruct(&fStringImpl, 0, 0, &osRC);
160 else
161 rc = STAFStringConstructCopy(&fStringImpl, from, &osRC);
162
163 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
164 }
165
166
STAFString(STAFString_t from,CopyMode mode)167 STAF_INLINE STAFString::STAFString(STAFString_t from, CopyMode mode)
168 {
169 unsigned int osRC = 0;
170 STAFRC_t rc = kSTAFOk;
171
172 // if from is null, then construct an empty string, else
173 // construct either a shallow or deep copy
174
175 if (from == 0)
176 rc = STAFStringConstruct(&fStringImpl, 0, 0, &osRC);
177 else if (mode == kShallow)
178 fStringImpl = (STAFString_t)from;
179 else
180 rc = STAFStringConstructCopy(&fStringImpl, from, &osRC);
181
182 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
183 }
184
185
STAFString(STAFUTF8Char_t aChar)186 STAF_INLINE STAFString::STAFString(STAFUTF8Char_t aChar)
187 {
188 unsigned int osRC = 0;
189 STAFRC_t rc = STAFStringConstructChar(&fStringImpl, aChar,
190 &osRC);
191 STAFException::checkRC(rc, "STAFStringConstructChar", osRC);
192 }
193
194
subString(unsigned int begin,unsigned int length,IndexRep corb) const195 STAF_INLINE STAFString STAFString::subString(unsigned int begin,
196 unsigned int length,
197 IndexRep corb) const
198 {
199 STAFString_t newString;
200 unsigned int osRC = 0;
201 STAFRC_t rc = STAFStringConstructSubString(&newString, fStringImpl,
202 begin, length, corb, &osRC);
203
204 STAFException::checkRC(rc, "STAFStringConstructSubString", osRC);
205
206 return STAFString(newString, STAFString::kShallow);
207 }
208
209
numWords() const210 STAF_INLINE unsigned int STAFString::numWords() const
211 {
212 unsigned int osRC = 0;
213 unsigned int theNumWords = 0;
214 STAFRC_t rc = STAFStringNumOfWords(fStringImpl, &theNumWords, &osRC);
215
216 STAFException::checkRC(rc, "STAFStringNumWords", osRC);
217
218 return theNumWords;
219 }
220
221
subWord(unsigned int begin,unsigned int length) const222 STAF_INLINE STAFString STAFString::subWord(unsigned int begin,
223 unsigned int length) const
224 {
225 STAFString_t newString;
226 unsigned int osRC = 0;
227 STAFRC_t rc = STAFStringConstructSubWord(&newString, fStringImpl,
228 begin, length, &osRC);
229
230 STAFException::checkRC(rc, "STAFStringConstructSubWord", osRC);
231
232 return STAFString(newString, STAFString::kShallow);
233 }
234
235
count(const STAFString & theSubStr) const236 STAF_INLINE unsigned int STAFString::count(const STAFString &theSubStr) const
237 {
238 unsigned int osRC = 0;
239 unsigned int theCount = 0;
240 STAFRC_t rc = STAFStringCountSubStrings(fStringImpl, theSubStr.fStringImpl,
241 &theCount, &osRC);
242
243 STAFException::checkRC(rc, "STAFStringCount", osRC);
244
245 return theCount;
246 }
247
248
length(IndexRep corb) const249 STAF_INLINE unsigned int STAFString::length(IndexRep corb) const
250 {
251 unsigned int osRC = 0;
252 unsigned int theLength = 0;
253 STAFRC_t rc = STAFStringLength(fStringImpl, &theLength, corb, &osRC);
254
255 STAFException::checkRC(rc, "STAFStringLength", osRC);
256
257 return theLength;
258 }
259
260
sizeOfChar(unsigned int index,IndexRep corb) const261 STAF_INLINE unsigned int STAFString::sizeOfChar(unsigned int index,
262 IndexRep corb) const
263 {
264 unsigned int osRC = 0;
265 unsigned int theSize = 0;
266 STAFRC_t rc = STAFStringSizeOfChar(fStringImpl, index, corb, &theSize,
267 &osRC);
268
269 STAFException::checkRC(rc, "STAFStringSizeOfChar", osRC);
270
271 return theSize;
272 }
273
buffer(unsigned int * bufLength) const274 STAF_INLINE const char *STAFString::buffer(unsigned int *bufLength) const
275 {
276 unsigned int osRC = 0;
277 const char *theData = 0;
278 STAFRC_t rc = STAFStringGetBuffer(fStringImpl, &theData, bufLength,
279 &osRC);
280
281 STAFException::checkRC(rc, "STAFStringGetBuffer", osRC);
282
283 return theData;
284 }
285
286
getImpl() const287 STAF_INLINE STAFString_t STAFString::getImpl() const
288 {
289 return fStringImpl;
290 }
291
292
adoptImpl()293 STAF_INLINE STAFString_t STAFString::adoptImpl()
294 {
295 STAFString_t temp = fStringImpl;
296
297 fStringImpl = 0;
298
299 return temp;
300 }
301
302
replaceImpl(STAFString_t replacementImpl)303 STAF_INLINE void STAFString::replaceImpl(STAFString_t replacementImpl)
304 {
305 STAFString_t temp = fStringImpl;
306
307 fStringImpl = replacementImpl;
308
309 unsigned int osRC = 0;
310 STAFRC_t rc = STAFStringDestruct(&temp, &osRC);
311
312 STAFException::checkRC(rc, "STAFStringDestruct", osRC);
313 }
314
315
byteIndexOfChar(unsigned int charIndex) const316 STAF_INLINE unsigned int STAFString::byteIndexOfChar(unsigned int charIndex)
317 const
318 {
319 unsigned int osRC = 0;
320 unsigned int theIndex = 0;
321 STAFRC_t rc = STAFStringByteIndexOfChar(fStringImpl, charIndex,
322 &theIndex, &osRC);
323
324 STAFException::checkRC(rc, "STAFStringByteIndexOfChar", osRC);
325
326 return theIndex;
327 }
328
329
find(const STAFString & searchFor,unsigned int begin,IndexRep corb) const330 STAF_INLINE unsigned int STAFString::find(const STAFString &searchFor,
331 unsigned int begin,
332 IndexRep corb) const
333 {
334 unsigned int osRC = 0;
335 unsigned int theIndex = 0;
336 STAFRC_t rc = STAFStringFind(fStringImpl, searchFor.fStringImpl, begin,
337 corb, &theIndex, &osRC);
338
339 STAFException::checkRC(rc, "STAFStringFind", osRC);
340
341 return theIndex;
342 }
343
344
findFirstOf(const STAFString & searchList,unsigned int begin,IndexRep corb) const345 STAF_INLINE unsigned int STAFString::findFirstOf(const STAFString &searchList,
346 unsigned int begin,
347 IndexRep corb) const
348 {
349 unsigned int osRC = 0;
350 unsigned int theIndex = 0;
351 STAFRC_t rc = STAFStringFindFirstOf(fStringImpl, searchList.fStringImpl,
352 begin, corb, &theIndex, &osRC);
353
354 STAFException::checkRC(rc, "STAFStringFindFirstOf", osRC);
355
356 return theIndex;
357 }
358
359
findFirstNotOf(const STAFString & searchList,unsigned int begin,IndexRep corb) const360 STAF_INLINE unsigned int STAFString::findFirstNotOf(const STAFString &searchList,
361 unsigned int begin,
362 IndexRep corb) const
363 {
364 unsigned int osRC = 0;
365 unsigned int theIndex = 0;
366 STAFRC_t rc = STAFStringFindFirstNotOf(fStringImpl,
367 searchList.fStringImpl, begin,
368 corb, &theIndex, &osRC);
369
370 STAFException::checkRC(rc, "STAFStringFindFirstNotOf", osRC);
371
372 return theIndex;
373 }
374
375
findLastOf(const STAFString & searchList,unsigned int begin,IndexRep corb) const376 STAF_INLINE unsigned int STAFString::findLastOf(const STAFString &searchList,
377 unsigned int begin,
378 IndexRep corb) const
379 {
380 unsigned int osRC = 0;
381 unsigned int theIndex = 0;
382
383 STAFRC_t rc = STAFStringFindLastOf(fStringImpl, searchList.fStringImpl,
384 begin, corb, &theIndex, &osRC);
385
386 STAFException::checkRC(rc, "STAFStringFindLastOf", osRC);
387
388 return theIndex;
389 }
390
391
findLastNotOf(const STAFString & searchList,unsigned int begin,IndexRep corb) const392 STAF_INLINE unsigned int STAFString::findLastNotOf(const STAFString &searchList,
393 unsigned int begin,
394 IndexRep corb) const
395 {
396 unsigned int osRC = 0;
397 unsigned int theIndex = 0;
398 STAFRC_t rc = STAFStringFindLastNotOf(fStringImpl, searchList.fStringImpl,
399 begin, corb, &theIndex, &osRC);
400
401 STAFException::checkRC(rc, "STAFStringFindLastNotOf", osRC);
402
403 return theIndex;
404 }
405
406
lowerCase()407 STAF_INLINE STAFString &STAFString::lowerCase()
408 {
409 unsigned int osRC = 0;
410 STAFRC_t rc = STAFStringToLowerCase(fStringImpl, &osRC);
411
412 STAFException::checkRC(rc, "STAFStringToLowerCase", osRC);
413
414 return *this;
415 }
416
417
upperCase()418 STAF_INLINE STAFString &STAFString::upperCase()
419 {
420 unsigned int osRC = 0;
421 STAFRC_t rc = STAFStringToUpperCase(fStringImpl, &osRC);
422
423 STAFException::checkRC(rc, "STAFStringToUpperCase", osRC);
424
425 return *this;
426 }
427
428
strip(StripWhat stripWhat)429 STAF_INLINE STAFString &STAFString::strip(StripWhat stripWhat)
430 {
431 unsigned int osRC = 0;
432 STAFRC_t rc = STAFStringStripCharsOfType(fStringImpl, kUTF8_TYPE_WHITESPACE,
433 stripWhat, &osRC);
434
435 STAFException::checkRC(rc, "STAFStringStripCharsOfType", osRC);
436
437 return *this;
438 }
439
440
join(const STAFString stringArray[],unsigned int arraySize)441 STAF_INLINE STAFString &STAFString::join(const STAFString stringArray[],
442 unsigned int arraySize)
443 {
444 unsigned int osRC = 0;
445 STAFRC_t rc = kSTAFOk;
446
447 if (arraySize == 0) return *this;
448
449 STAFString_t temp = fStringImpl;
450 unsigned int joinArraySize = arraySize + 1;
451 STAFString_t *joinArray = new STAFString_t[joinArraySize];
452
453 joinArray[0] = fStringImpl;
454
455 for (unsigned int i = 1; i < joinArraySize; ++i)
456 {
457 joinArray[i] = stringArray[i - 1].getImpl();
458 }
459
460 rc = STAFStringConstructJoin(&fStringImpl, joinArray, joinArraySize, &osRC);
461
462 delete [] joinArray;
463
464 STAFException::checkRC(rc, "STAFStringConstructJoin", osRC);
465
466 STAFStringDestruct(&temp, 0);
467
468 return *this;
469 }
470
471
asUInt(unsigned int base) const472 STAF_INLINE unsigned int STAFString::asUInt(unsigned int base) const
473 {
474 unsigned int osRC = 0;
475 unsigned int theUInt = 0;
476 STAFRC_t rc = STAFStringToUInt(fStringImpl, &theUInt, base, &osRC);
477
478 STAFException::checkRC(rc, "STAFStringToUInt", osRC);
479
480 return theUInt;
481 }
482
483
asUIntWithDefault(unsigned int defaultValue,unsigned int base) const484 STAF_INLINE unsigned int STAFString::asUIntWithDefault(
485 unsigned int defaultValue, unsigned int base) const
486 {
487 unsigned int osRC = 0;
488 unsigned int theUInt = 0;
489 STAFRC_t rc = STAFStringToUInt(fStringImpl, &theUInt, base, &osRC);
490
491 if (rc == kSTAFInvalidValue)
492 return defaultValue;
493
494 STAFException::checkRC(rc, "STAFStringToUInt", osRC);
495
496 return theUInt;
497 }
498
499
500 /* XXX: Commented out until get UINT64_MAX working on Solaris
501 STAF_INLINE STAFUInt64_t STAFString::asUInt64(unsigned int base) const
502 {
503 unsigned int osRC = 0;
504 STAFUInt64_t theUInt64 = 0;
505 STAFRC_t rc = STAFStringToUInt64(fStringImpl, &theUInt64, base, &osRC);
506
507 STAFException::checkRC(rc, "STAFStringToUInt64", osRC);
508
509 return theUInt64;
510 }
511
512
513 STAF_INLINE STAFUInt64_t STAFString::asUInt64WithDefault(
514 STAFUInt64_t defaultValue, unsigned int base) const
515 {
516 unsigned int osRC = 0;
517 STAFUInt64_t theUInt64 = 0;
518 STAFRC_t rc = STAFStringToUInt64(fStringImpl, &theUInt64, base, &osRC);
519
520 if (rc == kSTAFInvalidValue)
521 return defaultValue;
522
523 STAFException::checkRC(rc, "STAFStringToUInt64", osRC);
524
525 return theUInt64;
526 }
527 */
528
529
toCurrentCodePage() const530 STAF_INLINE STAFStringBufferPtr STAFString::toCurrentCodePage() const
531 {
532 unsigned int osRC = 0;
533 char *theBuffer = 0;
534 unsigned int theLength = 0;
535 STAFRC_t rc = STAFStringToCurrentCodePage(fStringImpl, &theBuffer,
536 &theLength, &osRC);
537
538 STAFException::checkRC(rc, "STAFStringToCurrentCodePage", osRC);
539
540 return STAFStringBufferPtr(new STAFStringBuffer(theBuffer, theLength),
541 STAFStringBufferPtr::INIT);
542 }
543
544
toLowerCase() const545 STAF_INLINE STAFString STAFString::toLowerCase() const
546 {
547 unsigned int osRC = 0;
548 STAFString_t theCopy = 0;
549 STAFRC_t rc = STAFStringConstructCopy(&theCopy, fStringImpl, &osRC);
550
551 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
552
553 rc = STAFStringToLowerCase(theCopy, &osRC);
554
555 if (rc != 0) STAFStringDestruct(&theCopy, 0);
556
557 STAFException::checkRC(rc, "STAFStringToLowerCase", osRC);
558
559 return STAFString(theCopy, STAFString::kShallow);
560 }
561
562
toUpperCase() const563 STAF_INLINE STAFString STAFString::toUpperCase() const
564 {
565 unsigned int osRC = 0;
566 STAFString_t theCopy = 0;
567 STAFRC_t rc = STAFStringConstructCopy(&theCopy, fStringImpl, &osRC);
568
569 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
570
571 rc = STAFStringToUpperCase(theCopy, &osRC);
572
573 if (rc != 0) STAFStringDestruct(&theCopy, 0);
574
575 STAFException::checkRC(rc, "STAFStringToUpperCase", osRC);
576
577 return STAFString(theCopy, STAFString::kShallow);
578 }
579
580
replace(const STAFString oldstr,const STAFString newstr) const581 STAF_INLINE STAFString STAFString::replace(const STAFString oldstr,
582 const STAFString newstr) const
583 {
584 unsigned int osRC = 0;
585 STAFString_t theCopy = 0;
586 STAFRC_t rc = STAFStringConstructCopy(&theCopy, fStringImpl, &osRC);
587
588 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
589
590 rc = STAFStringReplace(theCopy, oldstr.getImpl(), newstr.getImpl(),
591 &osRC);
592
593 if (rc != kSTAFOk) STAFStringDestruct(&theCopy, 0);
594
595 STAFException::checkRC(rc, "STAFStringReplace", osRC);
596
597 return STAFString(theCopy, STAFString::kShallow);
598 }
599
600
isWhiteSpace() const601 STAF_INLINE bool STAFString::isWhiteSpace() const
602 {
603 unsigned int osRC = 0;
604 unsigned int compVal = 0;
605 STAFRC_t rc = STAFStringIsCharsOfType(fStringImpl, kUTF8_TYPE_WHITESPACE,
606 &compVal, &osRC);
607
608 STAFException::checkRC(rc, "STAFStringIsCharsOfType", osRC);
609
610 return compVal ? true : false;
611 }
612
613
isDigits() const614 STAF_INLINE bool STAFString::isDigits() const
615 {
616 unsigned int osRC = 0;
617 unsigned int compVal = 0;
618 STAFRC_t rc = STAFStringIsCharsOfType(fStringImpl, kUTF8_TYPE_DIGIT,
619 &compVal, &osRC);
620
621 STAFException::checkRC(rc, "STAFStringIsCharsOfType", osRC);
622
623 return compVal ? true : false;
624 }
625
626
isEqualTo(const STAFString & theString,STAFStringCaseSensitive_t caseSensitive) const627 STAF_INLINE bool STAFString::isEqualTo(const STAFString &theString,
628 STAFStringCaseSensitive_t caseSensitive) const
629 {
630 unsigned int osRC = 0;
631 unsigned int compVal = 0;
632
633 STAFRC_t rc = STAFStringIsEqualTo(fStringImpl, theString.fStringImpl,
634 caseSensitive, &compVal, &osRC);
635
636 STAFException::checkRC(rc, "STAFStringIsEqualTo", osRC);
637
638 return compVal ? true : false;
639 }
640
641
hasWildcard() const642 STAF_INLINE bool STAFString::hasWildcard() const
643 {
644 unsigned int osRC = 0;
645 unsigned int hasWildcard = 0;
646
647 STAFRC_t rc = STAFStringContainsWildcard(fStringImpl, &hasWildcard, &osRC);
648
649 STAFException::checkRC(rc, "STAFStringContainsWildcard", osRC);
650
651 return hasWildcard ? true : false;
652 }
653
654
startsWith(const STAFString & someString) const655 STAF_INLINE bool STAFString::startsWith(const STAFString &someString) const
656 {
657 unsigned int osRC = 0;
658 unsigned int doesStartWith = 0;
659
660 STAFRC_t rc = STAFStringStartsWith(fStringImpl, someString.fStringImpl,
661 &doesStartWith, &osRC);
662
663 STAFException::checkRC(rc, "STAFStringStartsWith", osRC);
664
665 return doesStartWith ? true : false;
666 }
667
668
matchesWildcards(const STAFString & wildcardString,STAFStringCaseSensitive_t caseSensitive) const669 STAF_INLINE bool STAFString::matchesWildcards(const STAFString &wildcardString,
670 STAFStringCaseSensitive_t caseSensitive) const
671 {
672 unsigned int osRC = 0;
673 unsigned int matches = 0;
674 STAFRC_t rc = STAFStringMatchesWildcards(fStringImpl,
675 wildcardString.fStringImpl,
676 caseSensitive, &matches, &osRC);
677
678 STAFException::checkRC(rc, "STAFStringMatchesWildcards", osRC);
679
680 return matches ? true : false;
681 }
682
683
operator =(const STAFString & rhs)684 STAF_INLINE STAFString &STAFString::operator=(const STAFString &rhs)
685 {
686 unsigned int osRC = 0;
687 STAFString_t newString = 0;
688 STAFRC_t rc = STAFStringConstructCopy(&newString, rhs.fStringImpl, &osRC);
689
690 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
691
692 STAFString_t temp = fStringImpl;
693
694 fStringImpl = newString;
695
696 STAFStringDestruct(&temp, 0);
697
698 return *this;
699 }
700
701
operator ==(const STAFString & rhs) const702 STAF_INLINE bool STAFString::operator==(const STAFString &rhs) const
703 {
704 return isEqualTo(rhs, kSTAFStringCaseSensitive);
705 }
706
707
operator !=(const STAFString & rhs) const708 STAF_INLINE bool STAFString::operator!=(const STAFString &rhs) const
709 {
710 return !isEqualTo(rhs, kSTAFStringCaseSensitive);
711 }
712
713
operator <(const STAFString & rhs) const714 STAF_INLINE bool STAFString::operator<(const STAFString &rhs) const
715 {
716 unsigned int osRC = 0;
717 unsigned int compVal = 0;
718 STAFRC_t rc = STAFStringCompareTo(fStringImpl, rhs.fStringImpl,
719 &compVal, &osRC);
720
721 STAFException::checkRC(rc, "STAFStringCompareTo", osRC);
722
723 return (compVal == 1);
724 }
725
726
operator <=(const STAFString & rhs) const727 STAF_INLINE bool STAFString::operator<=(const STAFString &rhs) const
728 {
729 return !(rhs < *this);
730 }
731
732
operator >(const STAFString & rhs) const733 STAF_INLINE bool STAFString::operator>(const STAFString &rhs) const
734 {
735 return (rhs < *this);
736 }
737
738
operator >=(const STAFString & rhs) const739 STAF_INLINE bool STAFString::operator>=(const STAFString &rhs) const
740 {
741 return !(*this < rhs);
742 }
743
744
operator +=(const STAFString & rhs)745 STAF_INLINE STAFString &STAFString::operator+=(const STAFString &rhs)
746 {
747 unsigned int osRC = 0;
748 STAFRC_t rc = STAFStringConcatenate(fStringImpl, rhs.fStringImpl, &osRC);
749
750 STAFException::checkRC(rc, "STAFStringConcatenate", osRC);
751
752 return *this;
753 }
754
operator +(const STAFString & lhs,const STAFString & rhs)755 STAF_INLINE STAFString operator+(const STAFString &lhs, const STAFString &rhs)
756 {
757 unsigned int osRC = 0;
758 STAFString_t newString = 0;
759 STAFRC_t rc = STAFStringConstructCopy(&newString, lhs.fStringImpl,
760 &osRC);
761
762 STAFException::checkRC(rc, "STAFStringConstructCopy", osRC);
763
764 rc = STAFStringConcatenate(newString, rhs.fStringImpl, &osRC);
765
766 if (rc != kSTAFOk) STAFStringDestruct(&newString, 0);
767
768 STAFException::checkRC(rc, "STAFStringConcatenate", osRC);
769
770 return STAFString(newString, STAFString::kShallow);
771 }
772
773
operator <<(ostream & os,const STAFString & rhs)774 STAF_INLINE ostream &operator<<(ostream &os, const STAFString &rhs)
775 {
776 STAFStringBufferPtr buf = rhs.toCurrentCodePage();
777
778 os << buf->buffer();
779
780 return os;
781 }
782
783
~STAFString()784 STAF_INLINE STAFString::~STAFString()
785 {
786 unsigned int osRC = 0;
787 if (fStringImpl) STAFStringDestruct(&fStringImpl, &osRC);
788 }
789
790 #endif
791