(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.79 and 1.99

version 1.79, 2003/11/12 15:27:53 version 1.99, 2007/09/14 18:16:29
Line 1 
Line 1 
 //%2003////////////////////////////////////////////////////////////////////////  //%2006////////////////////////////////////////////////////////////////////////
 // //
 // Copyright (c) 2000, 2001, 2002  BMC Software, Hewlett-Packard Development  // Copyright (c) 2000, 2001, 2002 BMC Software; Hewlett-Packard Development
 // Company, L. P., IBM Corp., The Open Group, Tivoli Systems.  // Company, L.P.; IBM Corp.; The Open Group; Tivoli Systems.
 // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.; // Copyright (c) 2003 BMC Software; Hewlett-Packard Development Company, L. P.;
 // IBM Corp.; EMC Corporation, The Open Group. // IBM Corp.; EMC Corporation, The Open Group.
   // Copyright (c) 2004 BMC Software; Hewlett-Packard Development Company, L.P.;
   // IBM Corp.; EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2005 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; VERITAS Software Corporation; The Open Group.
   // Copyright (c) 2006 Hewlett-Packard Development Company, L.P.; IBM Corp.;
   // EMC Corporation; Symantec Corporation; The Open Group.
 // //
 // Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
 // of this software and associated documentation files (the "Software"), to // of this software and associated documentation files (the "Software"), to
Line 23 
Line 29 
 // //
 //============================================================================== //==============================================================================
 // //
 // Author: Mike Brasher (mbrasher@bmc.com)  
 //  
 // Modified By: Karl Schopmeyer(k.schopmeyer@opengroup.org)  
 //              Roger Kumpf, Hewlett-Packard Company (roger_kumpf@hp.com)  
 //  
 //%///////////////////////////////////////////////////////////////////////////// //%/////////////////////////////////////////////////////////////////////////////
  
 #ifndef Pegasus_String_h #ifndef Pegasus_String_h
Line 46 
Line 47 
 #include <Pegasus/Common/Char16.h> #include <Pegasus/Common/Char16.h>
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
  
 const char STRING_FLAG_ASCII[] = "ASCII";  
 const char STRING_FLAG_UTF8[]  = "UTF8";  
   
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 class String; class String;
 class StringRep;  struct StringRep;
  
 /** The CString class provides access to an 8-bit String representation. /** The CString class provides access to an 8-bit String representation.
 */ */
Line 65 
Line 63 
     CString();     CString();
  
     /** REVIEWERS: Describe method here.     /** REVIEWERS: Describe method here.
     @param cstr Specifies the name of the CString instance.      @param cstr Specifies the name of the CString instance to copy.
     */     */
     CString(const CString& cstr);     CString(const CString& cstr);
  
Line 79 
Line 77 
     */     */
     CString& operator=(const CString& cstr);     CString& operator=(const CString& cstr);
  
     /** REVIEWERS: Describe constructor here.      /** Gets a pointer to the CString's data.
       @return Returns a const char pointer to the CString's data.
     */     */
     operator const char*() const;     operator const char*() const;
  
Line 89 
Line 88 
  
     friend class String;     friend class String;
  
     void* _rep;      char* _rep;
 }; };
  
 /** /**
Line 110 
Line 109 
         <pre>         <pre>
             String test;             String test;
         </pre>         </pre>
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String();     String();
  
     /** Copy constructor.     /** Copy constructor.
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const String& str);     String(const String& str);
  
     /** Initialize with first n characters from str.      /** Initialize with first <TT>n</TT> characters from <TT>str</TT>.
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
     @param n Specifies the Uint32 size to use for the length of the string object.      @param n Specifies Uint32 size to use for the length of the string object.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const String& str, Uint32 n);     String(const String& str, Uint32 n);
  
     /** Initialize with str.     /** Initialize with str.
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const Char16* str);     String(const Char16* str);
  
     /** Initialize with first n characters of str.     /** Initialize with first n characters of str.
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
     @param n Specifies the Uint32 size.     @param n Specifies the Uint32 size.
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const Char16* str, Uint32 n);     String(const Char16* str, Uint32 n);
  
     /** Initialize from a plain C-String:     /** Initialize from a plain C-String:
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
       API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
       @exception Exception Thrown if str is invalid UTF8
     */     */
     String(const char* str);     String(const char* str);
  
 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES      /** Initialize from the first <TT>n</TT> characters of a plain C-String:
     /** Initialize from a plain C-String that allows UTF-8:  
     @param str Specifies the name of the String instance.  
     @param utfFlag Specifies the name of the character constructor.  
     */  
     String(const char* str, const char* utfFlag);  
 #endif  
   
     /** Initialize from the first n characters of a plain C-String:  
     @param str Specifies the name of the String instance.     @param str Specifies the name of the String instance.
     @param u Specifies the Uint32 size.     @param u Specifies the Uint32 size.
       API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
       @exception Exception Thrown if str is invalid UTF8
     */     */
     String(const char* str, Uint32 n);     String(const char* str, Uint32 n);
  
