2010-08-18 18:45:44 +02:00
|
|
|
#ifndef COMPONENTS_TOUTF8_H
|
|
|
|
#define COMPONENTS_TOUTF8_H
|
|
|
|
|
|
|
|
#include <string>
|
2013-01-02 23:02:13 +01:00
|
|
|
#include <cstring>
|
|
|
|
#include <vector>
|
2022-02-12 11:52:52 +01:00
|
|
|
#include <string_view>
|
2010-08-18 18:45:44 +02:00
|
|
|
|
|
|
|
namespace ToUTF8
|
|
|
|
{
|
2013-01-02 23:02:13 +01:00
|
|
|
// These are all the currently supported code pages
|
|
|
|
enum FromType
|
2010-08-18 18:45:44 +02:00
|
|
|
{
|
2013-01-02 23:02:13 +01:00
|
|
|
WINDOWS_1250, // Central ane Eastern European languages
|
|
|
|
WINDOWS_1251, // Cyrillic languages
|
2013-06-06 22:13:30 +02:00
|
|
|
WINDOWS_1252, // Used by English version of Morrowind (and
|
2013-01-02 23:02:13 +01:00
|
|
|
// probably others)
|
2013-06-06 22:13:30 +02:00
|
|
|
CP437 // Used for fonts (*.fnt) if data files encoding is 1252. Otherwise, uses the same encoding as the data files.
|
2010-08-18 18:45:44 +02:00
|
|
|
};
|
|
|
|
|
2013-01-02 23:02:13 +01:00
|
|
|
FromType calculateEncoding(const std::string& encodingName);
|
|
|
|
std::string encodingUsingMessage(const std::string& encodingName);
|
|
|
|
|
|
|
|
// class
|
|
|
|
|
|
|
|
class Utf8Encoder
|
|
|
|
{
|
|
|
|
public:
|
2013-01-06 01:37:58 +01:00
|
|
|
Utf8Encoder(FromType sourceEncoding);
|
2013-01-02 23:02:13 +01:00
|
|
|
|
|
|
|
// Convert to UTF8 from the previously given code page.
|
2022-02-12 11:52:52 +01:00
|
|
|
std::string getUtf8(std::string_view input);
|
|
|
|
|
|
|
|
std::string getLegacyEnc(std::string_view input);
|
2013-01-02 23:02:13 +01:00
|
|
|
|
|
|
|
private:
|
|
|
|
void resize(size_t size);
|
2021-05-20 14:16:44 +02:00
|
|
|
size_t getLength(const char* input, bool &ascii) const;
|
|
|
|
void copyFromArray(unsigned char chp, char* &out) const;
|
|
|
|
size_t getLength2(const char* input, bool &ascii) const;
|
|
|
|
void copyFromArray2(const char*& chp, char* &out) const;
|
2013-01-02 23:02:13 +01:00
|
|
|
|
|
|
|
std::vector<char> mOutput;
|
2021-05-20 14:16:44 +02:00
|
|
|
const signed char* translationArray;
|
2013-01-02 23:02:13 +01:00
|
|
|
};
|
2010-08-18 18:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|