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_utf8);
00089
00097 UString(const std::string & str, TextEncoding enc = e_utf8);
00098
00104 UString( const std::wstring& value );
00105
00109 ~UString();
00110
00115 UString& operator=(const UString& str);
00116 UString& operator=(const char* ascii_str);
00117
00122 UString& Assign(const UString& uni);
00123 UString& Assign(const Unicode* uni, int buf_sz = -1);
00124 UString& Assign2(const char* buf, int buf_sz = -1, TextEncoding enc = e_utf8);
00125
00130 UString& operator+=(const UString& str);
00131
00139 UString Concat(const UString &str) const;
00140
00141 friend UString operator+( const UString& str1, const UString& str2) { return str1.Concat(str2);}
00142
00149 int GetLength() const;
00150
00155 bool Empty() const;
00156
00164 const Unicode* GetBuffer() const;
00165
00181 int Compare(const UString& str, int max_length = -1) const;
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196 UString SubStr(int off = 0, int count = -1) const;
00197
00209 Unicode GetAt(int idx) const;
00210
00215 void PushBack(Unicode ch);
00216
00224 void Resize(int count, Unicode ch = ' ');
00225
00229 void ToUpper();
00230
00234 void ToLower();
00235
00240 void Reserve(int count);
00241
00248 const Unicode* CStr() const;
00249
00254 bool IsInAscii() const;
00255
00273 int ConvertToAscii(char* in_out_buf, int buf_sz, bool null_term) const;
00274
00293 int ConvertToUtf8(char* in_out_buf, int buf_sz, bool null_term) const;
00294
00313 int ConvertToUtf32( UInt32* out_buf, int buf_sz, bool null_term ) const;
00314
00318 std::wstring ConvertToNativeWString() const;
00319
00324 std::string ConvertToAscii() const;
00325
00330 std::string ConvertToUtf8() const;
00331
00335 std::basic_string<UInt32> ConvertToUtf32() const;
00336
00362 int ConvertToPDFText(char* in_out_buf, int buf_sz, bool force_unicode = false) const;
00363
00364 friend bool operator == (const UString& rStr1, const UString& rStr2) { return rStr1.GetLength() == rStr2.GetLength() && rStr1.Compare( rStr2 ) == 0; }
00365 friend bool operator == (const UString& rStr1, const Unicode* pStr2) { return rStr1.Compare( pStr2 ) == 0; }
00366 friend bool operator == (const Unicode* pStr1, const UString& rStr2) { return UString( pStr1 ).Compare( rStr2 ) == 0; }
00367 friend bool operator != (const UString& rStr1, const UString& rStr2) { return !(operator == ( rStr1, rStr2 )); }
00368 friend bool operator != (const UString& rStr1, const Unicode* pStr2) { return !(operator == ( rStr1, pStr2 )); }
00369 friend bool operator != (const Unicode* pStr1, const UString& rStr2) { return !(operator == ( pStr1, rStr2 )); }
00370 friend bool operator < (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) < 0; }
00371 friend bool operator > (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) > 0; }
00372 friend bool operator <= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) <= 0; }
00373 friend bool operator >= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) >= 0; }
00374
00375
00377 UString(TRN_UString impl);
00378 TRN_UString mp_impl;
00379
00380 };
00381
00382
00388 inline std::ostream& operator<<(std::ostream& stream, const UString& str) {
00389 return stream << str.ConvertToAscii();
00390 }
00391
00392
00393 #include <Impl/UString.inl>
00394
00395
00396 };
00397
00398 #endif // H_CPPPDFTRON_UNISTRING