Line 166 
Line 172 
         String t2 is assigned the value of t1.         String t2 is assigned the value of t1.
         @param str Specifies the name of the String to assign to another         @param str Specifies the name of the String to assign to another
         String instance.         String instance.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& operator=(const String& str);     String& operator=(const String& str);
  
     /** Assign this string with String str.     /** Assign this string with String str.
         @param str String to assign.         @param str String to assign.
         @return Returns the String.         @return Returns the String.
       API supports UTF8
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& assign(const String& str);     String& assign(const String& str);
  
     /** Assign this string with str.     /** Assign this string with str.
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& assign(const Char16* str);     String& assign(const Char16* str);
  
     /** Assign this string with first n characters of str.     /** Assign this string with first n characters of str.
     @param n REVIEWERS: Insert text here.     @param n REVIEWERS: Insert text here.
     @param str REVIEWERS: Insert text here.     @param str REVIEWERS: Insert text here.
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& assign(const Char16* str, Uint32 n);     String& assign(const Char16* str, Uint32 n);
  
     /** Assign this string with the plain C-String str.     /** Assign this string with the plain C-String str.
     @param str REVIEWERS: Insert text here.     @param str REVIEWERS: Insert text here.
       API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
       @exception Exception Thrown if str is invalid UTF8
     */     */
     String& assign(const char* str);     String& assign(const char* str);
  
     /** Assign this string with first n characters of the plain C-String str.     /** Assign this string with first n characters of the plain C-String str.
     @param str REVIEWERS: Insert text here.     @param str REVIEWERS: Insert text here.
     @param n REVIEWERS: Insert text here.     @param n REVIEWERS: Insert text here.
       API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
       @exception Exception Thrown if str is invalid UTF8
     */     */
     String& assign(const char* str, Uint32 n);     String& assign(const char* str, Uint32 n);
  
Line 204 
Line 225 
     */     */
     void clear();     void clear();
  
   
     /** Reserves memory for capacity characters. Notice     /** Reserves memory for capacity characters. Notice
         that this does not change the size of the string (size() returns         that this does not change the size of the string (size() returns
         what it did before).  If the capacity of the string is already         what it did before).  If the capacity of the string is already
Line 239 
Line 259 
  
     /** Create an 8-bit representation of this String object. For example,     /** Create an 8-bit representation of this String object. For example,
  
         @return CString object that provides access to the 8-bit String      @return CString object that provides access to the UTF8 String
         representation.         representation.
  
         <pre>         <pre>
             String test = "abc";             String test = "abc";
             printf("test = %s\n", (const char*)test.getCString());             printf("test = %s\n", (const char*)test.getCString());
  
             NOTE:  Do not do the following:              USAGE WARNING:  Do not do the following:
   
             const char * p = (const char *)test.getCString();             const char * p = (const char *)test.getCString();
   
             The pointer p will be invalid.  This is because             The pointer p will be invalid.  This is because
             the CString object is destructed, which deletes              the Compiler casues the CString object to be created on the
             the heap space for p.              callers stack as a temporary object. The deletion is therefore
               also the responsibility of the Compiler. The Compiler may cause
               it to be deleted at anytime after the return. Typically it is
               done at the closeof the next scope. When it is deleted the
               "const char *p" above will become a dangling pointer.
   
               The correct usage to achieve the "const char * p" is
               as follows:
   
                 String str = "hello";
                 ...
                 CString cstr = str.getCString();
   
                 const char* p = (const char*)cstr;
   
               This tells the compiler to create a CString object on the callers
               stack that is the deleted at the discretion of the caller rather
               than the compiler. The "const char *p" above will be good until
               the caller explicity deletes the CString object.
   
   
         </pre>         </pre>
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     CString getCString() const;     CString getCString() const;
  
     /** Returns the specified character of the String object.     /** Returns the specified character of the String object.
         @param index Index of the character to access.         @param index Index of the character to access.
         @return Specified character of the String object.         @return Specified character of the String object.
         @exception IndexOutOfBoundsException If the index      @exception IndexOutOfBoundsException If <TT>index</TT>
         is outside the bounds of the String.         is outside the bounds of the String.
         <pre>         <pre>
             String test = "abc;             String test = "abc;
Line 270 
Line 313 
     /** Returns the specified character of the String object (const version).     /** Returns the specified character of the String object (const version).
         @param index Index of the character to access.         @param index Index of the character to access.
         @return Specified character of the String object.         @return Specified character of the String object.
         @exception IndexOutOfBoundsException If the index      @exception IndexOutOfBoundsException If <TT>index</TT>
         is outside the bounds of the String.         is outside the bounds of the String.
     */     */
     const Char16 operator[](Uint32 index) const;     const Char16 operator[](Uint32 index) const;
