Loading...
Searching...
No Matches
UString.h
Go to the documentation of this file.
1//---------------------------------------------------------------------------------------
2// Copyright (c) 2001-2025 by Apryse Software Inc. All Rights Reserved.
3// Consult legal.txt regarding legal and license information.
4//---------------------------------------------------------------------------------------
5#ifndef PDFTRON_H_CPPCommonUString
6#define PDFTRON_H_CPPCommonUString
7
8#include <Common/BasicTypes.h>
9#include <Common/Exception.h>
10#include <C/Common/TRN_Types.h>
11#include <C/Common/TRN_UString.h>
12#include <Common/Common.h>
13#include <Common/CharTraits.h>
14#include <ostream>
15
16 namespace pdftron {
17
27 class UString
28{
29 public:
30
34 UString();
35
40 UString(const UString& str);
41
47 explicit UString(Unicode value);
48
54 UString(const Unicode* value);
55
63 UString(const Unicode* value, int length);
64
68 enum TextEncoding {
69 e_ascii_enc = 0,
70 e_pdfdoc_enc,
71 e_winansii_enc,
72 e_pdftext_enc,
73 e_utf16be_enc,
74 e_utf8,
75 e_no_enc
76 };
77
88 UString(const char* buf, int buf_sz = -1, TextEncoding enc = e_utf8);
89
97 UString(const std::string & str, TextEncoding enc = e_utf8);
98
104 UString( const std::wstring& value );
105
109 ~UString();
110
115 UString& operator=(const UString& str);
116 UString& operator=(const char* ascii_str);
117
122 UString& Assign(const UString& uni);
123 UString& Assign(const Unicode* uni, int buf_sz = -1);
124 UString& Assign2(const char* buf, int buf_sz = -1, TextEncoding enc = e_utf8);
125
130 UString& operator+=(const UString& str);
131
139 UString Concat(const UString &str) const;
140
141 friend UString operator+( const UString& str1, const UString& str2) { return str1.Concat(str2);}
142
149 int GetLength() const;
150
155 bool Empty() const;
156
164 const Unicode* GetBuffer() const;
165
181 int Compare(const UString& str, int max_length = -1) const;
182
196 UString SubStr(int off = 0, int count = -1) const;
197
209 Unicode GetAt(int idx) const;
210
215 void PushBack(Unicode ch);
216
224 void Resize(int count, Unicode ch = ' ');
225
229 void ToUpper();
230
234 void ToLower();
235
240 void Reserve(int count);
241
248 const Unicode* CStr() const;
249
254 bool IsInAscii() const;
255
273 int ConvertToAscii(char* in_out_buf, int buf_sz, bool null_term) const;
274
293 int ConvertToUtf8(char* in_out_buf, int buf_sz, bool null_term) const;
294
313 int ConvertToUtf32( UInt32* in_out_buf, int buf_sz, bool null_term ) const;
314
318 std::wstring ConvertToNativeWString() const;
319
324 std::string ConvertToAscii() const;
325
330 std::string ConvertToUtf8() const;
331
335 std::basic_string<UInt32> ConvertToUtf32() const;
336
362 int ConvertToPDFText(char* in_out_buf, int buf_sz, bool force_unicode = false) const;
363
364 friend bool operator == (const UString& rStr1, const UString& rStr2) { return rStr1.GetLength() == rStr2.GetLength() && rStr1.Compare( rStr2 ) == 0; }
365 friend bool operator == (const UString& rStr1, const Unicode* pStr2) { return rStr1.Compare( pStr2 ) == 0; }
366 friend bool operator == (const Unicode* pStr1, const UString& rStr2) { return UString( pStr1 ).Compare( rStr2 ) == 0; }
367 friend bool operator != (const UString& rStr1, const UString& rStr2) { return !(operator == ( rStr1, rStr2 )); }
368 friend bool operator != (const UString& rStr1, const Unicode* pStr2) { return !(operator == ( rStr1, pStr2 )); }
369 friend bool operator != (const Unicode* pStr1, const UString& rStr2) { return !(operator == ( pStr1, rStr2 )); }
370 friend bool operator < (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) < 0; }
371 friend bool operator > (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) > 0; }
372 friend bool operator <= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) <= 0; }
373 friend bool operator >= (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) >= 0; }
374
375// private:
376 // @cond PRIVATE_DOC
377 UString(TRN_UString impl);
378 TRN_UString mp_impl;
379 // @endcond
380};
381
382
388 inline std::ostream& operator<<(std::ostream& stream, const UString& str) {
389 return stream << str.ConvertToAscii();
390}
391
392
393#include <Impl/UString.inl>
394
395
396}; // namespace pdftron
397
398#endif // PDFTRON_H_CPPCommonUString
BasicTypes.h
CharTraits.h
Common.h
Exception.h
pdftron::UString
Definition UString.h:28
pdftron::UString::Compare
int Compare(const UString &str, int max_length=-1) const
pdftron::UString::operator==
friend bool operator==(const UString &rStr1, const UString &rStr2)
Definition UString.h:364
pdftron::UString::Assign
UString & Assign(const UString &uni)
pdftron::UString::ConvertToUtf8
int ConvertToUtf8(char *in_out_buf, int buf_sz, bool null_term) const
pdftron::UString::UString
UString(const char *buf, int buf_sz=-1, TextEncoding enc=e_utf8)
pdftron::UString::UString
UString(const UString &str)
pdftron::UString::operator!=
friend bool operator!=(const UString &rStr1, const UString &rStr2)
Definition UString.h:367
pdftron::UString::GetBuffer
const Unicode * GetBuffer() const
pdftron::UString::GetLength
int GetLength() const
pdftron::UString::Resize
void Resize(int count, Unicode ch=' ')
pdftron::UString::Assign2
UString & Assign2(const char *buf, int buf_sz=-1, TextEncoding enc=e_utf8)
pdftron::UString::GetAt
Unicode GetAt(int idx) const
pdftron::UString::Reserve
void Reserve(int count)
pdftron::UString::ToUpper
void ToUpper()
pdftron::UString::ConvertToAscii
std::string ConvertToAscii() const
pdftron::UString::ConvertToUtf8
std::string ConvertToUtf8() const
pdftron::UString::operator=
UString & operator=(const UString &str)
pdftron::UString::UString
UString(const std::wstring &value)
pdftron::UString::operator+=
UString & operator+=(const UString &str)
pdftron::UString::Empty
bool Empty() const
pdftron::UString::UString
UString()
pdftron::UString::UString
UString(const std::string &str, TextEncoding enc=e_utf8)
pdftron::UString::Concat
UString Concat(const UString &str) const
pdftron::UString::operator=
UString & operator=(const char *ascii_str)
pdftron::UString::ToLower
void ToLower()
pdftron::UString::~UString
~UString()
pdftron::UString::ConvertToNativeWString
std::wstring ConvertToNativeWString() const
pdftron::UString::ConvertToAscii
int ConvertToAscii(char *in_out_buf, int buf_sz, bool null_term) const
pdftron::UString::IsInAscii
bool IsInAscii() const
pdftron::UString::UString
UString(const Unicode *value, int length)
pdftron::UString::CStr
const Unicode * CStr() const
pdftron::UString::operator>
friend bool operator>(const UString &rStr1, const UString &rStr2)
Definition UString.h:371
pdftron::UString::ConvertToPDFText
int ConvertToPDFText(char *in_out_buf, int buf_sz, bool force_unicode=false) const
pdftron::UString::Assign
UString & Assign(const Unicode *uni, int buf_sz=-1)
pdftron::UString::UString
UString(Unicode value)
pdftron::UString::operator>=
friend bool operator>=(const UString &rStr1, const UString &rStr2)
Definition UString.h:373
pdftron::UString::SubStr
UString SubStr(int off=0, int count=-1) const
pdftron::UString::PushBack
void PushBack(Unicode ch)
pdftron::UString::ConvertToUtf32
std::basic_string< UInt32 > ConvertToUtf32() const
pdftron::UString::TextEncoding
TextEncoding
Definition UString.h:68
pdftron::UString::e_winansii_enc
@ e_winansii_enc
WinAnsiiEncoding. See Appendix 'D' in PDF Reference.
Definition UString.h:71
pdftron::UString::e_pdfdoc_enc
@ e_pdfdoc_enc
PDFDocEncoding. See Appendix 'D' in PDF Reference.
Definition UString.h:70
pdftron::UString::e_pdftext_enc
@ e_pdftext_enc
Text represented as PDF Text (section 3.8.1 'Text Strings' in PDF Reference).
Definition UString.h:72
pdftron::UString::e_no_enc
@ e_no_enc
No specific encoding.
Definition UString.h:75
pdftron::UString::e_utf16be_enc
@ e_utf16be_enc
UTF-16BE (big-endian) encoding scheme.
Definition UString.h:73
pdftron::UString::e_utf8
@ e_utf8
UTF-8 encoding scheme.
Definition UString.h:74
pdftron::UString::e_ascii_enc
@ e_ascii_enc
ASCII encoded text.
Definition UString.h:69
pdftron::UString::operator+
friend UString operator+(const UString &str1, const UString &str2)
Definition UString.h:141
pdftron::UString::operator<
friend bool operator<(const UString &rStr1, const UString &rStr2)
Definition UString.h:370
pdftron::UString::UString
UString(const Unicode *value)
pdftron::UString::ConvertToUtf32
int ConvertToUtf32(UInt32 *in_out_buf, int buf_sz, bool null_term) const
pdftron::UString::operator<=
friend bool operator<=(const UString &rStr1, const UString &rStr2)
Definition UString.h:372
pdftron
Definition BasicTypes.h:10
pdftron::UInt32
TRN_UInt32 UInt32
Definition BasicTypes.h:13
pdftron::operator<<
std::ostream & operator<<(std::ostream &stream, const UString &str)
Definition UString.h:388
pdftron::Unicode
TRN_Unicode Unicode
Definition BasicTypes.h:22