xoreos  0.0.5
encoding.h
Go to the documentation of this file.
1 /* xoreos - A reimplementation of BioWare's Aurora engine
2  *
3  * xoreos is the legal property of its developers, whose names
4  * can be found in the AUTHORS file distributed with this source
5  * distribution.
6  *
7  * xoreos is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 3
10  * of the License, or (at your option) any later version.
11  *
12  * xoreos 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 xoreos. If not, see <http://www.gnu.org/licenses/>.
19  */
20 
25 #ifndef COMMON_ENCODING_H
26 #define COMMON_ENCODING_H
27 
28 #include "src/common/types.h"
29 
30 namespace Common {
31 
32 class UString;
33 class SeekableReadStream;
34 class MemoryReadStream;
35 class WriteStream;
36 
37 enum Encoding {
39 
41 
43 
46 
48 
52 
57 
59 };
60 
62 UString getEncodingName(Encoding encoding);
63 
68 bool hasSupportEncoding(Encoding encoding);
69 
76 UString readString(SeekableReadStream &stream, Encoding encoding);
77 
83 UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length);
84 
96 UString readStringLine(SeekableReadStream &stream, Encoding encoding);
97 
103 UString readString(const byte *data, size_t size, Encoding encoding);
104 
115 size_t writeString(WriteStream &stream, const Common::UString &str, Encoding encoding, bool terminate = true);
116 
126 void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length);
127 
136 MemoryReadStream *convertString(const UString &str, Encoding encoding, bool terminateString = true);
137 
142 size_t getBytesPerCodepoint(Encoding encoding);
143 
148 bool isValidCodepoint(Encoding encoding, uint32 cp);
149 
150 } // End of namespace Common
151 
152 #endif // COMMON_ENCODING_H
Definition: 2dafile.h:39
bool hasSupportEncoding(Encoding encoding)
Do we have support for this encoding?
Definition: encoding.cpp:193
A class holding an UTF-8 string.
Definition: ustring.h:48
UString getEncodingName(Encoding encoding)
Return the human readable name of an encoding.
Definition: encoding.cpp:186
size_t writeString(WriteStream &stream, const Common::UString &str, Encoding encoding, bool terminate)
Write a string into a stream with a given encoding.
Definition: encoding.cpp:339
UTF-16 LE (little endian).
Definition: encoding.h:44
UTF-16 BE (big endian).
Definition: encoding.h:45
size_t getBytesPerCodepoint(Encoding encoding)
Return the number of bytes per codepoint in this encoding.
Definition: encoding.cpp:366
UString readStringLine(SeekableReadStream &stream, Encoding encoding)
Read a line with the given encoding out of a stream.
Definition: encoding.cpp:310
ISO-8859-15 (Latin-9).
Definition: encoding.h:47
Windows codepage 950 (Traditional Chinese, similar to Big5).
Definition: encoding.h:56
Encoding
Definition: encoding.h:37
Low-level type definitions to handle fixed width types portably.
For range checks.
Definition: encoding.h:58
Plain, unextended ASCII (7bit clean).
Definition: encoding.h:40
Windows codepage 932 (Japanese, extended Shift-JIS).
Definition: encoding.h:53
uint32_t uint32
Definition: types.h:204
Windows codepage 1250 (Eastern European, Latin alphabet).
Definition: encoding.h:49
UString readString(SeekableReadStream &stream, Encoding encoding)
Read a string with the given encoding of a stream.
Definition: encoding.cpp:287
Windows codepage 1251 (Eastern European, Cyrillic alphabet).
Definition: encoding.h:50
UString readStringFixed(SeekableReadStream &stream, Encoding encoding, size_t length)
Read length bytes as a string with the given encoding out of a stream.
Definition: encoding.cpp:297
Windows codepage 1252 (Western European, Latin alphabet).
Definition: encoding.h:51
bool isValidCodepoint(Encoding encoding, uint32 cp)
Return whether the given codepoint is valid in this encoding.
Definition: encoding.cpp:393
MemoryReadStream * convertString(const UString &str, Encoding encoding, bool terminateString)
Convert a string into the given encoding.
Definition: encoding.cpp:358
Windows codepage 949 (Korean, similar to EUC-KR).
Definition: encoding.h:55
Windows codepage 936 (Simplified Chinese, extended GB2312 with GBK codepoints).
Definition: encoding.h:54
uint8 byte
Definition: types.h:209
void writeStringFixed(WriteStream &stream, const Common::UString &str, Encoding encoding, size_t length)
Write a string into a stream with a given encoding and fixed length in bytes.
Definition: encoding.cpp:347