Line 283 
Line 326 
             test.append(Char16('d'));             test.append(Char16('d'));
             assert(test == "abcd");             assert(test == "abcd");
         </pre>         </pre>
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& append(const Char16& c);     String& append(const Char16& c);
  
     /** Append n characters from str to this String.     /** Append n characters from str to this String.
     @param str REVIEWERS: Insert text here.     @param str REVIEWERS: Insert text here.
     @param n REVIEWERS: Insert text here.     @param n REVIEWERS: Insert text here.
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& append(const Char16* str, Uint32 n);     String& append(const Char16* str, Uint32 n);
  
Line 300 
Line 346 
         test.append("def");         test.append("def");
         assert(test == "abcdef");         assert(test == "abcdef");
         </pre>         </pre>
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& append(const String& str);     String& append(const String& str);
  
     /** Remove size characters from the string starting at the given     /** Remove size characters from the string starting at the given
         index. If size is PEG_NOT_FOUND, then all characters after index are      index. If size is PEG_NOT_FOUND, then all characters after
         removed.      <TT>index</TT> are removed.
         @param index Position in string to start remove.         @param index Position in string to start remove.
         @param size Number of characters to remove. Default is PEG_NOT_FOUND         @param size Number of characters to remove. Default is PEG_NOT_FOUND
         which causes all characters after index to be removed.      which causes all characters after <TT>index</TT> to be removed.
         <pre>         <pre>
             String s;             String s;
             s = "abc";             s = "abc";
Line 332 
Line 379 
         is PEG_NOT_FOUND, then all characters after index are added to the new         is PEG_NOT_FOUND, then all characters after index are added to the new
         string.         string.
         @return String Specifies the Sting with the defined substring.         @return String Specifies the Sting with the defined substring.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String subString(Uint32 index, Uint32 length = PEG_NOT_FOUND) const;     String subString(Uint32 index, Uint32 length = PEG_NOT_FOUND) const;
  
Line 345 
Line 393 
  
     /** Find the index of the first occurence of the character c.     /** Find the index of the first occurence of the character c.
         If the character is not found, PEG_NOT_FOUND is returned.         If the character is not found, PEG_NOT_FOUND is returned.
         This begins searching from the given index.      Searching begins from the specified index.
         @param c Char to be found in the String.         @param c Char to be found in the String.
         @return Position of the character in the string or PEG_NOT_FOUND if not      @return Position of the character in the string or PEG_NOT_FOUND if the
         found.      character is not found.
     */     */
     Uint32 find(Uint32 index, Char16 c) const;     Uint32 find(Uint32 index, Char16 c) const;
  
