OWBI1_String.hpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002 * Copyright (C) 2001-2004 Vintela, Inc. All rights reserved.
00003 *
00004 * Redistribution and use in source and binary forms, with or without
00005 * modification, are permitted provided that the following conditions are met:
00006 *
00007 *  - Redistributions of source code must retain the above copyright notice,
00008 *    this list of conditions and the following disclaimer.
00009 *
00010 *  - Redistributions in binary form must reproduce the above copyright notice,
00011 *    this list of conditions and the following disclaimer in the documentation
00012 *    and/or other materials provided with the distribution.
00013 *
00014 *  - Neither the name of Vintela, Inc. nor the names of its
00015 *    contributors may be used to endorse or promote products derived from this
00016 *    software without specific prior written permission.
00017 *
00018 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS''
00019 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00020 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00021 * ARE DISCLAIMED. IN NO EVENT SHALL Vintela, Inc. OR THE CONTRIBUTORS
00022 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00023 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00024 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00025 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00026 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00027 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00028 * POSSIBILITY OF SUCH DAMAGE.
00029 *******************************************************************************/
00030 
00036 #ifndef OWBI1_STRING_HPP_INCLUDE_GUARD_
00037 #define OWBI1_STRING_HPP_INCLUDE_GUARD_
00038 #include "OWBI1_config.h"
00039 #include "OWBI1_Types.hpp"
00040 #include "OWBI1_COWIntrusiveReference.hpp"
00041 #include "OWBI1_CommonFwd.hpp"
00042 #include "OWBI1_CIMFwd.hpp"
00043 #include "OWBI1_Exception.hpp"
00044 #include <iosfwd>
00045 
00046 namespace OWBI1
00047 {
00048 
00049 OWBI1_DECLARE_APIEXCEPTION(StringConversion, OWBI1_OWBI1PROVIFC_API);
00050 
00063 class OWBI1_OWBI1PROVIFC_API String
00064 {
00065 public:
00066    class ByteBuf;
00070    String();
00077    explicit String(Int32 val);
00084    explicit String(UInt32 val);
00085 // do this check so we fill in the gaps and have int, long & long long constructors if necessary
00086 #if defined(OWBI1_INT32_IS_INT) && defined(OWBI1_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);
00136    enum ETakeOwnershipFlag
00137    {
00138       E_TAKE_OWNERSHIP
00139    };
00151    explicit String(ETakeOwnershipFlag, char* allocatedMemory, size_t len);
00158    explicit String(const char* str, size_t len);
00166    String(const String& arg);
00171    explicit String(char c);
00175    ~String();
00179    void swap(String& x);
00186    char* allocateCString() const;
00190    size_t length() const;
00196    size_t UTF8Length() const;
00200    bool empty() const { return length() == 0; }
00209    int format(const char* fmt, ...);
00210    enum EReturnDelimitersFlag
00211    {
00212       E_DISCARD_DELIMITERS,
00213       E_RETURN_DELIMITERS
00214    };
00215    enum EEmptyTokenReturnFlag
00216    {
00217       E_SKIP_EMPTY_TOKENS,
00218       E_RETURN_EMPTY_TOKENS
00219    };
00233    StringArray tokenize(const char* delims = " \n\r\t\v",
00234       EReturnDelimitersFlag returnDelimitersAsTokens = E_DISCARD_DELIMITERS,
00235       EEmptyTokenReturnFlag returnEmptyTokens = E_SKIP_EMPTY_TOKENS ) const;
00240    const char* c_str() const;
00247    char charAt(size_t ndx) const;
00255    int compareTo(const String& arg) const;
00263    int compareTo(const char* arg) const;
00271    int compareToIgnoreCase(const String& arg) const;
00279    int compareToIgnoreCase(const char* arg) const;
00285    String& concat(const char* arg);
00286 
00292    String& concat(const String& arg)
00293    {
00294       return concat(arg.c_str());
00295    }
00296 
00302    String& concat(char arg);
00303    enum EIgnoreCaseFlag
00304    {
00305       E_CASE_SENSITIVE,
00306       E_CASE_INSENSITIVE
00307    };
00316    bool endsWith(const char* arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const;
00317 
00327    bool endsWith(const String& arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const
00328    {
00329       return endsWith(arg.c_str(), ignoreCase);
00330    }
00331 
00338    bool endsWith(char arg) const;
00339 
00347    bool equals(const String& arg) const;
00355    bool equals(const char* arg) const;
00364    bool equalsIgnoreCase(const String& arg) const;
00373    bool equalsIgnoreCase(const char* arg) const;
00377    UInt32 hashCode() const;
00386    size_t indexOf(char ch, size_t fromIndex=0) const;
00394    size_t indexOf(const char* arg, size_t fromIndex=0) const;
00402    size_t indexOf(const String& arg, size_t fromIndex=0) const
00403    {
00404       return indexOf(arg.c_str(), fromIndex);
00405    }
00406 
00415    size_t lastIndexOf(char ch, size_t fromIndex=npos) const;
00424    size_t lastIndexOf(const char* arg, size_t fromIndex=npos) const;
00433    size_t lastIndexOf(const String& arg, size_t fromIndex=npos) const
00434    {
00435       return lastIndexOf(arg.c_str(), fromIndex);
00436    }
00437 
00446    bool startsWith(const char* arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const;
00455    bool startsWith(const String& arg, EIgnoreCaseFlag ignoreCase = E_CASE_SENSITIVE) const
00456    {
00457       return startsWith(arg.c_str(), ignoreCase);
00458    }
00465    bool startsWith(char arg) const;
00466 
00475    String substring(size_t beginIndex,
00476       size_t length=npos) const;
00481    bool isSpaces() const;
00487    String& toLowerCase();
00493    String& toUpperCase();
00499    String& ltrim();
00505    String& rtrim();
00512    String& trim();
00518    String& erase();
00519    
00525    String& erase( size_t idx, size_t len = npos );
00532    String& operator= (const String & arg);
00540    const char& operator[] (size_t ndx) const;
00541    char& operator[] (size_t ndx);
00548    String& operator+= (const String& arg) { return concat(arg); }
00555    String& operator+= (const char* arg) { return concat(arg); }
00562    String& operator+= (char arg) { return concat(arg); }
00569    void readObject(std::istream& istrm);
00575    void writeObject(std::ostream& ostrm) const;
00579    String toString() const;
00584    Real32 toReal32() const;
00589    Real64 toReal64() const;
00595    bool toBool() const;
00600    UInt8 toUInt8(int base=10) const;
00605    Int8 toInt8(int base=10) const;
00610    UInt16 toUInt16(int base=10) const;
00615    Int16 toInt16(int base=10) const;
00620    UInt32 toUInt32(int base=10) const;
00625    Int32 toInt32(int base=10) const;
00630    UInt64 toUInt64(int base=10) const;
00635    Int64 toInt64(int base=10) const;
00640    unsigned int toUnsignedInt(int base=10) const;
00645    int toInt(int base=10) const;
00656    static unsigned long long int strtoull(const char* nptr, char** endptr,
00657       int base);
00668    static long long int strtoll(const char* nptr, char** endptr, int base);
00676    static const char* strchr(const char* theStr, int c);
00685    static String getLine(std::istream& istr);
00686 
00687 #if defined(OWBI1_AIX)
00688    static const size_t npos;
00689 #else
00690    static const size_t npos = ~0;
00691 #endif // OWBI1_AIX
00692 
00693 #ifdef OWBI1_WIN32
00694 #pragma warning (push)
00695 #pragma warning (disable: 4251)
00696 #endif
00697 
00698    typedef COWIntrusiveReference<ByteBuf> buf_t;
00699 private:
00700    buf_t m_buf;
00701 
00702 #ifdef OWBI1_WIN32
00703 #pragma warning (pop)
00704 #endif
00705 
00706 };
00707 OWBI1_OWBI1PROVIFC_API std::ostream& operator<< (std::ostream& ostr, const String& arg);
00708 OWBI1_OWBI1PROVIFC_API String operator + (const String& s1, const String& s2);
00709 OWBI1_OWBI1PROVIFC_API String operator + (const char* p, const String& s);
00710 OWBI1_OWBI1PROVIFC_API String operator + (const String& s, const char* p);
00711 OWBI1_OWBI1PROVIFC_API String operator + (char c, const String& s);
00712 OWBI1_OWBI1PROVIFC_API String operator + (const String& s, char c);
00713 inline bool
00714 operator == (const String& s1, const String& s2)
00715 {
00716    return (s1.compareTo(s2) == 0);
00717 }
00718 inline bool
00719 operator == (const String& s, const char* p)
00720 {
00721    return (s.compareTo(p) == 0);
00722 }
00723 inline bool
00724 operator == (const char* p, const String& s)
00725 {
00726    return (s.compareTo(p) == 0);
00727 }
00728 inline bool
00729 operator != (const String& s1, const String& s2)
00730 {
00731    return (s1.compareTo(s2) != 0);
00732 }
00733 inline bool
00734 operator != (const String& s, const char* p)
00735 {
00736    return (s.compareTo(p) != 0);
00737 }
00738 inline bool
00739 operator != (const char* p, const String& s)
00740 {
00741    return (s.compareTo(p) != 0);
00742 }
00743 inline bool
00744 operator < (const String& s1, const String& s2)
00745 {
00746    return (s1.compareTo(s2) < 0);
00747 }
00748 inline bool
00749 operator < (const String& s, const char* p)
00750 {
00751    return (s.compareTo(p) < 0);
00752 }
00753 inline bool
00754 operator < (const char* p, const String& s)
00755 {
00756    return (String(p).compareTo(s) < 0);
00757 }
00758 inline bool
00759 operator <= (const String& s1, const String& s2)
00760 {
00761    return (s1.compareTo(s2) <= 0);
00762 }
00763 inline bool
00764 operator <= (const String& s, const char* p)
00765 {
00766    return (s.compareTo(p) <= 0);
00767 }
00768 inline bool
00769 operator <= (const char* p, const String& s)
00770 {
00771    return (String(p).compareTo(s) <= 0);
00772 }
00773 inline bool
00774 operator > (const String& s1, const String& s2)
00775 {
00776    return (s1.compareTo(s2) > 0);
00777 }
00778 inline bool
00779 operator > (const String& s, const char* p)
00780 {
00781    return (s.compareTo(p) > 0);
00782 }
00783 inline bool
00784 operator > (const char* p, const String& s)
00785 {
00786    return (String(p).compareTo(s) > 0);
00787 }
00788 inline bool
00789 operator >= (const String& s1, const String& s2)
00790 {
00791    return (s1.compareTo(s2) >= 0);
00792 }
00793 inline bool
00794 operator >= (const String& s, const char* p)
00795 {
00796    return (s.compareTo(p) >= 0);
00797 }
00798 inline bool
00799 operator >= (const char* p, const String& s)
00800 {
00801    return (String(p).compareTo(s) >= 0);
00802 }
00803 
00804 } // end namespace OWBI1
00805 
00806 #endif

Generated on Thu Feb 9 08:48:29 2006 for openwbem by  doxygen 1.4.6