mirror of
https://gitlab.com/OpenMW/openmw.git
synced 2025-04-30 05:47:57 +03:00
Imported Upstream version 0.26.0
This commit is contained in:
commit
9a2b6c69b6
1398 changed files with 212217 additions and 0 deletions
55
components/to_utf8/to_utf8.hpp
Normal file
55
components/to_utf8/to_utf8.hpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
#ifndef COMPONENTS_TOUTF8_H
|
||||
#define COMPONENTS_TOUTF8_H
|
||||
|
||||
#include <string>
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
|
||||
namespace ToUTF8
|
||||
{
|
||||
// These are all the currently supported code pages
|
||||
enum FromType
|
||||
{
|
||||
WINDOWS_1250, // Central ane Eastern European languages
|
||||
WINDOWS_1251, // Cyrillic languages
|
||||
WINDOWS_1252, // Used by English version of Morrowind (and
|
||||
// probably others)
|
||||
CP437 // Used for fonts (*.fnt) if data files encoding is 1252. Otherwise, uses the same encoding as the data files.
|
||||
};
|
||||
|
||||
FromType calculateEncoding(const std::string& encodingName);
|
||||
std::string encodingUsingMessage(const std::string& encodingName);
|
||||
|
||||
// class
|
||||
|
||||
class Utf8Encoder
|
||||
{
|
||||
public:
|
||||
Utf8Encoder(FromType sourceEncoding);
|
||||
|
||||
// Convert to UTF8 from the previously given code page.
|
||||
std::string getUtf8(const char *input, size_t size);
|
||||
inline std::string getUtf8(const std::string &str)
|
||||
{
|
||||
return getUtf8(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
std::string getLegacyEnc(const char *input, size_t size);
|
||||
inline std::string getLegacyEnc(const std::string &str)
|
||||
{
|
||||
return getLegacyEnc(str.c_str(), str.size());
|
||||
}
|
||||
|
||||
private:
|
||||
void resize(size_t size);
|
||||
size_t getLength(const char* input, bool &ascii);
|
||||
void copyFromArray(unsigned char chp, char* &out);
|
||||
size_t getLength2(const char* input, bool &ascii);
|
||||
void copyFromArray2(const char*& chp, char* &out);
|
||||
|
||||
std::vector<char> mOutput;
|
||||
signed char* translationArray;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue