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; }
|
2015-02-24 09:07:40 +00:00
|
|
|
void setVersion( std::string* v );
|
2013-10-28 08:06:38 +00:00
|
|
|
|
|
|
|
void setVersion( int v ) { version = v; }
|
2015-02-24 09:07:40 +00:00
|
|
|
void setCodePage( std::string* c );
|
2013-10-28 08:06:38 +00:00
|
|
|
|
|
|
|
void setCodePage( std::string c ) { setCodePage( &c ); }
|
|
|
|
std::string getCodePage() { return cp; }
|
2015-02-24 09:07:40 +00:00
|
|
|
|
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:
|
2015-02-24 09:07:40 +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 );
|
2017-09-23 09:20:10 +00:00
|
|
|
std::string encodeText( const std::string& stmp );
|
2013-10-28 08:06:38 +00:00
|
|
|
std::string decodeText( int c );
|
|
|
|
std::string encodeNum( int c );
|
|
|
|
int decodeNum( std::string s, int* b );
|
|
|
|
|
2015-02-24 09:07:40 +00:00
|
|
|
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 ) {}
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual std::string fromUtf8( std::string* s ) override;
|
|
|
|
virtual std::string toUtf8( std::string* s ) override;
|
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,
|
2015-02-24 09:07:40 +00:00
|
|
|
l )
|
2013-10-28 08:06:38 +00:00
|
|
|
{
|
2015-02-24 09:07:40 +00:00
|
|
|
leadTable = lt;
|
2013-10-24 16:44:38 +00:00
|
|
|
doubleTable = dt;
|
|
|
|
}
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual std::string fromUtf8( std::string* s ) override;
|
|
|
|
virtual std::string toUtf8( std::string* s ) override;
|
2013-10-28 08:06:38 +00:00
|
|
|
|
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,
|
2015-02-24 09:07:40 +00:00
|
|
|
l )
|
2013-10-28 08:06:38 +00:00
|
|
|
{
|
2015-02-24 09:07:40 +00:00
|
|
|
leadTable = lt;
|
2013-10-24 16:44:38 +00:00
|
|
|
doubleTable = dt;
|
|
|
|
}
|
|
|
|
|
2016-09-24 18:53:15 +00:00
|
|
|
virtual std::string fromUtf8( std::string* s ) override;
|
|
|
|
virtual std::string toUtf8( std::string* s ) override;
|
2013-10-28 08:06:38 +00:00
|
|
|
|
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
|