(file) Return to String.h CVS log (file) (dir) Up to [Pegasus] / pegasus / src / Pegasus / Common

Diff for /pegasus/src/Pegasus/Common/String.h between version 1.20 and 1.104

version 1.20, 2001/04/27 20:44:38 version 1.104, 2012/07/30 09:23:47
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM  // Licensed to The Open Group (TOG) under one or more contributor license
   // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
   // this work for additional information regarding copyright ownership.
   // Each contributor licenses this file to you under the OpenPegasus Open
   // Source License; you may not use this file except in compliance with the
   // License.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a // Permission is hereby granted, free of charge, to any person obtaining a
 // copy of this software and associated documentation files (the "Software"), // copy of this software and associated documentation files (the "Software"),
Line 9 
Line 14 
 // and/or sell copies of the Software, and to permit persons to whom the // and/or sell copies of the Software, and to permit persons to whom the
 // Software is furnished to do so, subject to the following conditions: // Software is furnished to do so, subject to the following conditions:
 // //
 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR  // The above copyright notice and this permission notice shall be included
 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,  // in all copies or substantial portions of the Software.
 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL  
 // THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER  
 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING  
 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER  
 // DEALINGS IN THE SOFTWARE.  
 //  
 //==============================================================================  
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
   // OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
   // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
   // IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
   // CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
   // TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
   // SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 // //
 // Modified By:  //////////////////////////////////////////////////////////////////////////
 // //
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_String_h #ifndef Pegasus_String_h
 #define Pegasus_String_h #define Pegasus_String_h
  
   #if defined PEGASUS_OS_HPUX && defined (HPUX_IA64_NATIVE_COMPILER)
   # include <iostream.h>
   #else
 #include <iostream> #include <iostream>
 #include <cstring>  #endif
 #include <Pegasus/Common/Config.h> #include <Pegasus/Common/Config.h>
 #include <Pegasus/Common/Char16.h> #include <Pegasus/Common/Char16.h>
 #include <Pegasus/Common/Array.h>  #include <Pegasus/Common/Linkage.h>
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
   class String;
   struct StringRep;
   
 /** /**
     The Pegasus String C++ Class implements the CIM string type.      The CString class provides access to an 8-bit String representation.
     This class is based on the general handle/representation pattern  
     defined for all the Pegasus objects.  However, it differes from  
     most in that it implements "copy on assign" all of the others implement  
     "no copy on assign" semantics.      The string class uses the Array class and  
     implements an array of characters.  
  */  */
 class PEGASUS_COMMON_LINKAGE String  class PEGASUS_COMMON_LINKAGE CString
 { {
 public: public:
  
     /** Default constructor without parameters. This constructor creates a      /**
         null string          Constructs a CString object with a null string value.
         <pre>  
             String test;  
         </pre>  
     */     */
     String();      CString();
   
       /**
           Constructs an independent copy of a CString object.
           @param cstr The CString instance to copy.
       */
       CString(const CString& cstr);
   
       /**
           Destructs a CString object.
       */
       ~CString();
   
       /**
           Copies the value of another CString object.
           @param cstr The CString object from which to copy the value.
           @return A reference to the target CString object with its newly
               assigned value.
       */
       CString& operator=(const CString& cstr);
   
       /**
           Gets the CString's data as a C string pointer.  IMPORTANT:  The
           returned pointer refers to memory owned by the CString object.  The
           caller must not free this memory.  The returned pointer is valid only
           until the CString object is destructed or reassigned.  Use of this
           operator on a temporary CString object may result in a memory error.
           For example, this usage is invalid:
  
     /// Copy constructor.              const char* cstr = String("Hello").getCString();
     String(const String& x);              printf(cstr);
  
     /// Initialize with first n characters from x.          @return Returns a const char pointer to the CString's data.
     String(const String& x, Uint32 n);      */
       operator const char*() const;
  
     /// Initialize with x.  private:
     String(const Char16* x);  
  
     /// Initialize with first n characters of x.      CString(char* cstr);
     String(const Char16* x, Uint32 n);  
  
     /// Initialize from a plain old C-String:      friend class String;
     String(const char* x);  
  
     /// Initialize from the first n characters of a plain old C-String:      char* _rep;
     String(const char* x, Uint32 n);  };
  
     /// String destructor. Used by the representation of the String object  /**
     ~String()      This class implements the CIM string type.  The intrinsic string format
       is UTF-16, which is a superset of the UCS-2 characters allowed in CIM
       strings.  Facilities are provided for converting to and from UTF-8
       character strings.
   
       Many of the method interfaces refer to a number of characters.  In all
       cases, these characters are counted as 8- or 16-bit memory chunks rather
       than logical UTF-8 or UTF-16 character chains.
   */
   class PEGASUS_COMMON_LINKAGE String
     {     {
     }  public:
  
     /** Assign this string with x.      /**
         <pre>          Represents an empty string.  This value may be used as a convenience
             String t1 = "abc";          to avoid construction of an empty String object.
             String t2 = t1;  
         </pre>  
     */     */
     String& operator=(const String& x) { _rep = x._rep; return *this; }      static const String EMPTY;
  
     /// Assign this string with x.      /**
     String& operator=(const Char16* x) { assign(x); return *this; }          Constructs an empty String.
       */
       String();
  
     /// Assign this string with x.      /**
     String& assign(const String& x) { _rep = x._rep; return *this; }          Constructs a String with the value of another String.
           @param str The String from which to copy the value.
       */
       String(const String& str);
  
     /// Assign this string with x.      /**
     String& assign(const Char16* x);          Constructs a String with a specified number of characters of the
           value of another String.
           @param str The String from which to copy the value.
           @param n A Uint32 specifying the number of characters to copy.
           @exception IndexOutOfBoundsException If the specified String does not
               contain the specified number of characters.
           @exception bad_alloc If the construction fails because of a memory
               allocation failure.
       */
       String(const String& str, Uint32 n);
  
     /// Assign this string with first n characters of x.      /**
     String& assign(const Char16* x, Uint32 n);          Constructs a String with the value from a Char16 buffer.
           @param str The Char16 buffer from which to copy the value.
           @exception NullPointer If the buffer pointer is NULL.
           @exception bad_alloc If the construction fails because of a memory
               allocation failure.
       */
       String(const Char16* str);
  
     /// Assign this string with the plain old C-String x.      /**
     String& assign(const char* x);          Constructs a String with a specified number of characters of the
           value from a Char16 buffer.
           @param str The Char16 buffer from which to copy the value.
           @param n A Uint32 specifying the number of characters to copy.
           @exception NullPointer If the buffer pointer is NULL.
           @exception bad_alloc If the construction fails because of a memory
               allocation failure.
       */
       String(const Char16* str, Uint32 n);
  
     /// Assign this string with first n characters of the plain old C-String x.      /**
     String& assign(const char* x, Uint32 n);          Constructs a String with the value from a C string in UTF-8 format.
           @param str The C string from which to copy the value.
           @exception NullPointer If the C string pointer is NULL.
           @exception bad_alloc If the construction fails because of a memory
               allocation failure.
           @exception Exception If the C string contains invalid UTF-8.
       */
       String(const char* str);
  
     /** Clear this string. After calling clear(), getLength() will return 0.      /**
         <pre>          Constructs a String with a specified number of characters of the
             String test = "abc";          value from a C string in UTF-8 format.
             test.clear();       // String test is now NULL (length == 0)          @param str The C string from which to copy the value.
         </pre>          @param n A Uint32 specifying the number of characters to copy.
           @exception NullPointer If the C string pointer is NULL.
           @exception bad_alloc If the construction fails because of a memory
               allocation failure.
           @exception Exception If the C string contains invalid UTF-8.
     */     */
     void clear() { _rep.clear(); _rep.append('\0'); }      String(const char* str, Uint32 n);
  
     /** Reserves memory for capacity characters. Notice that this does not      /**
         change the size of the string (getSize() returns what it did before).          Destructs a String object.
         If the capacity of the string is already greater or equal to the  
         capacity argument, this method has no effect. After calling reserve(),  
         getCapicty() returns a value which is greater or equal to the  
         capacity argument.  
         @param capacity defines the capacity in characters to reserve.  
     */     */
     void reserve(Uint32 capacity) { _rep.reserve(capacity + 1); }      ~String();
  
     /** Returns the length of the String object.      /**
         @return Length of the string in characters.          Assigns the value of a String to the value of another String.
         <pre>          @param str The String from which to copy the value.
             String s = "abcd";          @return A reference to the target String object with its newly
             assert(s.getLength() == 4);              assigned value.
         </pre>          @exception bad_alloc If the assignment fails because of a memory
               allocation failure.
     */     */
     Uint32 getLength() const { return _rep.getSize() - 1; }      String& operator=(const String& str);
  
     /** Returns a pointer to the first character in the null-terminated string      /**
         string.          Assigns the value of a String to the value of another String.
         @param          @param str The String from which to copy the value.
         @return Pointer to the first character of the String object          @return A reference to the target String object with its newly
         <pre>              assigned value.
             String t1 = "abc";          @exception bad_alloc If the assignment fails because of a memory
             const Char16* q = t1.getData();              allocation failure.
         </pre>  
     */     */
     const Char16* getData() const { return _rep.getData(); }      String& assign(const String& str);
  
     /** Allocates an 8 bit representation of this string. The user is      /**
         responsible for freeing the result. If any characters are truncated,          Assigns the value of a String to the value in a Char16 buffer.
         a TruncatedCharacter exception is thrown. This exception may          @param str The Char16 buffer from which to copy the value.
         be suppressed by passing true as the noThrow argument. Extra          @return A reference to the target String object with its newly
         characters may be allocated at the end of the new string by              assigned value.
         passing a non-zero value to the extraBytes argument.          @exception NullPointer If the buffer pointer is NULL.
         @param extraBytes -  Defines the number of extra characters to be          @exception bad_alloc If the assignment fails because of a memory
         allocated at the end of the new string. Default is zero.              allocation failure.
         @param  noThrow - If true, no exception will be thrown if characters  
         are truncated  
         @return pointer to the new representation of the string  
         @exception Throws TruncatedCharacter exception if any characters are  
         truncated  
         <pre>  
             String test = "abc";  
             char* p = test.allocateCString();  
         </pre>  
     */     */
     char* allocateCString(Uint32 extraBytes = 0, Boolean noThrow = false) const;      String& assign(const Char16* str);
  
     /** Append the given string to a C-string. If the length is not Uint32(-1),      /**
         then the lesser of the the length argument and the length of this          Assigns the value of a String with a specified number of characters
         string is truncated. Otherwise, the entire string is trunctated. The          of the value from a Char16 buffer.
         TruncatedCharacter exception is thrown if any characters are truncated.          @param str The Char16 buffer from which to copy the value.
         <pre>          @param n A Uint32 specifying the number of characters to copy.
             const char STR0[] = "one two three four";          @return A reference to the target String object with its newly
             String s = STR0;              assigned value.
             const char STR1[] = "zero ";          @exception NullPointer If the buffer pointer is NULL.
             char* tmp = new char[strlen(STR1) + s.getLength() + 1];          @exception bad_alloc If the assignment fails because of a memory
             strcpy(tmp, STR1);              allocation failure.
             s.appendToCString(tmp, 7);  
             assert(strcmp(tmp, "zero one two") == 0);  
         </pre>  
     */     */
     void appendToCString(      String& assign(const Char16* str, Uint32 n);
         char* str,  
         Uint32 length = Uint32(-1),      /**
         Boolean noThrow = false) const;          Assigns the value of a String to the value from a C string in UTF-8
           format.
     /** Returns the Ith character of the String object.          @param str The C string from which to copy the value.
         @exception - Throws exception "OutofBounds" if the index          @return A reference to the target String object with its newly
         is outside the length of the string.              assigned value.
         <pre>          @exception NullPointer If the C string pointer is NULL.
             String t1 = "abc;          @exception bad_alloc If the assignment fails because of a memory
             Char16 c = t1[1];   // character b              allocation failure.
         </pre>          @exception Exception If the C string contains invalid UTF-8.
     */     */
     Char16& operator[](Uint32 i);      String& assign(const char* str);
  
     /** Returns the Ith character of the String (const version).      /**
         @exception - Throws exception "OutofBounds" if the index          Assigns the value of a String with a specified number of characters
         is outside the length of the string.          of the value from a C string in UTF-8 format.
           @param str The C string from which to copy the value.
           @param n A Uint32 specifying the number of characters to copy.
           @return A reference to the target String object with its newly
               assigned value.
           @exception NullPointer If the C string pointer is NULL.
           @exception bad_alloc If the assignment fails because of a memory
               allocation failure.
           @exception Exception If the C string contains invalid UTF-8.
       */
       String& assign(const char* str, Uint32 n);
  
       /**
           Sets a String value to the empty String.
     */     */
     const Char16 operator[](Uint32 i) const;      void clear();
  
     /** Append the given character to the string.      /**
         <pre>          Reserves memory for a specified number of (16-bit) characters.
              String s4 = "Hello";          This method does not change the size() of the string or any other
             s4.append(Char16(0x0000))          external behavior.  If the capacity of the string is already greater
         </pre>          than or equal to the specified size, this method has no effect.  The
           capacity of a String is set only for performance reasons.
           @param capacity A Uint32 specifying the number of characters the
               String should be prepared to hold.
     */     */
     String& append(const Char16& c)      void reserveCapacity(Uint32 capacity);
     {  
         _rep.insert(_rep.getSize() - 1, c);  
         return *this;  
     }  
  
     /// Append n characters from str to this String object.      /**
     String& append(const Char16* str, Uint32 n);          Returns the number of characters in a String value.  No termination
           character is included in the count.  For example, String("abcd").size()
           returns 4.
       */
       Uint32 size() const;
  
     /// Append the characters of str to this String object.      /**
     String& append(const String& str)          Gets a null-terminated Char16 buffer containing the String value.
     {          The buffer is valid until the original String object is modified or
         return append(str.getData(), str.getLength());          destructed.
     }          @return A pointer to a null-terminated Char16 buffer containing the
               String value.
       */
       const Char16* getChar16Data() const;
  
     /** Overload operator += appends the parameter String to this String.      /**
         @parm String to append.          Gets a CString object containing the String value in UTF-8 format.
         @return This String          Important:  A character pointer extracted from a CString object is
         <pre>          only valid while the CString object exists and is unmodified.  (See
         String test = "abc";          the CString documentation.)  Thus, in the following example, the
         test += "def";          variable p holds a dangling (invalid) pointer:
         assert(test == "abcdef");          <pre>
         </pre>                const char * p = (const char *)test.getCString();
           </pre>
           This situation can be corrected by declaring a CString variable in
           the same scope.
   
           @return A CString object containing the String value in UTF-8 format.
           @exception bad_alloc If the operation fails because of a memory
               allocation failure.
     */     */
     String& operator+=(const String& x)      CString getCString() const;
     {  
         return append(x);  
     }  
  
     /** Append the character given by c to this String object.      /**
         @param c - Single character          Gets a specified character from the String value.
           @param index Index of the character to access.
           @return The Char16 character at the specified index.
           @exception IndexOutOfBoundsException If the String does not contain a
               character at the specified index.
     */     */
     String& operator+=(Char16 c)      Char16& operator[](Uint32 index);
     {  
         return append(c);  
     }  
  
     /** Append the character given by c to this string.      /**
         <pre>          Gets a specified character from the String value.
             String t1 = "abc";          @param index Index of the character to access.
             t1 += 'd'          @return The Char16 character at the specified index.
             assert(t1 == "abcd");          @exception IndexOutOfBoundsException If the String does not contain a
         </pre>              character at the specified index.
     */     */
     String& operator+=(char c)      const Char16 operator[](Uint32 index) const;
     {  
         return append(Char16(c));  
     }  
  
     /** Remove size characters from the string starting at the given      /**
         position. If size is -1, then all characters after pos are removed.          Appends a character to the String.
         @param pos - Position in string to start remove          @param c The Char16 character to append.
         @param size - Number of characters to remove. Default is -1 which          @return A reference to the String object containing the newly appended
         causes all characters after pos to be removed              character.
         <pre>          @exception bad_alloc If the append fails because of a memory
             String s;              allocation failure.
             s = "abc";  
             s.remove(0, 1);  
             assert(String::equal(s, "bc"));  
             assert(s.getLength() == 2);  
             s.remove(0);  
             assert(String::equal(s, ""));  
             assert(s.getLength() == 0);  
         </pre>  
         @exception throws "OutOfBounds" exception if size is greater than  
         length of String plus starting position for remove.  
     */     */
     void remove(Uint32 pos, Uint32 size = Uint32(-1));      String& append(const Char16& c);
  
     /** Return a new String which is initialzed with <TT>length</TT>      /**
         characters from this string starting at <TT>pos</TT>.          Appends a specified number of characters to the String from a Char16
         @param <TT>pos</TT> is the positon in string to start getting the          buffer.
         substring.          @param str The Char16 buffer from which to append the characters.
         @param <TT>length</TT> is the number of characters to get. If length          @param n A Uint32 specifying the number of characters to append from
         is -1, then all characters after pos are added to the new string.              the buffer.
         @return String with the defined substring.          @return A reference to the String object containing the newly appended
         <pre>              characters.
             s = "abcdefg";          @exception NullPointer If the buffer pointer is NULL.
             s.remove(3);          @exception bad_alloc If the append fails because of a memory
             assert(String::equal(s, "abc"));              allocation failure.
         </pre>  
     */     */
     String subString(Uint32 pos, Uint32 length = Uint32(-1)) const;      String& append(const Char16* str, Uint32 n);
  
     /** Find the position of the first occurence of the character c.      /**
         If the character is not found, -1 is returned.          Appends a String value to the String.
         @param c -  Char to be found in the String          @param str The String to append.
         @return Position of the character in the string or -1 if not found.          @return A reference to the String object containing the newly appended
               characters.
           @exception bad_alloc If the append fails because of a memory
               allocation failure.
     */     */
     Uint32 find(Char16 c) const;      String& append(const String& str);
  
     /** Find the position of the first occurence of the string object.      /**
         This function finds one string inside another          Removes a specified number of characters from the String starting at a
         If the matching substring is not found, -1 is returned.          given index.  If the number of characters to remove is specified as
         @param s -  String object to be found in the String          PEG_NOT_FOUND, then all characters from the index to the end of the
         @return Position of the substring in the String or -1 if not          String are removed.
         found.          @param index Uint32 position in String from which to remove characters.
           @param size A Uint32 specifying the number of characters to remove.
               The default value is PEG_NOT_FOUND, which means all characters
               from the index to the end of the String are to be removed.
           @exception IndexOutOfBoundsException If the index plus the size (if not
               PEG_NOT_FOUND) is greater than the number of characters in the
               String.
     */     */
     Uint32 find(const String& s) const;      void remove(Uint32 index, Uint32 size = PEG_NOT_FOUND);
  
     /** Find substring      /**
         @ param - 16 bit character pointer          Creates a new String containing up to the specified number of
         @seealso find          characters from the specified index in the String.
           @param index A Uint32 specifying the index at which to copy characters
               into the new String.
           @param n A Uint32 specifying the maximum number of characters to copy
               into the new String.  If the value is PEG_NOT_FOUND or is greater
               than the number of characters from the index to the end of the
               String, the new String contains all characters from the index to
               the end of the String.
           @return A new String containing up to the specified number of
               characters from the specified index in the String.
           @exception bad_alloc If the operation fails because of a memory
               allocation failure.
     */     */
     Uint32 find(const Char16* s) const;      String subString(Uint32 index, Uint32 n = PEG_NOT_FOUND) const;
  
     /** find substring      /**
         @param char* to substring          Finds the index of the first occurrence of a specified character in
           the String.  If the character is not found, PEG_NOT_FOUND is returned.
           @param c The Char16 value to find in the String.
           @return The Uint32 index of the character in the String if found,
               PEG_NOT_FOUND otherwise.
     */     */
     Uint32 find(const char* s) const;      Uint32 find(Char16 c) const;
   
       /**
           Finds the index of the first occurrence of a specified character in
           the String beginning at a specified index.  If the character is not
           found, PEG_NOT_FOUND is returned.
           @param c The Char16 value to find in the String.
           @param index The Uint32 index at which to start the search.
           @return The Uint32 index of the character in the String if found,
               PEG_NOT_FOUND otherwise.
       */
       Uint32 find(Uint32 index, Char16 c) const;
  
     /** Same as find() but start looking in reverse (last character first).      /**
         @Seealso find          Finds the index of the first occurrence of a specified String value in
         @return Position of the character in the string or -1 if not found.          the String.  If the String value is not found, PEG_NOT_FOUND is
           returned.
           @param s The String value to find in the String.
           @return The Uint32 index of the beginning of the String value if found,
               PEG_NOT_FOUND otherwise.
       */
       Uint32 find(const String& s) const;
  
         NOTE: This function is defined only for char* input, not for      /**
         String.          Finds the index of the last occurrence of a specified character in
           the String.  If the character is not found, PEG_NOT_FOUND is returned.
           @param c The Char16 value to find in the String.
           @return The Uint32 index of the character in the String if found,
               PEG_NOT_FOUND otherwise.
     */     */
     Uint32 reverseFind(Char16 c) const;     Uint32 reverseFind(Char16 c) const;
  
     /** Converts all characters in this string to lower case.      /**
           Converts all characters in the String to lower case.
     */     */
     void toLower();     void toLower();
  
     /** Compare the first n characters of the two strings.  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
         @param s1 - First null-terminated string for the comparison      /**
         @param s2 - Second null-terminated string for the comparison          <I><B>Experimental Interface</B></I><BR>
         @param n - Number of characters to compare          Converts all characters in the String to upper case.
         @return Return -1 if s1 is lexographically less than s2. If they      */
         are equavalent return 0. Otherwise return 1.      void toUpper();
     */  #endif
     static int compare(const Char16* s1, const Char16* s2, Uint32 n);  
   
     /** Compare two null-terminated strings.  
         @param s1 - First null-terminated string for the comparison  
         @param s2 - Second null-terminated string for the comparison  
         @return If s1 is less than s2, return -1; if equal return 0;  
         otherwise, return 1.  
   
         NOTE: Use the comparison operators <,<= > >= to compare  
         String objects.  
     */  
     static int compare(const Char16* s1, const Char16* s2);  
   
     /** Compare two String objects for equality.  
         @param s1 - First <TT>String</TT> for comparison.  
         @param s2 - Second <TT>String</TT> for comparison.  
  
         @return Boolean true if the two strings are equal.      /**
           Compares the first n characters of two String objects.
           @param s1 The first String to compare.
           @param s2 The second String to compare.
           @param n The maximum number of characters to compare.
           @return A negative integer if the first n characters of s1 are
               lexographically less than s2, 0 if the first n characters of s1
               and s2 are equal, and a positive integer otherwise.
       */
       static int compare(const String& s1, const String& s2, Uint32 n);
   
       /**
           Compares two String objects.  (Note: Use the comparison
           operators < <= > >= to compare String objects.)
           @param s1 The first String to compare.
           @param s2 The second String to compare.
           @return A negative integer if s1 is lexographically less than s2,
               0 if s1 and s2 are equal, and a positive integer otherwise.
       */
       static int compare(const String& s1, const String& s2);
   
       /**
           Compares two String objects, ignoring case differences.
           @param s1 The first String to compare.
           @param s2 The second String to compare.
           @return A negative integer if s1 is lexographically less than s2,
               0 if s1 and s2 are equal, and a positive integer otherwise.
               (Case differences are ignored in all cases.)
       */
       static int compareNoCase(const String& s1, const String& s2);
   
       /**
           Compares two String objects for equality.  For example,
         <pre>         <pre>
             String s1 = "Hello World";             String s1 = "Hello World";
             String s2 = s1;             String s2 = s1;
             String s3(s2);              assert(String::equal(s1, s2));
             assert(String::equal(s1, s3));  
         </pre>         </pre>
           @param s1 The first String to compare.
           @param s2 The second String to compare.
           @return True if the two strings are equal, false otherwise.
     */     */
     static Boolean equal(const String& x, const String& y);      static Boolean equal(const String& s1, const String& s2);
  
     /// Return true if the two strings are equal.      /**
     static Boolean equal(const String& x, const Char16* y);          Compares two strings and returns true if they are equal independent of
           the case of the characters.
           @param s1 The first String to compare.
           @param s2 The second String to compare.
           @return true if the strings are equal independent of case, false
               otherwise.
       */
       static Boolean equalNoCase(const String& s1, const String& s2);
  
     /// Return true if the two strings are equal.  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
     static Boolean equal(const Char16* x, const String& y);  
  
     /// Return true if the two strings are equal.      String(const String& s1, const String& s2);
     static Boolean equal(const String& x, const char* y);  
  
     /// Return true if the two strings are equal.      String(const String& s1, const char* s2);
     static Boolean equal(const char* x, const String& y);  
  
     static Boolean equalIgnoreCase(const String& x, const String& y);      String(const char* s1, const String& s2);
  
     /// Convert the plain old C-string to lower case:      String& operator=(const char* str);
     static void toLower(char* str);  
  
     /** EMPTY - Represent an empty string.      Uint32 find(const char* s) const;
         This member is used to represent empty strings. Using this member  
         avoids an expensive construction of an empty string (e.g., String()).  
     */  
     static const String EMPTY;  
  
 private:      static Boolean equal(const String& s1, const char* s2);
  
     static Uint32 _min(Uint32 x, Uint32 y) { return x < y ? x : y; }      static int compare(const String& s1, const char* s2);
  
     Array<Char16> _rep;      String& append(const char* str);
 };  
  
 /** String operator ==. Test for equality between two strings of any of the      String& append(const char* str, Uint32 size);
     types String or char*.  
     @return Boolean - True if the strings are equal  
  
 */      static Boolean equalNoCase(const String& s1, const char* s2);
 inline Boolean operator==(const String& x, const String& y)  
 {  
     return String::equal(x, y);  
 }  
  
 /** String operator ==. Test for equality between two strings  #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
  
 */  private:
 inline Boolean operator==(const String& x, const char* y)  
 {  
     return String::equal(x, y);  
 }  
  
 /** String operator ==. Test for equality between two strings      StringRep* _rep;
   };
  
 */  /**
 inline Boolean operator==(const char* x, const String& y)      Compares two String objects for equality.
 {      @param str1 The first String to compare.
     return String::equal(x, y);      @param str2 The second String to compare.
 }      @return True if the strings are equal, false otherwise.
   */
   PEGASUS_COMMON_LINKAGE Boolean operator==(
       const String& str1,
       const String& str2);
  
 /** String operator ==. Test for equality between two strings  /**
       Compares a String and a C string for equality.
       @param str1 The String to compare.
       @param str2 The C string to compare.
       @return True if the strings are equal, false otherwise.
   */
   PEGASUS_COMMON_LINKAGE Boolean operator==(const String& str1, const char* str2);
  
   /**
       Compares a String and a C string for equality.
       @param str1 The C string to compare.
       @param str2 The String to compare.
       @return True if the strings are equal. false otherwise.
 */ */
 inline Boolean operator!=(const String& x, const String& y)  PEGASUS_COMMON_LINKAGE Boolean operator==(const char* str1, const String& str2);
 {  
     return !String::equal(x, y);  
 }  
  
 PEGASUS_COMMON_LINKAGE std::ostream& operator<<(  /**
     std::ostream& os,      Compares two String objects for inequality.
     const String& x);      @param str1 The first String to compare.
       @param str2 The second String to compare.
       @return False if the strings are equal, true otherwise.
   */
   PEGASUS_COMMON_LINKAGE Boolean operator!=(
       const String& str1,
       const String& str2);
  
 /** overload operator +  - Concatenates String objects.  /**
       Writes a String value to an output stream.  Characters with a zero value or
       with a non-zero high-order byte are written in a hexadecimal encoding.
       @param os The output stream to which the String value is written.
       @param str The String to write to the output stream.
       @return A reference to the output stream.
   */
   PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
       PEGASUS_STD(ostream)& os,
       const String& str);
  
   /**
       Concatenates String objects. For example,
     <pre>     <pre>
         String t1 = "abc";         String t1 = "abc";
         String t2;         String t2;
         t2 = t1 + "def"         t2 = t1 + "def"
         assert(t2 == "abcdef");         assert(t2 == "abcdef");
     </pre>     </pre>
       @param str1 The first String to concatenate.
       @param str2 The second String to concatenate.
       @return The concatenated String.
 */ */
 inline String operator+(const String& x, const String& y)  PEGASUS_COMMON_LINKAGE String operator+(const String& str1, const String& str2);
 {  
     return String(x).append(y);  
 }  
  
 /** overload operator < - Compares String obects.  /**
     <pre>      Compares two String objects.
         String t1 = "def";      @param s1 The first String to compare.
         String t2 = "a";      @param s2 The second String to compare.
         assert (t2 < t1);      @return True if s1 is lexographically less than s2, false otherwise.
     </pre>  */
 */  PEGASUS_COMMON_LINKAGE Boolean operator<(
 inline Boolean operator<(const String& x, const String& y)      const String& str1,
 {      const String& str2);
     return String::compare(x.getData(), y.getData()) < 0;  
 }  
  
 /** overload operator <= compares String objects.  /**
       Compares two String objects.
       @param s1 The first String to compare.
       @param s2 The second String to compare.
       @return True if s1 is lexographically less than or equal to s2,
           false otherwise.
   */
   PEGASUS_COMMON_LINKAGE Boolean operator<=(
       const String& str1,
       const String& str2);
  
 */  /**
 inline Boolean operator<=(const String& x, const String& y)      Compares two String objects.
 {      @param s1 The first String to compare.
     return String::compare(x.getData(), y.getData()) <= 0;      @param s2 The second String to compare.
 }      @return True if s1 is lexographically greater than s2, false otherwise.
   */
   PEGASUS_COMMON_LINKAGE Boolean operator>(
       const String& str1,
       const String& str2);
  
 /** Overload operator > compares String objects  /**
       Compares two String objects.
       @param s1 The first String to compare.
       @param s2 The second String to compare.
       @return True if s1 is lexographically greater than or equal to s2,
           false otherwise.
 */ */
 inline Boolean operator>(const String& x, const String& y)  PEGASUS_COMMON_LINKAGE Boolean operator>=(
 {      const String& str1,
     return String::compare(x.getData(), y.getData()) > 0;      const String& str2);
 }  
  
 /** overload operator >= - Compares String objects  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
 */  
 inline Boolean operator>=(const String& x, const String& y)  
 {  
     return String::compare(x.getData(), y.getData()) >= 0;  
 }  
  
 /** Return a version of this string whose characters have been shifted  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2);
     to lower case.  
 */  
 PEGASUS_COMMON_LINKAGE String ToLower(const String& str);  
  
 /** Compare two strings but ignore any case differences.  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const char* s2);
 */  
 PEGASUS_COMMON_LINKAGE int CompareIgnoreCase(const char* s1, const char* s2);  
  
 /** Get the next line from the input file.  PEGASUS_COMMON_LINKAGE Boolean operator==(const char* s1, const String& s2);
 */  
 PEGASUS_COMMON_LINKAGE Boolean GetLine(std::istream& is, String& line);  
  
 /*  This is an internal class not to be used by the internal Pegasus  PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const String& s2);
     components only. It provides an easy way to create an 8-bit string  
     representation on the fly without calling allocateCString() and  
     then worrying about deleting the string. The underscore before the  
     class name denotes that this class is internal, unsupported, undocumented,  
     and may be removed in future releases.  
 */  
 class _CString  
 {  
 public:  
  
     _CString(const String& x)  PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const char* s2);
     {  
         _rep = x.allocateCString();  
     }  
  
     _CString(const _CString& x)  PEGASUS_COMMON_LINKAGE Boolean operator!=(const char* s1, const String& s2);
     {  
         _rep = strcpy(new char[strlen(x._rep) + 1], x._rep);  
     }  
  
     ~_CString()  PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const String& s2);
     {  
         delete [] _rep;  
     }  
  
     _CString& operator=(const _CString& x)  PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const char* s2);
     {  
         if (this != &x)  
             _rep = strcpy(new char[strlen(x._rep) + 1], x._rep);  
  
         return *this;  PEGASUS_COMMON_LINKAGE Boolean operator<(const char* s1, const String& s2);
     }  
  
     operator const char*() const  PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const String& s2);
     {  
         return _rep;  
     }  
  
     const char* data() const  PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const char* s2);
     {  
         return _rep;  
     }  
  
 private:  PEGASUS_COMMON_LINKAGE Boolean operator>(const char* s1, const String& s2);
  
     char* _rep;  PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const String& s2);
 };  
   PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const char* s2);
   
   PEGASUS_COMMON_LINKAGE Boolean operator<=(const char* s1, const String& s2);
   
   PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const String& s2);
   
   PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const char* s2);
   
   PEGASUS_COMMON_LINKAGE Boolean operator>=(const char* s1, const String& s2);
   
   PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const String& s2);
   
   PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const char* s2);
   
   PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2);
   
   #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
  
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
   #if defined(PEGASUS_INTERNALONLY)
   # include "StringInline.h"
   #endif
   
 #endif /* Pegasus_String_h */ #endif /* Pegasus_String_h */


Legend:
Removed from v.1.20  
changed lines
  Added in v.1.104

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2