(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.2 and 1.9

version 1.2, 2001/01/24 16:16:38 version 1.9, 2001/02/26 04:33:28
Line 23 
Line 23 
 // Author: // Author:
 // //
 // $Log$ // $Log$
   // Revision 1.9  2001/02/26 04:33:28  mike
   // Fixed many places where cim names were be compared with operator==(String,String).
   // Changed all of these to use CIMName::equal()
   //
   // Revision 1.8  2001/02/20 14:05:24  karl
   // Comments for Document
   //
   // Revision 1.7  2001/02/11 17:19:30  mike
   // added reverseFind() method
   //
   // Revision 1.6  2001/02/11 05:42:33  mike
   // new
   //
   // Revision 1.5  2001/01/30 08:00:43  karl
   // DOC++ Documentation update for header files
   //
   // Revision 1.4  2001/01/28 07:05:18  mike
   // added instance name/reference converters
   //
   // Revision 1.3  2001/01/28 04:11:03  mike
   // fixed qualifier resolution
   //
 // Revision 1.2  2001/01/24 16:16:38  karl // Revision 1.2  2001/01/24 16:16:38  karl
 // Incorporate Doc++ Comments as documentation into .h files // Incorporate Doc++ Comments as documentation into .h files
 // //
Line 32 
Line 54 
 // //
 //END_HISTORY //END_HISTORY
  
 ////////////////////////////////////////////////////////////////////////////////  
 //  
 // String.h  
 //  
 //      Simple String type.  
 //  
 ////////////////////////////////////////////////////////////////////////////////  
   
 /*  
 String Header File - Defines the CIM String Class.  
 */  
   
 #ifndef Pegasus_String_h #ifndef Pegasus_String_h
 #define Pegasus_String_h #define Pegasus_String_h
  
Line 55 
Line 65 
  
 PEGASUS_NAMESPACE_BEGIN PEGASUS_NAMESPACE_BEGIN
  
 PEGASUS_COMMON_LINKAGE void ThrowNullPointer();  
   
 PEGASUS_COMMON_LINKAGE Uint32 StrLen(const Char16* str);  
   
 inline Uint32 StrLen(const char* str)  
 {  
     if (!str)  
         ThrowNullPointer();  
   
     return strlen(str);  
 }  
 /** /**
 The Pegasus String C++ Class implements the CIM string type The Pegasus String C++ Class implements the CIM string type
 */ */
Line 73 
Line 72 
 { {
 public: public:
  
     /**      /// Default constructor.
     String with no parameters  
     */  
     String();     String();
     /**  
         String something class definitions      /// Copy constructor.
     */  
     String(const String& x);     String(const String& x);
     /// Create a CIM string  
       /// Initialize with first n characters from x.
     String(const String& x, Uint32 n);     String(const String& x, Uint32 n);
     /// Create a CIM String  
       /// Initialize with x.
     String(const Char16* x);     String(const Char16* x);
     /// Create a CIM String  
       /// Initialize with first n characters of x.
     String(const Char16* x, Uint32 n);     String(const Char16* x, Uint32 n);
     /** Create a CIM String  
     */      /// Initialize from a plain old C-String:
     String(const char* x);     String(const char* x);
  
       /// Initialize from the first n characters of a plain old C-String:
     String(const char* x, Uint32 n);     String(const char* x, Uint32 n);
  
     ~String() { }      /// Release all resources.
     /** method ATTN:      ~String()
     */      {
       }
   
       /// Assign this string with x.
     String& operator=(const String& x) { _rep = x._rep; return *this; }     String& operator=(const String& x) { _rep = x._rep; return *this; }
  
       /// Assign this string with x.
     String& operator=(const Char16* x) { assign(x); return *this; }     String& operator=(const Char16* x) { assign(x); return *this; }
     /** method assign - ATTN:  
     */      /// Assign this string with x.
     String& assign(const String& x) { _rep = x._rep; return *this; }     String& assign(const String& x) { _rep = x._rep; return *this; }
     /** method assign - ATTN:  
     */      /// Assign this string with x.
     String& assign(const Char16* x);     String& assign(const Char16* x);
     /** method assign - ATTN:  
     */      /// Assign this string with first n characters of x.
     String& assign(const Char16* x, Uint32 n);     String& assign(const Char16* x, Uint32 n);
     /** method assign - ATTN:  
     */      /// Assign this string with the plain old C-String x.
     String& assign(const char* x);     String& assign(const char* x);
     /** method assign - ATTN:  
     */      /// Assign this string with first n characters of the plain old C-String x.
     String& assign(const char* x, Uint32 n);     String& assign(const char* x, Uint32 n);
     /** Method clear -- ATTN:  
     */      /// Clear this string. After calling clear(), getLength() will return 0.
     void clear() { _rep.clear(); _rep.append('\0'); }     void clear() { _rep.clear(); _rep.append('\0'); }
     /** Method reserve - ATTN:  
       /** Reserves memory for capacity characters. Notice that this does not
           change the size of the string (getSize() returns what it did before).
           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.
     */     */
     void reserve(Uint32 capacity) { _rep.reserve(capacity + 1); }     void reserve(Uint32 capacity) { _rep.reserve(capacity + 1); }
     /** Method getLength - ATTN:  
     */      /// Returns the length of the string.
     Uint32 getLength() const { return _rep.getSize() - 1; }     Uint32 getLength() const { return _rep.getSize() - 1; }
     /** Method getData - ATT  
     */      /// Returns a pointer to the first character in the string string.
     const Char16* getData() const { return _rep.getData(); }     const Char16* getData() const { return _rep.getData(); }
  
     /** Method allocateCString -  Allocates an 8 bit representation of this      /** Allocates an 8 bit representation of this string. The user is
     string. The user is responsible for freeing the result. If any characters          responsible for freeing the result. If any characters are truncated,
     are truncated, a TruncatedCharacter exception is thrown. This exception may          a TruncatedCharacter exception is thrown. This exception may
     be suppressed by passing true as the noThrow argument. */          be suppressed by passing true as the noThrow argument. Extra
           characters may be allocated at the end of the new string by
           passing a non-zero value to the extraBytes argument.
       */
     char* allocateCString(Uint32 extraBytes = 0, Boolean noThrow = false) const;     char* allocateCString(Uint32 extraBytes = 0, Boolean noThrow = false) const;
  
     /** Method appendToCString - Append the given string to a C-string. If the      /** Append the given string to a C-string. If the length is not Uint32(-1),
     length is not Uint32(-1), then the lesser of the the length argument and the          then the lesser of the the length argument and the length of this
     length of this string is truncated. Otherwise, the entire string is          string is truncated. Otherwise, the entire string is trunctated. The
     trunctated. The TruncatedCharacter exception is thrown if any characters are          TruncatedCharacter exception is thrown if any characters are truncated.
     truncated.  
     */     */
     void appendToCString(     void appendToCString(
         char* str,         char* str,
         Uint32 length = Uint32(-1),         Uint32 length = Uint32(-1),
         Boolean noThrow = false) const;         Boolean noThrow = false) const;
  
       /// Returns the Ith character of the string.
     Char16& operator[](Uint32 i);     Char16& operator[](Uint32 i);
  
       /// Returns the Ith character of the string (const version).
     const Char16 operator[](Uint32 i) const;     const Char16 operator[](Uint32 i) const;
     /// method Append  
       /// Append the given character to the string.
     String& append(const Char16& c)     String& append(const Char16& c)
     {     {
         _rep.insert(_rep.getSize() - 1, c);         _rep.insert(_rep.getSize() - 1, c);
         return *this;         return *this;
     }     }
     /// method append  
       /// Append n characters from str to this string.
     String& append(const Char16* str, Uint32 n);     String& append(const Char16* str, Uint32 n);
     /// method append  
       /// Append the characters of str to this string.
     String& append(const String& str)     String& append(const String& str)
     {     {
         return append(str.getData(), str.getLength());         return append(str.getData(), str.getLength());
     }     }
     /// ATTN  
       /// Append the characters of str to this string.
     String& operator+=(const String& x)     String& operator+=(const String& x)
     {     {
         return append(x);         return append(x);
     }     }
     /// ATTN  
       /// Append the character given by c to this string.
     String& operator+=(Char16 c)     String& operator+=(Char16 c)
     {     {
         return append(c);         return append(c);
     }     }
     /// ATTN  
       /// Append the character given by c to this string.
     String& operator+=(char c)     String& operator+=(char c)
     {     {
         return append(Char16(c));         return append(Char16(c));
     }     }
     /// remove a string  
       /** Remove size characters from the string starting at the given
           position. If size is -1, then all characters after pos are removed.
       */
     void remove(Uint32 pos, Uint32 size = Uint32(-1));     void remove(Uint32 pos, Uint32 size = Uint32(-1));
     /// method subString ATTN:  
       /** Return a new string which is initialzed with <TT>length</TT>
           characters from this string starting at <TT>pos</TT>.
           @param <TT>pos</TT> is the positon in string to start getting the
           substring.
           @param <TT>length</TT> is the number of characters to get. If length
           is -1, then all characters after pos are added to the new string.
           @return String with the defined substring.
       */
     String subString(Uint32 pos, Uint32 length = Uint32(-1)) const;     String subString(Uint32 pos, Uint32 length = Uint32(-1)) const;
     /// Method find - ATTN:  
       /** Find the position of the first occurence of the character c.
           If the character is not found, -1 is returned.
       */
     Uint32 find(Char16 c) const;     Uint32 find(Char16 c) const;
     /// Method compare - Compare two CIM strings - ATTN:  
       /** Same as find() but start looking in reverse (last character first).
       */
       Uint32 reverseFind(Char16 c) const;
   
       /** Compare the first n characters of the two strings. Return -1 if s1
           is lexographically less than s2. If they are equavalent return 0.
           Otherwise return 1.
       */
     static int compare(const Char16* s1, const Char16* s2, Uint32 n);     static int compare(const Char16* s1, const Char16* s2, Uint32 n);
     /// Method compare -- Compare two CIM strings  
       /** Compare the two null-terminated strings. If s1 is less than s2,
           return -1; if equal return 0; otherwise, return 1.
       */
     static int compare(const Char16* s1, const Char16* s2);     static int compare(const Char16* s1, const Char16* s2);
     /// ATTN  
       /// Return true if the two strins are equal.
       static Boolean equal(const String& x, const String& y);
   
       /// Return true if the two strins are equal.
       static Boolean equal(const String& x, const Char16* y);
   
       /// Return true if the two strins are equal.
       static Boolean equal(const Char16* x, const String& y);
   
       /// Return true if the two strins are equal.
       static Boolean equal(const String& x, const char* y);
   
       /// Return true if the two strins are equal.
       static Boolean equal(const char* x, const String& y);
   
       /// Convert the plain old C-string to lower case:
       static void toLower(char* str);
   
       /**
           This member is used to represent empty strings. Using this member
           avoid an expensive construction of an empty string (e.g., String()).
       */
     static const String EMPTY;     static const String EMPTY;
  
 private: private:
Line 195 
Line 262 
     Array<Char16> _rep;     Array<Char16> _rep;
 }; };
  
 PEGASUS_COMMON_LINKAGE Boolean operator==(const String& x, const String& y);  inline Boolean operator==(const String& x, const String& y)
   {
       return String::equal(x, y);
   }
  
 PEGASUS_COMMON_LINKAGE Boolean operator==(const String& x, const char* y);  inline Boolean operator==(const String& x, const char* y)
   {
       return String::equal(x, y);
   }
  
 PEGASUS_COMMON_LINKAGE Boolean operator==(const char* x, const String& y);  inline Boolean operator==(const char* x, const String& y)
   {
       return String::equal(x, y);
   }
  
 inline Boolean operator!=(const String& x, const String& y) inline Boolean operator!=(const String& x, const String& y)
 { {
     return !operator==(x, y);      return !String::equal(x, y);
 } }
  
 PEGASUS_COMMON_LINKAGE std::ostream& operator<<(std::ostream& os, const String&  PEGASUS_COMMON_LINKAGE std::ostream& operator<<(
 x);      std::ostream& os,
       const String& x);
  
 inline String operator+(const String& x, const String& y) inline String operator+(const String& x, const String& y)
 { {
Line 234 
Line 311 
     return String::compare(x.getData(), y.getData()) >= 0;     return String::compare(x.getData(), y.getData()) >= 0;
 } }
  
   /** Return a version of this string whose characters have been shifted
       to lower case.
   */
   PEGASUS_COMMON_LINKAGE String ToLower(const String& str);
   
   
 PEGASUS_NAMESPACE_END PEGASUS_NAMESPACE_END
  
 #endif /* Pegasus_String_h */ #endif /* Pegasus_String_h */


Legend:
Removed from v.1.2  
changed lines
  Added in v.1.9

No CVS admin address has been configured
Powered by
ViewCVS 0.9.2