String.h
1 //%LICENSE////////////////////////////////////////////////////////////////
2 //
3 // Licensed to The Open Group (TOG) under one or more contributor license
4 // agreements. Refer to the OpenPegasusNOTICE.txt file distributed with
5 // this work for additional information regarding copyright ownership.
6 // Each contributor licenses this file to you under the OpenPegasus Open
7 // Source License; you may not use this file except in compliance with the
8 // License.
9 //
10 // Permission is hereby granted, free of charge, to any person obtaining a
11 // copy of this software and associated documentation files (the "Software"),
12 // to deal in the Software without restriction, including without limitation
13 // the rights to use, copy, modify, merge, publish, distribute, sublicense,
14 // and/or sell copies of the Software, and to permit persons to whom the
15 // Software is furnished to do so, subject to the following conditions:
16 //
17 // The above copyright notice and this permission notice shall be included
18 // in all copies or substantial portions of the Software.
19 //
20 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21 // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
23 // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
24 // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
25 // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
26 // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 //
29 //
30 //%/////////////////////////////////////////////////////////////////////////////
31 
32 #ifndef Pegasus_String_h
33 #define Pegasus_String_h
34 
35 #ifdef PEGASUS_OS_HPUX
36 # ifdef HPUX_IA64_NATIVE_COMPILER
37 # include <iostream>
38 # else
39 # include <iostream.h>
40 # endif
41 #else
42 # include <iostream>
43 #endif
44 #include <Pegasus/Common/Config.h>
45 #include <Pegasus/Common/Char16.h>
46 #include <Pegasus/Common/Linkage.h>
47 #include <cstdarg>
48 
49 PEGASUS_NAMESPACE_BEGIN
50 
51 class String;
52 struct StringRep;
53 
57 class PEGASUS_COMMON_LINKAGE CString
58 {
59 public:
60 
64  CString();
65 
70  CString(const CString& cstr);
71 
75  ~CString();
76 
83  CString& operator=(const CString& cstr);
84 
98  operator const char*() const;
99 
100 private:
101 
102  CString(char* cstr);
103 
104  friend class String;
105 
106  char* _rep;
107 };
108 
119 class PEGASUS_COMMON_LINKAGE String
120 {
121 public:
122 
127  static const String EMPTY;
128 
132  String();
133 
138  String(const String& str);
139 
150  String(const String& str, Uint32 n);
151 
159  String(const Char16* str);
160 
170  String(const Char16* str, Uint32 n);
171 
180  String(const char* str);
181 
192  String(const char* str, Uint32 n);
193 
197  ~String();
198 
207  String& operator=(const String& str);
208 
217  String& assign(const String& str);
218 
228  String& assign(const Char16* str);
229 
241  String& assign(const Char16* str, Uint32 n);
242 
254  String& assign(const char* str);
255 
268  String& assign(const char* str, Uint32 n);
269 
273  void clear();
274 
284  void reserveCapacity(Uint32 capacity);
285 
291  Uint32 size() const;
292 
300  const Char16* getChar16Data() const;
301 
318  CString getCString() const;
319 
327  Char16& operator[](Uint32 index);
328 
336  const Char16 operator[](Uint32 index) const;
337 
346  String& append(const Char16& c);
347 
360  String& append(const Char16* str, Uint32 n);
361 
370  String& append(const String& str);
371 
385  void remove(Uint32 index, Uint32 size = PEG_NOT_FOUND);
386 
402  String subString(Uint32 index, Uint32 n = PEG_NOT_FOUND) const;
403 
411  Uint32 find(Char16 c) const;
412 
422  Uint32 find(Uint32 index, Char16 c) const;
423 
432  Uint32 find(const String& s) const;
433 
441  Uint32 reverseFind(Char16 c) const;
442 
446  void toLower();
447 
458  PEGASUS_FORMAT(2,3)
459  void appendPrintf(const char* format, ...);
460 
461 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
462 
466  void toUpper();
467 #endif
468 
478  static int compare(const String& s1, const String& s2, Uint32 n);
479 
488  static int compare(const String& s1, const String& s2);
489 
498  static int compareNoCase(const String& s1, const String& s2);
499 
511  static Boolean equal(const String& s1, const String& s2);
512 
518  static Boolean equalNoCase(const String& s1, const String& s2);
519 
520 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
521 
522  String(const String& s1, const String& s2);
523 
524  String(const String& s1, const char* s2);
525 
526  String(const char* s1, const String& s2);
527 
528  String& operator=(const char* str);
529 
530  Uint32 find(const char* s) const;
531 
532  static Boolean equal(const String& s1, const char* s2);
533 
534  static int compare(const String& s1, const char* s2);
535 
536  String& append(const char* str);
537 
538  String& append(const char* str, Uint32 size);
539 
540  static Boolean equalNoCase(const String& s1, const char* s2);
541 
542 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
543 
544 private:
545 
546  StringRep* _rep;
547 };
548 
555 PEGASUS_COMMON_LINKAGE Boolean operator==(
556  const String& str1,
557  const String& str2);
558 
565 PEGASUS_COMMON_LINKAGE Boolean operator==(const String& str1, const char* str2);
566 
573 PEGASUS_COMMON_LINKAGE Boolean operator==(const char* str1, const String& str2);
574 
581 PEGASUS_COMMON_LINKAGE Boolean operator!=(
582  const String& str1,
583  const String& str2);
584 
592 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
593  PEGASUS_STD(ostream)& os,
594  const String& str);
595 
608 PEGASUS_COMMON_LINKAGE String operator+(const String& str1, const String& str2);
609 
616 PEGASUS_COMMON_LINKAGE Boolean operator<(
617  const String& str1,
618  const String& str2);
619 
627 PEGASUS_COMMON_LINKAGE Boolean operator<=(
628  const String& str1,
629  const String& str2);
630 
637 PEGASUS_COMMON_LINKAGE Boolean operator>(
638  const String& str1,
639  const String& str2);
640 
648 PEGASUS_COMMON_LINKAGE Boolean operator>=(
649  const String& str1,
650  const String& str2);
651 
652 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
653 
654 PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2);
655 
656 PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const char* s2);
657 
658 PEGASUS_COMMON_LINKAGE Boolean operator==(const char* s1, const String& s2);
659 
660 PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const String& s2);
661 
662 PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const char* s2);
663 
664 PEGASUS_COMMON_LINKAGE Boolean operator!=(const char* s1, const String& s2);
665 
666 PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const String& s2);
667 
668 PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const char* s2);
669 
670 PEGASUS_COMMON_LINKAGE Boolean operator<(const char* s1, const String& s2);
671 
672 PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const String& s2);
673 
674 PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const char* s2);
675 
676 PEGASUS_COMMON_LINKAGE Boolean operator>(const char* s1, const String& s2);
677 
678 PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const String& s2);
679 
680 PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const char* s2);
681 
682 PEGASUS_COMMON_LINKAGE Boolean operator<=(const char* s1, const String& s2);
683 
684 PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const String& s2);
685 
686 PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const char* s2);
687 
688 PEGASUS_COMMON_LINKAGE Boolean operator>=(const char* s1, const String& s2);
689 
690 PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const String& s2);
691 
692 PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const char* s2);
693 
694 PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2);
695 
696 #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
697 
698 PEGASUS_NAMESPACE_END
699 
700 #if defined(PEGASUS_INTERNALONLY)
701 # include "StringInline.h"
702 #endif
703 
704 #endif /* Pegasus_String_h */
Definition: String.h:119
Definition: String.h:57
static const String EMPTY
Definition: String.h:127
Definition: Char16.h:47