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
16namespace pdftron {
17
28{
29public:
30
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
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
110
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
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
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
388inline 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
int Compare(const UString &str, int max_length=-1) const
friend bool operator==(const UString &rStr1, const UString &rStr2)
Definition UString.h:364
UString & Assign(const UString &uni)
int ConvertToUtf8(char *in_out_buf, int buf_sz, bool null_term) const
UString(const char *buf, int buf_sz=-1, TextEncoding enc=e_utf8)
UString(const UString &str)
friend bool operator!=(const UString &rStr1, const UString &rStr2)
Definition UString.h:367
const Unicode * GetBuffer() const
int GetLength() const
void Resize(int count, Unicode ch=' ')
UString & Assign2(const char *buf, int buf_sz=-1, TextEncoding enc=e_utf8)
Unicode GetAt(int idx) const
void Reserve(int count)
std::string ConvertToAscii() const
std::string ConvertToUtf8() const
UString & operator=(const UString &str)
UString(const std::wstring &value)
UString & operator+=(const UString &str)
bool Empty() const
UString(const std::string &str, TextEncoding enc=e_utf8)
UString Concat(const UString &str) const
UString & operator=(const char *ascii_str)
std::wstring ConvertToNativeWString() const
int ConvertToAscii(char *in_out_buf, int buf_sz, bool null_term) const
bool IsInAscii() const
UString(const Unicode *value, int length)
const Unicode * CStr() const
friend bool operator>(const UString &rStr1, const UString &rStr2)
Definition UString.h:371
int ConvertToPDFText(char *in_out_buf, int buf_sz, bool force_unicode=false) const
UString & Assign(const Unicode *uni, int buf_sz=-1)
UString(Unicode value)
friend bool operator>=(const UString &rStr1, const UString &rStr2)
Definition UString.h:373
UString SubStr(int off=0, int count=-1) const
void PushBack(Unicode ch)
std::basic_string< UInt32 > ConvertToUtf32() const
@ e_winansii_enc
WinAnsiiEncoding. See Appendix 'D' in PDF Reference.
Definition UString.h:71
@ e_pdfdoc_enc
PDFDocEncoding. See Appendix 'D' in PDF Reference.
Definition UString.h:70
@ e_pdftext_enc
Text represented as PDF Text (section 3.8.1 'Text Strings' in PDF Reference).
Definition UString.h:72
@ e_no_enc
No specific encoding.
Definition UString.h:75
@ e_utf16be_enc
UTF-16BE (big-endian) encoding scheme.
Definition UString.h:73
@ e_utf8
UTF-8 encoding scheme.
Definition UString.h:74
@ e_ascii_enc
ASCII encoded text.
Definition UString.h:69
friend UString operator+(const UString &str1, const UString &str2)
Definition UString.h:141
friend bool operator<(const UString &rStr1, const UString &rStr2)
Definition UString.h:370
UString(const Unicode *value)
int ConvertToUtf32(UInt32 *in_out_buf, int buf_sz, bool null_term) const
friend bool operator<=(const UString &rStr1, const UString &rStr2)
Definition UString.h:372
TRN_UInt32 UInt32
Definition BasicTypes.h:13
std::ostream & operator<<(std::ostream &stream, const UString &str)
Definition UString.h:388
TRN_Unicode Unicode
Definition BasicTypes.h:22