ScummVM API documentation
ustr.h
1/* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
21
22#ifndef COMMON_USTR_H
23#define COMMON_USTR_H
24
25#include "common/scummsys.h"
26#include "common/util.h"
27#include "common/str-enc.h"
28#include "common/str-base.h"
29
30namespace Common {
31
41class String;
42
55typedef char32_t u32char_type_t;
56
57class U32String : public BaseString<u32char_type_t> {
58public:
59 typedef uint32 unsigned_type;
60public:
63
65 explicit U32String(const value_type *str) : BaseString<u32char_type_t>(str) {}
66
68 U32String(const value_type *str, uint32 len) : BaseString<u32char_type_t>(str, len) {}
69
71 U32String(const value_type *beginP, const value_type *endP) : BaseString<u32char_type_t>(beginP, endP) {}
72
75
78
80 explicit U32String(const char *str, CodePage page = kUtf8);
81
83 U32String(const char *str, uint32 len, CodePage page = kUtf8);
84
86 U32String(const char *beginP, const char *endP, CodePage page = kUtf8);
87
89 U32String(const String &str, CodePage page = kUtf8);
90
92 explicit constexpr U32String(value_type c) : BaseString<u32char_type_t>(c) {}
93
95 U32String(size_t n, value_type c) : BaseString<u32char_type_t>(n, c) {}
96
99
102
105
107 U32String &operator=(const value_type *str);
108
110 U32String &operator=(const char *str);
111
113 U32String &operator=(value_type c);
114
117
119 U32String &operator+=(const value_type *str);
120
122 U32String &operator+=(value_type c);
123
125 String encode(CodePage page = kUtf8) const;
126
129 StringEncodingResult encode(String &outString, CodePage page, char errorChar) const;
130
137 template<class... TParam>
138 static U32String format(const U32String &fmt, TParam... param);
139
141 static U32String format(const char *fmt, ...);
142
147 static int vformat(const value_type *fmt, const value_type *fmtEnd, U32String &output, va_list args);
148
150 U32String substr(size_t pos = 0, size_t len = npos) const;
151
153 static Common::U32String decodeUTF16BE(const uint16 *start, uint len);
154
156 static Common::U32String decodeUTF16LE(const uint16 *start, uint len);
157
159 static Common::U32String decodeUTF16Native(const uint16 *start, uint len);
160
162 uint16 *encodeUTF16BE(uint *len = nullptr) const;
163
165 uint16 *encodeUTF16LE(uint *len = nullptr) const;
166
168 uint16 *encodeUTF16Native(uint *len = nullptr) const;
169
172
173private:
174 static U32String formatInternal(const U32String *fmt, ...);
175
180 static value_type* ustr_helper_itoa(int num, value_type* str, uint base);
181
186 static value_type* ustr_helper_uitoa(uint num, value_type* str, uint base);
187
188 void decodeInternal(const char *str, uint32 len, CodePage page);
189 void decodeOneByte(const char *str, uint32 len, CodePage page);
190 void decodeWindows932(const char *src, uint32 len);
191 void decodeWindows936(const char *src, uint32 len);
192 void decodeWindows949(const char *src, uint32 len);
193 void decodeWindows950(const char *src, uint32 len);
194 void decodeJohab(const char *src, uint32 len);
195 void decodeUTF8(const char *str, uint32 len);
196
197 friend class String;
198};
199
200template<class... TParam>
201inline U32String U32String::format(const U32String &fmt, TParam... param) {
202 return formatInternal(&fmt, Common::forward<TParam>(param)...);
203}
204
207
209U32String operator+(const U32String &x, U32String::value_type y);
210
221U32String toPrintable(const U32String &src, bool keepNewLines = true);
222
225} // End of namespace Common
226
227#endif
Definition: str-base.h:32
Definition: str.h:59
Definition: ustr.h:57
U32String & operator=(const value_type *str)
U32String & operator=(const char *str)
U32String(const value_type *str, uint32 len)
Definition: ustr.h:68
uint16 * encodeUTF16Native(uint *len=nullptr) const
U32String(const value_type *beginP, const value_type *endP)
Definition: ustr.h:71
U32String & operator+=(value_type c)
uint16 * encodeUTF16BE(uint *len=nullptr) const
U32String(const value_type *str)
Definition: ustr.h:65
U32String & operator=(U32String &&str)
U32String(const U32String &str)
Definition: ustr.h:74
U32String(U32String &&str)
Definition: ustr.h:77
U32String transcodeChineseT2S() const
U32String & operator+=(const U32String &str)
constexpr U32String()
Definition: ustr.h:62
constexpr U32String(value_type c)
Definition: ustr.h:92
U32String(const char *str, CodePage page=kUtf8)
StringEncodingResult encode(String &outString, CodePage page, char errorChar) const
U32String & operator=(value_type c)
U32String substr(size_t pos=0, size_t len=npos) const
U32String & operator=(const String &str)
static Common::U32String decodeUTF16BE(const uint16 *start, uint len)
static Common::U32String decodeUTF16LE(const uint16 *start, uint len)
uint16 * encodeUTF16LE(uint *len=nullptr) const
U32String(size_t n, value_type c)
Definition: ustr.h:95
U32String & operator=(const U32String &str)
static Common::U32String decodeUTF16Native(const uint16 *start, uint len)
static int vformat(const value_type *fmt, const value_type *fmtEnd, U32String &output, va_list args)
U32String & operator+=(const value_type *str)
U32String(const String &str, CodePage page=kUtf8)
uint32 unsigned_type
Definition: ustr.h:59
U32String(const char *str, uint32 len, CodePage page=kUtf8)
String encode(CodePage page=kUtf8) const
static U32String format(const char *fmt,...)
U32String(const char *beginP, const char *endP, CodePage page=kUtf8)
String toPrintable(const String &src, bool keepNewLines=true)
char32_t u32char_type_t
Definition: ustr.h:55
static U32String format(const U32String &fmt, TParam... param)
Definition: ustr.h:201
Definition: algorithm.h:29
DBCSString operator+(const DBCSString &x, const DBCSString &y)