drw_textcodec.h 2.41 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
#ifndef DRW_TEXTCODEC_H
#define DRW_TEXTCODEC_H

#include <string>

class DRW_Converter;

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

16 17 18 19 20 21 22 23
    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; }
24
private:
25
    std::string correctCodePage( const std::string& s );
26 27

private:
28 29 30
    int             version;
    std::string     cp;
    DRW_Converter*  conv;
31 32 33 34 35
};

class DRW_Converter
{
public:
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
    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;
52 53
};

54 55
class DRW_ConvTable : public DRW_Converter
{
56
public:
57 58 59
    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 );
60 61
};

62 63
class DRW_ConvDBCSTable : public DRW_Converter
{
64
public:
65 66 67 68
    DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
                                                                                                l )
    {
        leadTable   = lt;
69 70 71
        doubleTable = dt;
    }

72 73 74
    virtual std::string fromUtf8( std::string* s );
    virtual std::string toUtf8( std::string* s );

75
private:
76
    const int* leadTable;
77 78 79
    const int (*doubleTable)[2];
};

80 81
class DRW_Conv932Table : public DRW_Converter
{
82
public:
83 84 85 86
    DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
                                                                                               l )
    {
        leadTable   = lt;
87 88 89
        doubleTable = dt;
    }

90 91 92
    virtual std::string fromUtf8( std::string* s );
    virtual std::string toUtf8( std::string* s );

93
private:
94
    const int* leadTable;
95 96 97
    const int (*doubleTable)[2];
};

98
#endif    // DRW_TEXTCODEC_H