|
1
2
3
4
5
6
7
8
9
10
|
/*
* File: EncodingConverter.hpp
* Author: mlenart
*
* Created on 14 listopad 2013, 17:28
*/
#ifndef ENCODINGCONVERTER_HPP
#define ENCODINGCONVERTER_HPP
|
|
11
|
#include <inttypes.h>
|
|
12
|
#include <string>
|
|
13
14
|
#include <vector>
#include <map>
|
|
15
|
|
|
16
17
|
class CharsetConverter {
public:
|
|
18
|
virtual uint32_t peek(const char*& it, const char* end) const = 0;
|
|
19
|
virtual uint32_t next(const char*& it, const char* end) const = 0;
|
|
20
|
virtual void append(uint32_t cp, std::string& result) const = 0;
|
|
21
|
virtual std::string fromUTF8(const std::string& input) const;
|
|
22
|
|
|
23
|
std::string toString(const std::vector<uint32_t>& codepoints) const;
|
|
24
25
|
virtual ~CharsetConverter();
|
|
26
27
28
|
private:
};
|
|
29
|
class UTF8CharsetConverter : public CharsetConverter {
|
|
30
|
public:
|
|
31
|
uint32_t peek(const char*& it, const char* end) const;
|
|
32
|
uint32_t next(const char*& it, const char* end) const;
|
|
33
|
void append(uint32_t cp, std::string& result) const;
|
|
34
|
// std::string fromUTF8(const std::string& input) const;
|
|
35
36
37
|
private:
};
|
|
38
39
40
|
/*
* Converter that uses a simple conversion table
*/
|
|
41
|
class OneByteCharsetConverter : public CharsetConverter {
|
|
42
|
public:
|
|
43
|
explicit OneByteCharsetConverter(const uint32_t* array);
|
|
44
|
uint32_t peek(const char*& it, const char* end) const;
|
|
45
|
uint32_t next(const char*& it, const char* end) const;
|
|
46
|
void append(uint32_t cp, std::string& result) const;
|
|
47
|
private:
|
|
48
49
50
51
|
const uint32_t* array;
const std::vector<char> codepoint2Char;
};
|
|
52
|
class ISO8859_2_CharsetConverter : public OneByteCharsetConverter {
|
|
53
|
public:
|
|
54
|
ISO8859_2_CharsetConverter();
|
|
55
56
57
|
private:
};
|
|
58
|
class Windows_1250_CharsetConverter : public OneByteCharsetConverter {
|
|
59
|
public:
|
|
60
|
Windows_1250_CharsetConverter();
|
|
61
|
private:
|
|
62
63
|
};
|
|
64
65
66
67
68
69
|
class CP852_CharsetConverter : public OneByteCharsetConverter {
public:
CP852_CharsetConverter();
private:
};
|
|
70
71
|
#endif /* ENCODINGCONVERTER_HPP */
|