(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.88 and 1.92

version 1.88, 2005/04/11 16:49:39 version 1.92, 2005/11/10 01:10:55
Line 45 
Line 45 
 #include <Pegasus/Common/Char16.h> #include <Pegasus/Common/Char16.h>
 #include <Pegasus/Common/Linkage.h> #include <Pegasus/Common/Linkage.h>
  
 // Locale constants  
 // These constants need to be defined as follows:  
 // lower case language; underscore; Uppercase Country  
 const char ENGLISH_US[] = "en_US";  
   
   
 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 67 
Line 61 
     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 81 
Line 75 
     */     */
     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 91 
Line 86 
  
     friend class String;     friend class String;
  
     void* _rep;      char* _rep;
 }; };
  
 /** /**
Line 112 
Line 107 
         <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     API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const char* str);     String(const char* str);
  
     /** Initialize from the first n characters of a plain C-String:      /** Initialize from the first <TT>n</TT> 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     API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String(const char* str, Uint32 n);     String(const char* str, Uint32 n);
  
Line 162 
Line 168 
         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);
  
Line 169 
Line 176 
         @param str String to assign.         @param str String to assign.
         @return Returns the String.         @return Returns the String.
         API supports UTF8         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     API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& assign(const char* str);     String& assign(const char* str);
  
Line 192 
Line 206 
     @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     API supports UTF8
       @exception NullPointer Thrown if str is NULL.
       @exception bad_alloc Thrown if there is insufficient memory.
     */     */
     String& assign(const char* str, Uint32 n);     String& assign(const char* str, Uint32 n);
  
Line 203 
Line 219 
     */     */
     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 245 
Line 260 
             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 269 
Line 307 
     /** 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 282 
Line 320 
             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 299 
Line 340 
         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 331 
Line 373 
         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 344 
Line 387 
  
     /** 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 355 
Line 398 
         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;
  
Line 432 
Line 475 
     */     */
     static Boolean equalNoCase(const String& str1, const String& str2);     static Boolean equalNoCase(const String& str1, const String& str2);
  
   #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
   
       String(const String& s1, const String& s2);
   
       String(const String& s1, const char* s2);
   
       String(const char* s1, const String& s2);
   
       String& operator=(const char* str);
   
       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:
  
     StringRep* _rep;     StringRep* _rep;
Line 522 
Line 589 
     const String& str1,     const String& str1,
     const String& str2);     const String& str2);
  
   #ifdef PEGASUS_USE_EXPERIMENTAL_INTERFACES
   
   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 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) && !defined(PEGASUS_DISABLE_INTERNAL_INLINES)
   # include "StringInline.h"
   #endif
   
 #endif /* Pegasus_String_h */ #endif /* Pegasus_String_h */


Legend:
Removed from v.1.88  
changed lines
  Added in v.1.92

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2