Blame view

morfeusz/charset/CharsetConverter.hpp 1.79 KB
Michał Lenart authored
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
Michał Lenart authored
11
#include <inttypes.h>
Michał Lenart authored
12
#include <string>
Michał Lenart authored
13
14
#include <vector>
#include <map>
Michał Lenart authored
15
Michał Lenart authored
16
17
class CharsetConverter {
public:
Michał Lenart authored
18
    virtual uint32_t peek(const char*& it, const char* end) const = 0;
Michał Lenart authored
19
    virtual uint32_t next(const char*& it, const char* end) const = 0;
Michał Lenart authored
20
    virtual void append(uint32_t cp, std::string& result) const = 0;
Michał Lenart authored
21
    virtual std::string fromUTF8(const std::string& input) const;
Michał Lenart authored
22
Michał Lenart authored
23
    std::string toString(const std::vector<uint32_t>& codepoints) const;
Michał Lenart authored
24
25

    virtual ~CharsetConverter();
Michał Lenart authored
26
27
28
private:
};
Michał Lenart authored
29
class UTF8CharsetConverter : public CharsetConverter {
Michał Lenart authored
30
public:
Michał Lenart authored
31
    uint32_t peek(const char*& it, const char* end) const;
Michał Lenart authored
32
    uint32_t next(const char*& it, const char* end) const;
Michał Lenart authored
33
    void append(uint32_t cp, std::string& result) const;
Michał Lenart authored
34
    //    std::string fromUTF8(const std::string& input) const;
Michał Lenart authored
35
36
37
private:
};
Michał Lenart authored
38
39
40
/*
 * Converter that uses a simple conversion table
 */
Michał Lenart authored
41
class OneByteCharsetConverter : public CharsetConverter {
Michał Lenart authored
42
public:
Michał Lenart authored
43
    explicit OneByteCharsetConverter(const uint32_t* array);
Michał Lenart authored
44
    uint32_t peek(const char*& it, const char* end) const;
Michał Lenart authored
45
    uint32_t next(const char*& it, const char* end) const;
Michał Lenart authored
46
    void append(uint32_t cp, std::string& result) const;
Michał Lenart authored
47
private:
Michał Lenart authored
48
49
50
51
    const uint32_t* array;
    const std::vector<char> codepoint2Char;
};
Michał Lenart authored
52
class ISO8859_2_CharsetConverter : public OneByteCharsetConverter {
Michał Lenart authored
53
public:
Michał Lenart authored
54
    ISO8859_2_CharsetConverter();
Michał Lenart authored
55
56
57
private:
};
Michał Lenart authored
58
class Windows_1250_CharsetConverter : public OneByteCharsetConverter {
Michał Lenart authored
59
public:
Michał Lenart authored
60
    Windows_1250_CharsetConverter();
Michał Lenart authored
61
private:
Michał Lenart authored
62
63
};
Michał Lenart authored
64
65
66
67
68
69
class CP852_CharsetConverter : public OneByteCharsetConverter {
public:
    CP852_CharsetConverter();
private:
};
Michał Lenart authored
70
71
#endif	/* ENCODINGCONVERTER_HPP */