00001 
00002 
00003 
00004 
00005 
00006 
00007 
00008 
00009 
00010 
00011 
00012 
00013 
00014 
00015 
00016 
00017 
00018 
00019 
00020 
00021 
00022 
00023 
00024 
00025 
00026 
00027 
00028 
00029 
00030 
00036 #ifndef OW_STRING_HPP_INCLUDE_GUARD_
00037 #define OW_STRING_HPP_INCLUDE_GUARD_
00038 #include "OW_config.h"
00039 #include "OW_Types.hpp"
00040 #include "OW_COWIntrusiveReference.hpp"
00041 #include "OW_CommonFwd.hpp"
00042 #include "OW_CIMFwd.hpp"
00043 #include "OW_Exception.hpp"
00044 #include <iosfwd>
00045 
00046 namespace OW_NAMESPACE
00047 {
00048 
00049 OW_DECLARE_APIEXCEPTION(StringConversion, OW_COMMON_API);
00050 
00063 class OW_COMMON_API String
00064 {
00065 public:
00066    class ByteBuf;
00070    String();
00077    explicit String(Int32 val);
00084    explicit String(UInt32 val);
00085 
00086 #if defined(OW_INT32_IS_INT) && defined(OW_INT64_IS_LONG_LONG)
00087 
00093    explicit String(long val);
00100    explicit String(unsigned long val);
00101 #endif
00102 
00108    explicit String(Int64 val);
00115    explicit String(UInt64 val);
00122    explicit String(Real32 val);
00129    explicit String(Real64 val);
00135    String(const char* str);
00142    explicit String(const Char16Array& ra) OW_DEPRECATED;
00149    explicit String(Bool parm) OW_DEPRECATED;
00156    explicit String(const Char16& parm) OW_DEPRECATED;
00163    explicit String(const CIMDateTime& parm) OW_DEPRECATED;
00170    explicit String(const CIMObjectPath& parm) OW_DEPRECATED;
00171    enum ETakeOwnershipFlag
00172    {
00173       E_TAKE_OWNERSHIP
00174    };
00186    explicit String(ETakeOwnershipFlag, char* allocatedMemory, size_t len);
00193    explicit String(const char* str, size_t len);
00201    String(const String& arg);
00206    explicit String(char c);
00210    ~String();
00214    void swap(String& x);
00221    char* allocateCString() const;
00225    size_t length() const;
00231    size_t UTF8Length() const;
00235    bool empty() const { return length() == 0; }
00244    int format(const char* fmt, ...);
00245    enum EReturnDelimitersFlag
00246    {
00247       E_DISCARD_TOKENS, 
00248       E_RETURN_TOKENS, 
00249       E_DISCARD_DELIMITERS,
00250       E_RETURN_DELIMITERS
00251    };
00252    enum EEmptyTokenReturnFlag
00253    {
00254       E_SKIP_EMPTY_TOKENS,
00255       E_RETURN_EMPTY_TOKENS
00256    };
00270    StringArray tokenize(const char* delims = " \n\r\t\v",
00271       EReturnDelimitersFlag returnDelimitersAsTokens = E_DISCARD_DELIMITERS,
00272       EEmptyTokenReturnFlag returnEmptyTokens = E_SKIP_EMPTY_TOKENS ) const;
00277    const char* c_str() const;
00282    OW_DEPRECATED const char* getBytes() const  {  return c_str(); }
00289    char charAt(size_t ndx) const;
00297    int compareTo(const String& arg) const;
00305    int compareTo(const char* arg) const;
00313    int compareToIgnoreCase(const String& arg) const;
00321    int compareToIgnoreCase(const char* arg) const;
00327    String& concat(const char* arg);
00328 
00334    String& concat(const String& arg)
00335    {
00336       return concat(arg.c_str());
00337    }
00338 
00344    String& concat(char arg);
00345    enum EIgnoreCaseFlag
00346    {
00347       E_CASE_SENSITIVE,
00348       E_CASE_INSENSITIVE
00349    };
00358    bool endsWith(const char* arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const;
00359 
00369    bool endsWith(const String& arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const
00370    {
00371       return endsWith(arg.c_str(), ignoreCase);
00372    }
00373 
00380    bool endsWith(char arg) const;
00381 
00389    bool equals(const String& arg) const;
00397    bool equals(const char* arg) const;
00406    bool equalsIgnoreCase(const String& arg) const;
00415    bool equalsIgnoreCase(const char* arg) const;
00419    UInt32 hashCode() const;
00428    size_t indexOf(char ch, size_t fromIndex=0) const;
00436    size_t indexOf(const char* arg, size_t fromIndex=0) const;
00444    size_t indexOf(const String& arg, size_t fromIndex=0) const
00445    {
00446       return indexOf(arg.c_str(), fromIndex);
00447    }
00448 
00457    size_t lastIndexOf(char ch, size_t fromIndex=npos) const;
00466    size_t lastIndexOf(const char* arg, size_t fromIndex=npos) const;
00475    size_t lastIndexOf(const String& arg, size_t fromIndex=npos) const
00476    {
00477       return lastIndexOf(arg.c_str(), fromIndex);
00478    }
00479 
00488    bool startsWith(const char* arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const;
00497    bool startsWith(const String& arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const
00498    {
00499       return startsWith(arg.c_str(), ignoreCase);
00500    }
00507    bool startsWith(char arg) const;
00508 
00517    String substring(size_t beginIndex,
00518       size_t length=npos) const;
00523    bool isSpaces() const;
00529    String& toLowerCase();
00535    String& toUpperCase();
00541    String& ltrim();
00547    String& rtrim();
00554    String& trim();
00560    String& erase();
00561    
00567    String& erase( size_t idx, size_t len = npos );
00574    String& operator= (const String & arg);
00582    const char& operator[] (size_t ndx) const;
00583    char& operator[] (size_t ndx);
00590    String& operator+= (const String& arg) { return concat(arg); }
00597    String& operator+= (const char* arg) { return concat(arg); }
00604    String& operator+= (char arg) { return concat(arg); }
00611    void readObject(std::istream& istrm);
00617    void writeObject(std::ostream& ostrm) const;
00621    String toString() const;
00627    Char16 toChar16() const OW_DEPRECATED;
00632    Real32 toReal32() const;
00637    Real64 toReal64() const;
00643    bool toBool() const;
00648    UInt8 toUInt8(int base=10) const;
00653    Int8 toInt8(int base=10) const;
00658    UInt16 toUInt16(int base=10) const;
00663    Int16 toInt16(int base=10) const;
00668    UInt32 toUInt32(int base=10) const;
00673    Int32 toInt32(int base=10) const;
00678    UInt64 toUInt64(int base=10) const;
00683    Int64 toInt64(int base=10) const;
00688    unsigned int toUnsignedInt(int base=10) const;
00693    int toInt(int base=10) const;
00699    CIMDateTime toDateTime() const OW_DEPRECATED;
00710    static unsigned long long int strtoull(const char* nptr, char** endptr,
00711       int base);
00722    static long long int strtoll(const char* nptr, char** endptr, int base);
00730    static const char* strchr(const char* theStr, int c);
00739    static String getLine(std::istream& istr);
00740 
00741 #if defined(OW_AIX)
00742    static const size_t npos;
00743 #else
00744    static const size_t npos = size_t(~0);
00745 #endif // OW_AIX
00746 
00747 #ifdef OW_WIN32
00748 #pragma warning (push)
00749 #pragma warning (disable: 4251)
00750 #endif
00751 
00752    typedef COWIntrusiveReference<ByteBuf> buf_t;
00753 private:
00754    buf_t m_buf;
00755 
00756 #ifdef OW_WIN32
00757 #pragma warning (pop)
00758 #endif
00759 
00760 };
00761 OW_EXPORT_TEMPLATE(OW_COMMON_API, Array, String);
00762 OW_EXPORT_TEMPLATE(OW_COMMON_API, Enumeration, String);
00763 
00764 OW_COMMON_API std::ostream& operator<< (std::ostream& ostr, const String& arg);
00765 OW_COMMON_API String operator + (const String& s1, const String& s2);
00766 OW_COMMON_API String operator + (const char* p, const String& s);
00767 OW_COMMON_API String operator + (const String& s, const char* p);
00768 OW_COMMON_API String operator + (char c, const String& s);
00769 OW_COMMON_API String operator + (const String& s, char c);
00770 inline bool
00771 operator == (const String& s1, const String& s2)
00772 {
00773    return (s1.compareTo(s2) == 0);
00774 }
00775 inline bool
00776 operator == (const String& s, const char* p)
00777 {
00778    return (s.compareTo(p) == 0);
00779 }
00780 inline bool
00781 operator == (const char* p, const String& s)
00782 {
00783    return (s.compareTo(p) == 0);
00784 }
00785 inline bool
00786 operator != (const String& s1, const String& s2)
00787 {
00788    return (s1.compareTo(s2) != 0);
00789 }
00790 inline bool
00791 operator != (const String& s, const char* p)
00792 {
00793    return (s.compareTo(p) != 0);
00794 }
00795 inline bool
00796 operator != (const char* p, const String& s)
00797 {
00798    return (s.compareTo(p) != 0);
00799 }
00800 inline bool
00801 operator < (const String& s1, const String& s2)
00802 {
00803    return (s1.compareTo(s2) < 0);
00804 }
00805 inline bool
00806 operator < (const String& s, const char* p)
00807 {
00808    return (s.compareTo(p) < 0);
00809 }
00810 inline bool
00811 operator < (const char* p, const String& s)
00812 {
00813    return (String(p).compareTo(s) < 0);
00814 }
00815 inline bool
00816 operator <= (const String& s1, const String& s2)
00817 {
00818    return (s1.compareTo(s2) <= 0);
00819 }
00820 inline bool
00821 operator <= (const String& s, const char* p)
00822 {
00823    return (s.compareTo(p) <= 0);
00824 }
00825 inline bool
00826 operator <= (const char* p, const String& s)
00827 {
00828    return (String(p).compareTo(s) <= 0);
00829 }
00830 inline bool
00831 operator > (const String& s1, const String& s2)
00832 {
00833    return (s1.compareTo(s2) > 0);
00834 }
00835 inline bool
00836 operator > (const String& s, const char* p)
00837 {
00838    return (s.compareTo(p) > 0);
00839 }
00840 inline bool
00841 operator > (const char* p, const String& s)
00842 {
00843    return (String(p).compareTo(s) > 0);
00844 }
00845 inline bool
00846 operator >= (const String& s1, const String& s2)
00847 {
00848    return (s1.compareTo(s2) >= 0);
00849 }
00850 inline bool
00851 operator >= (const String& s, const char* p)
00852 {
00853    return (s.compareTo(p) >= 0);
00854 }
00855 inline bool
00856 operator >= (const char* p, const String& s)
00857 {
00858    return (String(p).compareTo(s) >= 0);
00859 }
00860 
00861 } 
00862 
00863 #endif