(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.39.2.6 and 1.105

version 1.39.2.6, 2001/08/22 08:11:08 version 1.105, 2012/08/14 14:55:28
Line 1 
Line 1 
 //%/////////////////////////////////////////////////////////////////////////////  //%LICENSE////////////////////////////////////////////////////////////////
 //  
 // Copyright (c) 2000, 2001 The Open group, BMC Software, Tivoli Systems, IBM  
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy  // Licensed to The Open Group (TOG) under one or more contributor license
 // of this software and associated documentation files (the "Software"), to  // agreements.  Refer to the OpenPegasusNOTICE.txt file distributed with
 // deal in the Software without restriction, including without limitation the  // this work for additional information regarding copyright ownership.
 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or  // Each contributor licenses this file to you under the OpenPegasus Open
 // sell copies of the Software, and to permit persons to whom the Software is  // Source License; you may not use this file except in compliance with the
 // furnished to do so, subject to the following conditions:  // License.
 // //
 // THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN  // Permission is hereby granted, free of charge, to any person obtaining a
 // ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED  // copy of this software and associated documentation files (the "Software"),
 // "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT  // to deal in the Software without restriction, including without limitation
 // LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR  // the rights to use, copy, modify, merge, publish, distribute, sublicense,
 // PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT  // and/or sell copies of the Software, and to permit persons to whom the
 // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN  // Software is furnished to do so, subject to the following conditions:
 // 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.  
 // //
 //==============================================================================  // The above copyright notice and this permission notice shall be included
   // in all copies or substantial portions of 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
  
   #ifdef PEGASUS_OS_HPUX
   # ifdef HPUX_IA64_NATIVE_COMPILER
 #include <iostream> #include <iostream>
 #include <fstream>  # else
 #include <cstring>  #  include <iostream.h>
   # endif
   #else
   # include <iostream>
   #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();
   
     /// Copy constructor.  
     String(const String& x);  
   
     /// Initialize with first n characters from x.  
     String(const String& x, Uint32 n);  
   
     /// Initialize with x.  
     String(const Char16* x);  
   
     /// Initialize with first n characters of x.  
     String(const Char16* x, Uint32 n);  
  
     /// Initialize from a plain old C-String:      /**
     String(const char* x);          Constructs an independent copy of a CString object.
           @param cstr The CString instance to copy.
     /// Initialize from the first n characters of a plain old C-String:      */
     String(const char* x, Uint32 n);      CString(const CString& cstr);
  
     /// String destructor. Used by the representation of the String object      /**
     ~String();          Destructs a CString object.
       */
       ~CString();
  
     /** Assign this string with x.      /**
         <pre>          Copies the value of another CString object.
             String t1 = "abc";          @param cstr The CString object from which to copy the value.
             String t2 = t1;          @return A reference to the target CString object with its newly
         </pre>              assigned value.
     */     */
     String& operator=(const String& x) { return assign(x); }      CString& operator=(const CString& cstr);
  
     /// Assign this string with Char16 x.      /**
     String& operator=(const Char16* x) { assign(x); return *this; }          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:
   
               const char* cstr = String("Hello").getCString();
               printf(cstr);
  
     /** Assign this string with String x          @return Returns a const char pointer to the CString's data.
     @param x String to assign  
     @return Returns the String  
     */     */
     String& assign(const String& x);      operator const char*() const;
  
     /// Assign this string with x.  private:
     String& assign(const Char16* x);  
  
     /// Assign this string with first n characters of x.      CString(char* cstr);
     String& assign(const Char16* x, Uint32 n);  
  
     /// Assign this string with the plain old C-String x.      friend class String;
     String& assign(const char* x);  
  
     /// Assign this string with first n characters of the plain old C-String x.      char* _rep;
     String& assign(const char* x, Uint32 n);  };
  
     /** clear - Clear this string. After calling clear(), size() will return 0.  /**
         <pre>      This class implements the CIM string type.  The intrinsic string format
             String test = "abc";      is UTF-16, which is a superset of the UCS-2 characters allowed in CIM
             test.clear();       // String test is now NULL (length == 0)      strings.  Facilities are provided for converting to and from UTF-8
         </pre>      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.
     */     */
     void clear();  class PEGASUS_COMMON_LINKAGE String
   {
   public:
  
     /** reserve - Reserves memory for capacity characters. Notice that this does      /**
     not          Represents an empty string.  This value may be used as a convenience
         change the size of the string (size() returns what it did before).          to avoid construction of an empty 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);      static const String EMPTY;
  
     /** Returns the length of the String object.      /**
         @return Length of the string in characters.          Constructs an empty String.
         <pre>  
             String s = "abcd";  
             assert(s.size() == 4);  
         </pre>  
     */     */
     Uint32 size() const { return _rep.size() - 1; }      String();
  
     /** getData Returns a pointer to the first character in the      /**
         null-terminated string string of the String object.          Constructs a String with the value of another String.
         @return Pointer to the first character of the String object          @param str The String from which to copy the value.
         <pre>  
             String t1 = "abc";  
             const Char16* q = t1.getData();  
         </pre>  
     */     */
     const Char16* getData() const { return _rep.getData(); }      String(const String& str);
  
     /** AallocateCString - llocates an 8 bit representation of this String      /**
         object. The user is responsible for freeing the result. If any          Constructs a String with a specified number of characters of the
         characters are truncated, a TruncatedCharacter exception is thrown.          value of another String.
         This exception may be suppressed by passing true as the noThrow          @param str The String from which to copy the value.
         argument. Extra characters may be allocated at the end of the          @param n A Uint32 specifying the number of characters to copy.
         new string by passing a non-zero value to the extraBytes argument.          @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);
  
         @param extraBytes Defines the number of extra characters to be      /**
         allocated at the end of the new string. Default is zero.          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);
  
         @param  noThrow If true, no exception will be thrown if characters      /**
         are truncated          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);
  
         @return pointer to the new representation of the string      /**
           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);
  
         @exception Throws TruncatedCharacter exception if any characters are      /**
         truncated          Constructs a String with a specified number of characters of the
         <pre>          value from a C string in UTF-8 format.
             String test = "abc";          @param str The C string from which to copy the value.
             char* p = test.allocateCString();          @param n A Uint32 specifying the number of characters to copy.
             ...          @exception NullPointer If the C string pointer is NULL.
             delete [] p;          @exception bad_alloc If the construction fails because of a memory
         </pre>              allocation failure.
           @exception Exception If the C string contains invalid UTF-8.
     */     */
     char* allocateCString(Uint32 extraBytes = 0, Boolean noThrow = false) const;      String(const char* str, Uint32 n);
  
     /** appendToCString - Append the given String object to a C-string. If the      /**
         length is not PEG_NOT_FOUND, then the lesser of the the length argument          Destructs a String object.
         and he length of this string is truncated.  Otherwise, the entire string  
         is trunctated.  The TruncatedCharacter exception is thrown if any  
         characters are truncated.  
         @param str Char pointer to the string to append  
         @param length Length to append or PEG_NOT_FOUND (Uint32(-1)  
         @param noThrow - If false, throw the "TruncatedCharacter" exception of  
         any characters are truncated  
         @return void  
         @exception Throws TruncatedCharacter exception of characters are  
         truncated and noThrow parameter is false.  
         <pre>  
             const char STR0[] = "one two three four";  
             String s = STR0;  
             const char STR1[] = "zero ";  
             char* tmp = new char[strlen(STR1) + s.size() + 1];  
             strcpy(tmp, STR1);  
             s.appendToCString(tmp, 7);  
             assert(strcmp(tmp, "zero one two") == 0);  
         </pre>  
     */     */
     void appendToCString(      ~String();
         char* str,  
         Uint32 length = PEG_NOT_FOUND,      /**
         Boolean noThrow = false) const;          Assigns the value of a String to the value of another String.
           @param str The String from which to copy the value.
     /** Returns the Ith character of the String object.          @return A reference to the target String object with its newly
         @exception - Throws exception "OutofBounds" if the index              assigned value.
         is outside the length of the string.          @exception bad_alloc If the assignment fails because of a memory
         <pre>              allocation failure.
             String t1 = "abc;  
             Char16 c = t1[1];   // character b  
         </pre>  
     */     */
     Char16& operator[](Uint32 i);      String& operator=(const String& str);
  
     /** Returns the Ith character of the String (const version).      /**
         @exception - Throws exception "OutofBounds" if the index          Assigns the value of a String to the value of another String.
         is outside the length of the string.          @param str The String from which to copy the value.
           @return A reference to the target String object with its newly
               assigned value.
           @exception bad_alloc If the assignment fails because of a memory
               allocation failure.
       */
       String& assign(const String& str);
  
       /**
           Assigns the value of a String to the value in a Char16 buffer.
           @param str The Char16 buffer from which to copy the value.
           @return A reference to the target String object with its newly
               assigned value.
           @exception NullPointer If the buffer pointer is NULL.
           @exception bad_alloc If the assignment fails because of a memory
               allocation failure.
     */     */
     const Char16 operator[](Uint32 i) const;      String& assign(const Char16* str);
  
     /** Append the given character to the string.      /**
         <pre>          Assigns the value of a String with a specified number of characters
              String s4 = "Hello";          of the value from a Char16 buffer.
             s4.append(Char16(0x0000))          @param str The Char16 buffer from which to copy the value.
         </pre>          @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 buffer pointer is NULL.
           @exception bad_alloc If the assignment fails because of a memory
               allocation failure.
     */     */
     String& append(const Char16& c);      String& assign(const Char16* str, Uint32 n);
  
     /// Append n characters from str to this String object.      /**
     String& append(const Char16* str, Uint32 n);          Assigns the value of a String to the value from a C string in UTF-8
           format.
           @param str The C string from which to copy the value.
           @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);
  
     /// Append the characters of str to this String object.      /**
     String& append(const String& str)          Assigns the value of a String with a specified number of characters
     {          of the value from a C string in UTF-8 format.
         return append(str.getData(), str.size());          @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);
  
     /** Overload operator += appends the parameter String to this String.      /**
         @param String to append.          Sets a String value to the empty String.
         @return This String  
         <pre>  
         String test = "abc";  
         test += "def";  
         assert(test == "abcdef");  
         </pre>  
     */     */
     String& operator+=(const String& x)      void clear();
     {  
         return append(x);  
     }  
  
     /** Append the character given by c to this String object.      /**
         @param c Single character to be appended          Reserves memory for a specified number of (16-bit) characters.
         @return String with appended character          This method does not change the size() of the string or any other
           external behavior.  If the capacity of the string is already greater
           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& operator+=(Char16 c)      void reserveCapacity(Uint32 capacity);
     {  
         return append(c);  
     }  
  
     /** Append the character given by c to this string.      /**
         <pre>          Returns the number of characters in a String value.  No termination
             String t1 = "abc";          character is included in the count.  For example, String("abcd").size()
             t1 += 'd'          returns 4.
             assert(t1 == "abcd");  
         </pre>  
     */     */
     String& operator+=(char c)      Uint32 size() const;
     {  
         return append(Char16(c));  
     }  
  
     /** Remove size characters from the string starting at the given      /**
         position. If size is PEG_NOT_FOUND, then all characters after pos are          Gets a null-terminated Char16 buffer containing the String value.
         removed.          The buffer is valid until the original String object is modified or
         @param pos Position in string to start remove          destructed.
         @param size Number of characters to remove. Default is PEG_NOT_FOUND          @return A pointer to a null-terminated Char16 buffer containing the
         (Uint32(-1) which causes all characters after pos to be removed              String value.
         <pre>  
             String s;  
             s = "abc";  
             s.remove(0, 1);  
             assert(String::equal(s, "bc"));  
             assert(s.size() == 2);  
             s.remove(0);  
             assert(String::equal(s, ""));  
             assert(s.size() == 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 = PEG_NOT_FOUND);      const Char16* getChar16Data() const;
  
     /** Return a new String which is initialzed with <TT>length</TT>      /**
         characters from this string starting at <TT>pos</TT>.          Gets a CString object containing the String value in UTF-8 format.
         @param <TT>pos</TT> is the positon in string to start getting the          Important:  A character pointer extracted from a CString object is
         substring.          only valid while the CString object exists and is unmodified.  (See
         @param <TT>length</TT> is the number of characters to get. If length          the CString documentation.)  Thus, in the following example, the
         is PEG_NOT_FOUND, then all characters after pos are added to the new          variable p holds a dangling (invalid) pointer:
         string.          <pre>
         @return String with the defined substring.                const char * p = (const char *)test.getCString();
         <pre>          </pre>
             s = "abcdefg";          This situation can be corrected by declaring a CString variable in
             s.remove(3);          the same scope.
             assert(String::equal(s, "abc"));  
         </pre>          @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 subString(Uint32 pos, Uint32 length = PEG_NOT_FOUND) const;      CString getCString() const;
  
     /** Find the position of the first occurence of the character c.      /**
         If the character is not found, PEG_NOT_FOUND is returned.          Gets a specified character from the String value.
         @param c Char to be found in the String          @param index Index of the character to access.
         @return Position of the character in the string or PEG_NOT_FOUND if not          @return The Char16 character at the specified index.
         found.          @exception IndexOutOfBoundsException If the String does not contain a
               character at the specified index.
     */     */
     Uint32 find(Char16 c) const;      Char16& operator[](Uint32 index);
  
     /** Same as above but starts searching from the given position. */      /**
     Uint32 find(Uint32 pos, Char16 c) const;          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.
       */
       const Char16 operator[](Uint32 index) const;
  
     /** Find the position of the first occurence of the string object.      /**
         This function finds one string inside another          Appends a character to the String.
         If the matching substring is not found, PEG_NOT_FOUND is returned.          @param c The Char16 character to append.
         @param s String object to be found in the String          @return A reference to the String object containing the newly appended
         @return Position of the substring in the String or PEG_NOT_FOUND if not              character.
         found.          @exception bad_alloc If the append fails because of a memory
               allocation failure.
     */     */
     Uint32 find(const String& s) const;      String& append(const Char16& c);
  
     /** Find substring      /**
         @ param 16 bit character pointer          Appends a specified number of characters to the String from a Char16
         @seealso find          buffer.
         @return Position of the substring in the String or PEG_NOT_FOUND if not          @param str The Char16 buffer from which to append the characters.
         found.          @param n A Uint32 specifying the number of characters to append from
     */              the buffer.
     Uint32 find(const Char16* s) const;          @return A reference to the String object containing the newly appended
               characters.
     /** find substring          @exception NullPointer If the buffer pointer is NULL.
         @param s char* to substring          @exception bad_alloc If the append fails because of a memory
         @return Position of the substring in the String or PEG_NOT_FOUND if not              allocation failure.
         found.  
     */     */
     Uint32 find(const char* s) const;      String& append(const Char16* str, Uint32 n);
  
     /** reverseFind - Same as find() but start looking in reverse (last      /**
     character first).          Appends a String value to the String.
         @param c Char16 character to find in String.          @param str The String to append.
         @Seealso find          @return A reference to the String object containing the newly appended
         @return Position of the character in the string or PEG_NOT_FOUND if not              characters.
         found.          @exception bad_alloc If the append fails because of a memory
               allocation failure.
       */
       String& append(const String& str);
  
         NOTE: This function is defined only for char* input, not for      /**
           Removes a specified number of characters from the String starting at a
           given index.  If the number of characters to remove is specified as
           PEG_NOT_FOUND, then all characters from the index to the end of the
           String are removed.
           @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.         String.
     */     */
     Uint32 reverseFind(Char16 c) const;      void remove(Uint32 index, Uint32 size = PEG_NOT_FOUND);
  
     /** Converts all characters in this string to lower case.      /**
           Creates a new String containing up to the specified number of
           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.
     */     */
     void toLower();      String subString(Uint32 index, Uint32 n = PEG_NOT_FOUND) const;
  
     /** Translate any occurences of fromChar to toChar.      /**
           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.
     */     */
     void translate(Char16 fromChar, Char16 toChar);      Uint32 find(Char16 c) const;
  
     /** Method for printing a string.      /**
           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.
     */     */
     void print() const;      Uint32 find(Uint32 index, Char16 c) const;
  
     /** Compare the first n characters of the two strings..      /**
         @param s1 First null-terminated string for the comparison.          Finds the index of the first occurrence of a specified String value in
         @param s2 Second null-terminated string for the comparison.          the String.  If the String value is not found, PEG_NOT_FOUND is
         @param n Number of characters to compare.          returned.
         @return Return -1 if s1 is lexographically less than s2. If they are          @param s The String value to find in the String.
         equavalent return 0. Otherwise return 1.          @return The Uint32 index of the beginning of the String value if found,
               PEG_NOT_FOUND otherwise.
     */     */
     static int compare(const Char16* s1, const Char16* s2, Uint32 n);      Uint32 find(const String& s) const;
  
     /** Just like one above except ignores case differences.      /**
           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.
     */     */
     static int compareNoCase(const char* s1, const char* s2, Uint32 n);      Uint32 reverseFind(Char16 c) const;
  
     static int compareNoCase(const char* s1, const char* s2);      /**
           Converts all characters in the String to lower case.
       */
       void toLower();
  
     /** Compare two null-terminated 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>
         @return If s1 is less than s2, return -1; if equal return 0;          Converts all characters in the String to upper case.
         otherwise, return 1.      */
       void toUpper();
   #endif
  
         NOTE: Use the comparison operators <,<= > >= to compare      /**
         String objects.          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 Char16* s1, const Char16* s2);      static int compare(const String& s1, const String& s2, Uint32 n);
  
     /** Compare two String objects for equality.      /**
         @param s1 First <TT>String</TT> for comparison.          Compares two String objects.  (Note: Use the comparison
         @param s2 Second <TT>String</TT> for 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);
  
         @return Boolean true if the two strings are equal.      /**
           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 equalNoCase(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;  
  
     /** Return true if the str parameter matches the pattern. C-Shell style      static Boolean equal(const String& s1, const char* s2);
         glob matching is used.  
     */  
     static Boolean match(const String& str, const String& pattern);  
  
     /** Return true if the str parameter matches the pattern. C-Shell style      static int compare(const String& s1, const char* s2);
         glob matching is used. Ignore case in all comparisons.  
     */  
     static Boolean matchNoCase(const String& str, const String& pattern);  
  
 private:      String& append(const char* str);
  
     static Uint32 _min(Uint32 x, Uint32 y) { return x < y ? x : y; }      String& append(const char* str, Uint32 size);
  
     Array<Char16> _rep;      static Boolean equalNoCase(const String& s1, const char* s2);
 };  
  
 /** String operator ==. Test for equality between two strings of any of the  #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
     types String or char*.  
     @return Boolean - True if the strings are equal  
  
 */  private:
 inline Boolean operator==(const String& x, const String& y)  
 {  
     return String::equal(x, y);  
 }  
  
 /** String operator ==. Test for equality between two strings      StringRep* _rep;
   };
  
 */  /**
 inline Boolean operator==(const String& x, const char* 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 char* x, const String& y)  PEGASUS_COMMON_LINKAGE Boolean operator==(const char* str1, const String& str2);
 {  
     return String::equal(x, y);  
 }  
  
 /** String operator ==. Test for equality between two strings  /**
       Compares two String objects for inequality.
       @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);
  
   /**
       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.
 */ */
 inline Boolean operator!=(const String& x, const String& y)  
 {  
     return !String::equal(x, y);  
 }  
   
 PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<( PEGASUS_COMMON_LINKAGE PEGASUS_STD(ostream)& operator<<(
     PEGASUS_STD(ostream)& os,     PEGASUS_STD(ostream)& os,
     const String& x);      const String& str);
   
 /** overload operator +  - Concatenates String objects.  
  
   /**
       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>  
         String t1 = "def";  
         String t2 = "a";  
         assert (t2 < t1);  
     </pre>  
 */  
 inline Boolean operator<(const String& x, const String& y)  
 {  
     return String::compare(x.getData(), y.getData()) < 0;  
 }  
   
 /** overload operator <= compares String objects.  
   
 */  
 inline Boolean operator<=(const String& x, const String& y)  
 {  
     return String::compare(x.getData(), y.getData()) <= 0;  
 }  
   
 /** Overload operator > compares String objects  
 */  
 inline Boolean operator>(const String& x, const String& y)  
 {  
     return String::compare(x.getData(), y.getData()) > 0;  
 }  
   
 /** overload operator >= - Compares String objects  
 */  
 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  /**
     to lower case.      Compares two String objects.
 */      @param s1 The first String to compare.
 PEGASUS_COMMON_LINKAGE String ToLower(const String& str);      @param s2 The second String to compare.
       @return True if s1 is lexographically less than s2, false otherwise.
 /** Compare two strings but ignore any case differences.  */
 */  PEGASUS_COMMON_LINKAGE Boolean operator<(
 PEGASUS_COMMON_LINKAGE int CompareNoCase(const char* s1, const char* s2);      const String& str1,
       const String& str2);
  
 inline int EqualNoCase(const char* s1, const char* s2)  /**
 {      Compares two String objects.
     return CompareNoCase(s1, s2) == 0;      @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);
  
 /** Get the next line from the input file.  /**
 */      Compares two String objects.
 PEGASUS_COMMON_LINKAGE Boolean GetLine(PEGASUS_STD(istream)& is, String& line);      @param s1 The first String to compare.
       @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);
  
 /*  This is an internal class to be used by the internal Pegasus  /**
     components only. It provides an easy way to create an 8-bit string      Compares two String objects.
     representation on the fly without calling allocateCString() and      @param s1 The first String to compare.
     then worrying about deleting the string. The underscore before the      @param s2 The second String to compare.
     class name denotes that this class is internal, unsupported, undocumented,      @return True if s1 is lexographically greater than or equal to s2,
     and may be removed in future releases.          false otherwise.
 */ */
 class _CString  PEGASUS_COMMON_LINKAGE Boolean operator>=(
 {      const String& str1,
 public:      const String& str2);
  
     _CString(const String& x)  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
     {  
         _rep = x.allocateCString();  
     }  
  
     _CString(const _CString& x)  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2);
     {  
         _rep = strcpy(new char[strlen(x._rep) + 1], x._rep);  
     }  
  
     ~_CString()  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const char* s2);
     {  
         delete [] _rep;  
     }  
  
     _CString& operator=(const _CString& x)  PEGASUS_COMMON_LINKAGE Boolean operator==(const char* s1, const String& s2);
     {  
         if (this != &x)  
             _rep = strcpy(new char[strlen(x._rep) + 1], x._rep);  
  
         return *this;  PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const String& s2);
     }  
  
     operator const char*() const  PEGASUS_COMMON_LINKAGE Boolean operator!=(const String& s1, const char* s2);
     {  
         return _rep;  
     }  
  
     const char* data() const  PEGASUS_COMMON_LINKAGE Boolean operator!=(const char* s1, const String& s2);
     {  
         return _rep;  
     }  
  
 private:  PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const String& s2);
  
     char* _rep;  PEGASUS_COMMON_LINKAGE Boolean operator<(const String& s1, const char* s2);
 };  
   
 inline Uint32 _Length(const String& s1) { return s1.size(); }  
   
 inline Uint32 _Length(const char* s1) { return strlen(s1); }  
  
 inline Uint32 _Length(const char) { return 1; }  PEGASUS_COMMON_LINKAGE Boolean operator<(const char* s1, const String& s2);
  
 template<class S1, class S2>  PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const String& s2);
 inline String Cat(const S1& s1, const S2& s2)  
 {  
     String tmp;  
     tmp.reserve(_Length(s1) + _Length(s2));  
     tmp.append(s1);  
     tmp.append(s2);  
     return tmp;  
 }  
  
 template<class S1, class S2, class S3>  PEGASUS_COMMON_LINKAGE Boolean operator>(const String& s1, const char* s2);
 inline String Cat(const S1& s1, const S2& s2, const S3& s3)  
 {  
     String tmp;  
     tmp.reserve(_Length(s1) + _Length(s2) + _Length(s3));  
     tmp.append(s1);  
     tmp.append(s2);  
     tmp.append(s3);  
     return tmp;  
 }  
  
 template<class S1, class S2, class S3, class S4>  PEGASUS_COMMON_LINKAGE Boolean operator>(const char* s1, const String& s2);
 inline String Cat(const S1& s1, const S2& s2, const S3& s3, const S4& s4)  
 {  
     String tmp;  
     tmp.reserve(_Length(s1) + _Length(s2) + _Length(s3) + _Length(s4));  
     tmp.append(s1);  
     tmp.append(s2);  
     tmp.append(s3);  
     tmp.append(s4);  
     return tmp;  
 }  
   
 template<class S1, class S2, class S3, class S4, class S5>  
 inline String Cat(  
     const S1& s1,  
     const S2& s2,  
     const S3& s3,  
     const S4& s4,  
     const S5& s5)  
 {  
     String tmp;  
  
     tmp.reserve(_Length(s1) + _Length(s2) + _Length(s3) + _Length(s4) +  PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const String& s2);
         _Length(s5));  
  
     tmp.append(s1);  PEGASUS_COMMON_LINKAGE Boolean operator<=(const String& s1, const char* s2);
     tmp.append(s2);  
     tmp.append(s3);  
     tmp.append(s4);  
     tmp.append(s5);  
   
     return tmp;  
 }  
   
 template<class S1, class S2, class S3, class S4, class S5, class S6>  
 inline String Cat(  
     const S1& s1,  
     const S2& s2,  
     const S3& s3,  
     const S4& s4,  
     const S5& s5,  
     const S6& s6)  
 {  
     String tmp;  
  
     tmp.reserve(_Length(s1) + _Length(s2) + _Length(s3) + _Length(s4) +  PEGASUS_COMMON_LINKAGE Boolean operator<=(const char* s1, const String& s2);
         _Length(s5) + _Length(s6));  
  
     tmp.append(s1);  PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const String& s2);
     tmp.append(s2);  
     tmp.append(s3);  
     tmp.append(s4);  
     tmp.append(s5);  
     tmp.append(s6);  
  
     return tmp;  PEGASUS_COMMON_LINKAGE Boolean operator>=(const String& s1, const char* s2);
 }  
  
 PEGASUS_COMMON_LINKAGE const Array<String>& EmptyStringArray();  PEGASUS_COMMON_LINKAGE Boolean operator>=(const char* s1, const String& s2);
  
 PEGASUS_COMMON_LINKAGE Boolean Equal(const String& x, const String& y);  PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const String& s2);
  
 inline Boolean Open(PEGASUS_STD(ifstream)& is, const String& path)  PEGASUS_COMMON_LINKAGE String operator+(const String& s1, const char* s2);
 {  
     char* tmpPath = path.allocateCString();  
     is.open(tmpPath);  
     delete [] tmpPath;  
     return !!is;  
 }  
  
 inline Boolean Open(PEGASUS_STD(ofstream)& os, const String& path)  PEGASUS_COMMON_LINKAGE String operator+(const char* s1, const String& s2);
 {  
     char* tmpPath = path.allocateCString();  
     os.open(tmpPath);  
     delete [] tmpPath;  
     return !!os;  
 }  
  
 inline Boolean OpenAppend(PEGASUS_STD(ofstream)& os, const String& path)  #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
 {  
     char* tmpPath = path.allocateCString();  
     os.open(tmpPath, PEGASUS_STD(ios::app));  
     delete [] tmpPath;  
     return !!os;  
 }  
   
 #define PEGASUS_ARRAY_T String  
 #include <Pegasus/Common/ArrayInter.h>  
 #undef PEGASUS_ARRAY_T  
  
 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.39.2.6  
changed lines
  Added in v.1.105

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2