UString.h

Go to the documentation of this file.
00001 //---------------------------------------------------------------------------------------
00002 // Copyright (c) 2001-2008 by PDFTron Systems Inc. All Rights Reserved.
00003 // Consult legal.txt regarding legal and license information.
00004 //---------------------------------------------------------------------------------------
00005 
00006 #ifndef   H_CPPPDFTRON_UNISTRING
00007 #define   H_CPPPDFTRON_UNISTRING
00008 
00009 #include <Common/BasicTypes.h>
00010 #include <Common/Exception.h>
00011 #include <C/Common/TRN_Types.h>
00012 #include <C/Common/TRN_UString.h>
00013 #include <Common/Common.h>
00014 #include <ostream>
00015 
00016 namespace pdftron { 
00017 
00027 class UString
00028 {
00029 public:
00030 
00034          UString();
00035 
00040          UString(const UString& str);
00041 
00047          explicit UString(Unicode value);
00048 
00054          UString(const Unicode* value);
00055 
00063          UString(const Unicode* value, int length);
00064 
00068         enum TextEncoding {
00069                 e_ascii_enc,       
00070                 e_pdfdoc_enc,      
00071                 e_winansii_enc,    
00072                 e_pdftext_enc,     
00073                 e_utf16be_enc,     
00074                 e_no_enc           
00075         };
00076 
00086          UString(const char* buf, int buf_sz = -1, TextEncoding enc = e_ascii_enc);
00087 
00091         ~UString();
00092 
00097          UString& operator=(const UString& str);
00098          UString& operator=(const char* ascii_str);
00099 
00104          UString& Assign(const UString& uni);
00105          UString& Assign(const Unicode* uni, int buf_sz = -1);
00106          UString& Assign2(const char* buf, int buf_sz = -1, TextEncoding enc = e_ascii_enc);
00107 
00112          UString& operator+=(const UString& str);
00113 
00121          UString Concat(const UString &str) const;
00122 
00123         friend UString operator+( const UString& str1, const UString& str2) { return str1.Concat(str2);}
00124 
00131          int GetLength() const;
00132 
00137          bool Empty() const;
00138 
00146          const Unicode* GetBuffer() const;
00147 
00163          int Compare(const UString& str, int max_length = -1) const;
00164 
00184          int Compare(const char* ascii_string, int max_length = -1) const;
00185 
00186         /* 
00187          * Copies a substring of at most some number of characters from a string 
00188          * beginning from a specified position.
00189          *
00190          * @param off An index locating the element at the position from which 
00191          * the copy of the string is made, with a default value of 0.
00192          * 
00193          * @param count The number of characters that are to be copied if they 
00194          * are present. -1 means copy the entire string.
00195          *
00196          * @return A substring object that is a copy of elements of the string operand 
00197          * beginning at the position specified by the first argument.
00198          */
00199          UString SubStr(int off = 0, int count = -1);
00200 
00213          Unicode GetAt(int idx) const;
00214 
00219          void PushBack(Unicode ch);
00220 
00228          void Resize(int count, Unicode ch = ' ');
00229 
00233         void ToUpper();
00234 
00238         void ToLower();
00239 
00244          void Reserve(int count);
00245 
00252          const Unicode* CStr() const;
00253         
00258          bool IsInAscii() const;
00259 
00277          int ConvertToAscii(char* in_out_buf, int buf_sz, bool null_term) const;
00278 
00283          std::string ConvertToAscii() const; 
00284 
00310          int ConvertToPDFText(char* in_out_buf, int buf_sz, bool force_unicode = false) const;
00311 
00312          friend bool operator == (const UString& rStr1, const UString& rStr2) { return rStr1.GetLength() == rStr2.GetLength() && rStr1.Compare( rStr2 ) == 0; }
00313          friend bool operator == (const UString& rStr1, const Unicode* pStr2) { return rStr1.Compare( pStr2 ) == 0; }
00314          friend bool operator == (const Unicode* pStr1, const UString& rStr2) { return UString( pStr1 ).Compare( rStr2 ) == 0; }
00315          friend bool operator != (const UString& rStr1, const UString& rStr2) { return !(operator == ( rStr1, rStr2 )); }
00316          friend bool operator != (const UString& rStr1, const Unicode* pStr2) { return !(operator == ( rStr1, pStr2 )); }
00317          friend bool operator != (const Unicode* pStr1, const UString& rStr2) { return !(operator == ( pStr1, rStr2 )); }
00318          friend bool operator <  (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) < 0; }
00319          friend bool operator >  (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) > 0; }
00320          friend bool operator <= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) <= 0; }
00321          friend bool operator >= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) >= 0; }
00322         
00323 // private:
00325         UString(TRN_UString impl);
00326         TRN_UString mp_impl;  
00327 
00328 };
00329 
00330 
00336 inline std::ostream& operator<<(std::ostream& stream, const UString& str) {
00337         return stream << str.ConvertToAscii();
00338 }
00339 
00340 
00341 #include <Impl/UString.inl>
00342 
00343 
00344 };      // namespace pdftron
00345 
00346 #endif // H_CPPPDFTRON_UNISTRING

© 2002-2008 PDFTron Systems Inc.