summaryrefslogtreecommitdiff
path: root/lib_dxf/intern/drw_textcodec.h
blob: 1a8c56a41045a3a602089cd0a8534d8dc3c045f6 (plain)
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
89
90
91
92
93
94
95
96
97
98
99
#ifndef DRW_TEXTCODEC_H
#define DRW_TEXTCODEC_H

#include <string>

class DRW_Converter;

class DRW_TextCodec
{
public:
    DRW_TextCodec();
    ~DRW_TextCodec();
    std::string fromUtf8( std::string s );
    std::string toUtf8( std::string s );

    int getVersion() { return version; }
    void setVersion( std::string* v );

    void setVersion( int v ) { version = v; }
    void setCodePage( std::string* c );

    void setCodePage( std::string c ) { setCodePage( &c ); }
    std::string getCodePage() { return cp; }

private:
    std::string correctCodePage( const std::string& s );

private:
    int version;
    std::string cp;
    DRW_Converter* conv;
};

class DRW_Converter
{
public:
    DRW_Converter( const int* t, int l )
    {
        table = t;
        cpLenght = l;
    }

    virtual ~DRW_Converter() {}
    virtual std::string fromUtf8( std::string* s ) { return *s; }
    virtual std::string toUtf8( std::string* s );
    std::string         encodeText( std::string stmp );
    std::string         decodeText( int c );
    std::string         encodeNum( int c );
    int                 decodeNum( std::string s, int* b );

    const int* table;
    int cpLenght;
};

class DRW_ConvTable : public DRW_Converter
{
public:
    DRW_ConvTable( const int* t, int l ) : DRW_Converter( t, l ) {}
    virtual std::string fromUtf8( std::string* s );
    virtual std::string toUtf8( std::string* s );
};

class DRW_ConvDBCSTable : public DRW_Converter
{
public:
    DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
                l )
    {
        leadTable = lt;
        doubleTable = dt;
    }

    virtual std::string fromUtf8( std::string* s );
    virtual std::string toUtf8( std::string* s );

private:
    const int* leadTable;
    const int (*doubleTable)[2];
};

class DRW_Conv932Table : public DRW_Converter
{
public:
    DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
                l )
    {
        leadTable = lt;
        doubleTable = dt;
    }

    virtual std::string fromUtf8( std::string* s );
    virtual std::string toUtf8( std::string* s );

private:
    const int* leadTable;
    const int (*doubleTable)[2];
};

#endif    // DRW_TEXTCODEC_H