All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
UString.h
Go to the documentation of this file.
1 //---------------------------------------------------------------------------------------
2 // Copyright (c) 2001-2020 by PDFTron Systems 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 <ostream>
14 
15 namespace pdftron {
16 
26 class UString
27 {
28 public:
29 
33  UString();
34 
39  UString(const UString& str);
40 
46  explicit UString(Unicode value);
47 
53  UString(const Unicode* value);
54 
62  UString(const Unicode* value, int length);
63 
67  enum TextEncoding {
75  };
76 
87  UString(const char* buf, int buf_sz = -1, TextEncoding enc = e_utf8);
88 
96  UString(const std::string & str, TextEncoding enc = e_utf8);
97 
103  UString( const std::wstring& value );
104 
108  ~UString();
109 
114  UString& operator=(const UString& str);
115  UString& operator=(const char* ascii_str);
116 
121  UString& Assign(const UString& uni);
122  UString& Assign(const Unicode* uni, int buf_sz = -1);
123  UString& Assign2(const char* buf, int buf_sz = -1, TextEncoding enc = e_utf8);
124 
129  UString& operator+=(const UString& str);
130 
138  UString Concat(const UString &str) const;
139 
140  friend UString operator+( const UString& str1, const UString& str2) { return str1.Concat(str2);}
141 
148  int GetLength() const;
149 
154  bool Empty() const;
155 
163  const Unicode* GetBuffer() const;
164 
180  int Compare(const UString& str, int max_length = -1) const;
181 
195  UString SubStr(int off = 0, int count = -1) const;
196 
208  Unicode GetAt(int idx) const;
209 
214  void PushBack(Unicode ch);
215 
223  void Resize(int count, Unicode ch = ' ');
224 
228  void ToUpper();
229 
233  void ToLower();
234 
239  void Reserve(int count);
240 
247  const Unicode* CStr() const;
248 
253  bool IsInAscii() const;
254 
272  int ConvertToAscii(char* in_out_buf, int buf_sz, bool null_term) const;
273 
292  int ConvertToUtf8(char* in_out_buf, int buf_sz, bool null_term) const;
293 
312  int ConvertToUtf32( UInt32* out_buf, int buf_sz, bool null_term ) const;
313 
317  std::wstring ConvertToNativeWString() const;
318 
323  std::string ConvertToAscii() const;
324 
329  std::string ConvertToUtf8() const;
330 
334  std::basic_string<UInt32> ConvertToUtf32() const;
335 
361  int ConvertToPDFText(char* in_out_buf, int buf_sz, bool force_unicode = false) const;
362 
363  friend bool operator == (const UString& rStr1, const UString& rStr2) { return rStr1.GetLength() == rStr2.GetLength() && rStr1.Compare( rStr2 ) == 0; }
364  friend bool operator == (const UString& rStr1, const Unicode* pStr2) { return rStr1.Compare( pStr2 ) == 0; }
365  friend bool operator == (const Unicode* pStr1, const UString& rStr2) { return UString( pStr1 ).Compare( rStr2 ) == 0; }
366  friend bool operator != (const UString& rStr1, const UString& rStr2) { return !(operator == ( rStr1, rStr2 )); }
367  friend bool operator != (const UString& rStr1, const Unicode* pStr2) { return !(operator == ( rStr1, pStr2 )); }
368  friend bool operator != (const Unicode* pStr1, const UString& rStr2) { return !(operator == ( pStr1, rStr2 )); }
369  friend bool operator < (const UString& rStr1, const UString& rStr2) { return rStr1.Compare( rStr2 ) < 0; }
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 
374 // private:
375  // @cond PRIVATE_DOC
376  UString(TRN_UString impl);
377  TRN_UString mp_impl;
378  // @endcond
379 };
380 
381 
387 inline std::ostream& operator<<(std::ostream& stream, const UString& str) {
388  return stream << str.ConvertToAscii();
389 }
390 
391 
392 #include <Impl/UString.inl>
393 
394 
395 }; // namespace pdftron
396 
397 #endif // PDFTRON_H_CPPCommonUString
std::string ConvertToUtf8() const
std::basic_string< UInt32 > ConvertToUtf32() const
friend UString operator+(const UString &str1, const UString &str2)
Definition: UString.h:140
void Reserve(int count)
ASCII encoded text.
Definition: UString.h:68
std::ostream & operator<<(std::ostream &stream, const UString &str)
Definition: UString.h:387
std::string ConvertToAscii() const
void Resize(int count, Unicode ch= ' ')
friend bool operator==(const UString &rStr1, const UString &rStr2)
Definition: UString.h:363
friend bool operator<=(const UString &rStr1, const UString &rStr2)
Definition: UString.h:371
int GetLength() const
Text represented as PDF Text (section 3.8.1 &#39;Text Strings&#39; in PDF Reference).
Definition: UString.h:71
std::wstring ConvertToNativeWString() const
TRN_Unicode Unicode
Definition: BasicTypes.h:22
bool Empty() const
int ConvertToAscii(char *in_out_buf, int buf_sz, bool null_term) const
int ConvertToPDFText(char *in_out_buf, int buf_sz, bool force_unicode=false) const
bool IsInAscii() const
TRN_UInt32 UInt32
Definition: BasicTypes.h:13
const Unicode * GetBuffer() const
UString Concat(const UString &str) const
UTF-16BE (big-endian) encoding scheme.
Definition: UString.h:72
UTF-8 encoding scheme.
Definition: UString.h:73
Unicode GetAt(int idx) const
UString & Assign(const UString &uni)
PDFDocEncoding. See Appendix &#39;D&#39; in PDF Reference.
Definition: UString.h:69
UString & operator+=(const UString &str)
friend bool operator<(const UString &rStr1, const UString &rStr2)
Definition: UString.h:369
friend bool operator!=(const UString &rStr1, const UString &rStr2)
Definition: UString.h:366
const Unicode * CStr() const
No specific encoding.
Definition: UString.h:74
int Compare(const UString &str, int max_length=-1) const
WinAnsiiEncoding. See Appendix &#39;D&#39; in PDF Reference.
Definition: UString.h:70
UString SubStr(int off=0, int count=-1) const
void PushBack(Unicode ch)
friend bool operator>=(const UString &rStr1, const UString &rStr2)
Definition: UString.h:372
UString & Assign2(const char *buf, int buf_sz=-1, TextEncoding enc=e_utf8)
friend bool operator>(const UString &rStr1, const UString &rStr2)
Definition: UString.h:370
UString & operator=(const UString &str)