Line 356 
Line 404 
         This function finds one string inside another.         This function finds one string inside another.
         If the matching substring is not found, PEG_NOT_FOUND is returned.         If the matching substring is not found, PEG_NOT_FOUND is returned.
         @param s String object to be found in the String.         @param s String object to be found in the String.
         @return Position of the substring in the String or PEG_NOT_FOUND if not      @return Position of the substring in the String or PEG_NOT_FOUND if the
         found.      substring is not found.
     */     */
     Uint32 find(const String& s) const;     Uint32 find(const String& s) const;
  
     /** Same as find() but start looking in reverse (last character first).     /** Same as find() but start looking in reverse (last character first).
         @param c Char16 character to find in String.         @param c Char16 character to find in String.
         @return Position of the character in the string or PEG_NOT_FOUND if not      @return Position of the character in the string or PEG_NOT_FOUND if the
         found.      character is not found.
     */     */
     Uint32 reverseFind(Char16 c) const;     Uint32 reverseFind(Char16 c) const;
  
     /** Converts all characters in this string to lowercase characters.      /** Converts all characters in this string to lowercase characters,
     */     */
     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.      /** <I><B>Experimental Interface</B></I><BR>
         @param s2 Second null-terminated string for the comparison.          Converts all characters in this string to uppercase characters.
         @param n Number of characters to compare.      */
         @return Return -1 If s1 is lexographically less than s2; if they are      void toUpper();
         equivalent return 0; otherwise return 1.  #endif
   
       /**
           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 Returns 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);     static int compare(const String& s1, const String& s2, Uint32 n);
  
     /** Compare two null-terminated strings.      /**
         @param s1 First null-terminated string for the comparison.          Compares two String objects.
         @param s2 Second null-terminated string for the comparison.          @param s1 The first String to compare.
         @return Return -1 if s1 is less than s2; if equal return 0;          @param s2 The second String to compare.
         otherwise return 1.          @return Returns a negative integer if s1 is lexographically less
           than s2, 0 if s1 and s2 are equal, and a positive integer otherwise.
  
         NOTE: Use the comparison operators <,<= > >= to compare         NOTE: Use the comparison operators <,<= > >= to compare
         String objects.         String objects.
     */     */
     static int compare(const String& s1, const String& s2);     static int compare(const String& s1, const String& s2);
  
     /** Compare two null-terminated strings but ignore case.      /**
         @param s1 First null-terminated string for the comparison.          Compares two String objects, ignoring case differences.
         @param s2 Second null-terminated string for the comparison.          @param s1 The first String to compare.
         @return Return -1 if s1 is less than s2; if equal return 0;          @param s2 The second String to compare.
         otherwise return 1.          @return Returns a negative integer if s1 is lexographically less
           than s2, 0 if s1 and s2 are equal, and a positive integer otherwise.
         NOTE: Use the comparison operators <,<= > >= to compare          (Case differences are ignored in all cases.)
         String objects.  
     */     */
     static int compareNoCase(const String& s1, const String& s2);     static int compareNoCase(const String& s1, const String& s2);
  
Line 427 
Line 484 
     static Boolean equalNoCase(const String& str1, const String& str2);     static Boolean equalNoCase(const String& str1, const String& str2);
  
 #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
     // UTF8 specific code:  
  
     /** Assign this string with a C string that may contain UTF-8.      String(const String& s1, const String& s2);
         @param str The C string  
     */  
     String& assignUTF8(const char* str);  
  
     /** Create an 8-bit UTF-8 representation of this String object.      String(const String& s1, const char* s2);
         @return CString object that provides access to the 8-bit UTF-8 String  
         representation.  
     */  
     CString getCStringUTF8() const;  
  
     /** Tests whether a C string contains valid UTF-8 characters.      String(const char* s1, const String& s2);
         @param str The C string  
     */      String& operator=(const char* str);
     static Boolean isUTF8(const char*);  
 #endif      Uint32 find(const char* s) const;
   
       static Boolean equal(const String& s1, const char* s2);
   
       static int compare(const String& s1, const char* s2);
   
       String& append(const char* str);
   
       String& append(const char* str, Uint32 size);
   
       static Boolean equalNoCase(const String& s1, const char* s2);
   
   #endif /* PEGASUS_USE_EXPERIMENTAL_INTERFACES */
  
 private: private:
  
Line 536 
Line 597 
     const String& str1,     const String& str1,
     const String& str2);     const String& str2);
  
 #ifndef PEGASUS_REMOVE_DEPRECATED  #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
 /** Compares two strings but ignores any case differences.  
     @param s1 REVIEWERS: Insert description here.  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const String& s2);
     @param s2 REVIEWERS: Insert description here.  
 */  PEGASUS_COMMON_LINKAGE Boolean operator==(const String& s1, const char* s2);
 PEGASUS_COMMON_LINKAGE int CompareNoCase(const char* s1, const char* s2);  
 #endif  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 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 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.79  
changed lines
  Added in v.1.99

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2