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