2013-10-24 16:44:38 +00:00
|
|
|
#ifndef DRW_TEXTCODEC_H
|
|
|
|
#define DRW_TEXTCODEC_H
|
|
|
|
|
|
|
|
#include <string>
|
|
|
|
|
|
|
|
class DRW_Converter;
|
|
|
|
|
|
|
|
class DRW_TextCodec
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
DRW_TextCodec();
|
|
|
|
~DRW_TextCodec();
|
2013-10-28 08:06:38 +00:00
|
|
|
std::string fromUtf8( std::string s );
|
|
|
|
std::string toUtf8( std::string s );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
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; }
|
2013-10-24 16:44:38 +00:00
|
|
|
private:
|
2013-10-28 08:06:38 +00:00
|
|
|
std::string correctCodePage( const std::string& s );
|
2013-10-24 16:44:38 +00:00
|
|
|
|
|
|
|
private:
|
2013-10-28 08:06:38 +00:00
|
|
|
int version;
|
|
|
|
std::string cp;
|
|
|
|
DRW_Converter* conv;
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
class DRW_Converter
|
|
|
|
{
|
|
|
|
public:
|
2013-10-28 08:06:38 +00:00
|
|
|
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;
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class DRW_ConvTable : public DRW_Converter
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2013-10-28 08:06:38 +00:00
|
|
|
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 );
|
2013-10-24 16:44:38 +00:00
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class DRW_ConvDBCSTable : public DRW_Converter
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2013-10-28 08:06:38 +00:00
|
|
|
DRW_ConvDBCSTable( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
|
|
|
|
l )
|
|
|
|
{
|
|
|
|
leadTable = lt;
|
2013-10-24 16:44:38 +00:00
|
|
|
doubleTable = dt;
|
|
|
|
}
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
virtual std::string fromUtf8( std::string* s );
|
|
|
|
virtual std::string toUtf8( std::string* s );
|
|
|
|
|
2013-10-24 16:44:38 +00:00
|
|
|
private:
|
2013-10-28 08:06:38 +00:00
|
|
|
const int* leadTable;
|
2013-10-24 16:44:38 +00:00
|
|
|
const int (*doubleTable)[2];
|
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
class DRW_Conv932Table : public DRW_Converter
|
|
|
|
{
|
2013-10-24 16:44:38 +00:00
|
|
|
public:
|
2013-10-28 08:06:38 +00:00
|
|
|
DRW_Conv932Table( const int* t, const int* lt, const int dt[][2], int l ) : DRW_Converter( t,
|
|
|
|
l )
|
|
|
|
{
|
|
|
|
leadTable = lt;
|
2013-10-24 16:44:38 +00:00
|
|
|
doubleTable = dt;
|
|
|
|
}
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
virtual std::string fromUtf8( std::string* s );
|
|
|
|
virtual std::string toUtf8( std::string* s );
|
|
|
|
|
2013-10-24 16:44:38 +00:00
|
|
|
private:
|
2013-10-28 08:06:38 +00:00
|
|
|
const int* leadTable;
|
2013-10-24 16:44:38 +00:00
|
|
|
const int (*doubleTable)[2];
|
|
|
|
};
|
|
|
|
|
2013-10-28 08:06:38 +00:00
|
|
|
#endif // DRW_TEXTCODEC_H
|