00001
00002
00003
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 = 0,
00070 e_pdfdoc_enc,
00071 e_winansii_enc,
00072 e_pdftext_enc,
00073 e_utf16be_enc,
00074 e_utf8,
00075 e_no_enc
00076 };
00077
00088 UString(const char* buf, int buf_sz = -1, TextEncoding enc = e_ascii_enc);
00089
00093 ~UString();
00094
00099 UString& operator=(const UString& str);
00100 UString& operator=(const char* ascii_str);
00101
00106 UString& Assign(const UString& uni);
00107 UString& Assign(const Unicode* uni, int buf_sz = -1);
00108 UString& Assign2(const char* buf, int buf_sz = -1, TextEncoding enc = e_ascii_enc);
00109
00114 UString& operator+=(const UString& str);
00115
00123 UString Concat(const UString &str) const;
00124
00125 friend UString operator+( const UString& str1, const UString& str2) { return str1.Concat(str2);}
00126
00133 int GetLength() const;
00134
00139 bool Empty() const;
00140
00148 const Unicode* GetBuffer() const;
00149
00165 int Compare(const UString& str, int max_length = -1) const;
00166
00186 int Compare(const char* ascii_string, int max_length = -1) const;
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201 UString SubStr(int off = 0, int count = -1) const;
00202
00215 Unicode GetAt(int idx) const;
00216
00221 void PushBack(Unicode ch);
00222
00230 void Resize(int count, Unicode ch = ' ');
00231
00235 void ToUpper();
00236
00240 void ToLower();
00241
00246 void Reserve(int count);
00247
00254 const Unicode* CStr() const;
00255
00260 bool IsInAscii() const;
00261
00279 int ConvertToAscii(char* in_out_buf, int buf_sz, bool null_term) const;
00280
00299 int ConvertToUtf8(char* in_out_buf, int buf_sz, bool null_term) const;
00300
00305 std::string ConvertToAscii() const;
00306
00311 std::string ConvertToUtf8() const;
00312
00338 int ConvertToPDFText(char* in_out_buf, int buf_sz, bool force_unicode = false) const;
00339
00340 friend bool operator == (const UString& rStr1, const UString& rStr2) { return rStr1.GetLength() == rStr2.GetLength() && rStr1.Compare( rStr2 ) == 0; }
00341 friend bool operator == (const UString& rStr1, const Unicode* pStr2) { return rStr1.Compare( pStr2 ) == 0; }
00342 friend bool operator == (const Unicode* pStr1, const UString& rStr2) { return UString( pStr1 ).Compare( rStr2 ) == 0; }
00343 friend bool operator != (const UString& rStr1, const UString& rStr2) { return !(operator == ( rStr1, rStr2 )); }
00344 friend bool operator != (const UString& rStr1, const Unicode* pStr2) { return !(operator == ( rStr1, pStr2 )); }
00345 friend bool operator != (const Unicode* pStr1, const UString& rStr2) { return !(operator == ( pStr1, rStr2 )); }
00346 friend bool operator < (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) < 0; }
00347 friend bool operator > (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) > 0; }
00348 friend bool operator <= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) <= 0; }
00349 friend bool operator >= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) >= 0; }
00350
00351
00353 UString(TRN_UString impl);
00354 TRN_UString mp_impl;
00355
00356 };
00357
00358
00364 inline std::ostream& operator<<(std::ostream& stream, const UString& str) {
00365 return stream << str.ConvertToAscii();
00366 }
00367
00368
00369 #include <Impl/UString.inl>
00370
00371
00372 };
00373
00374 #endif // H_CPPPDFTRON_UNISTRING