- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 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
class TCP1251ToUTF16StringConverter
{
public:
static WideChar convert(Char Source)
{
WideChar Result=static_cast<unsigned char>(Source);
const WideChar Russian_YO=static_cast<unsigned char>('Ё');
const WideChar Russian_yo=static_cast<unsigned char>('ё');
const WideChar RussianWide_YO=L'Ё';
const WideChar RussianWide_yo=L'ё';
const WideChar Russian_A=static_cast<unsigned char>('А');
const WideChar RussianWide_A=L'А';
const unsigned int AmountOfSymbols=0x40;
if(Result==Russian_YO)
return RussianWide_YO;
if(Result==Russian_yo)
return RussianWide_yo;
if(Result>=Russian_A&&Result<Russian_A+AmountOfSymbols)
return (Result-Russian_A+RussianWide_A);
return Result;
};
static void convert(PwideChar UTF16StringDestination, PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
assert(CP1251WinEngRusStringSource!=NULL);
size_t i=0;
for(;;)
{
if(i>=TextLength)
break;
assert(i<TextLength);
Char CP1251SourceChar=CP1251WinEngRusStringSource[i];
if(CP1251SourceChar=='\0')
break;
UTF16StringDestination[i]=convert(CP1251SourceChar);
++i;
};
UTF16StringDestination[i]=L'\0';
assert(i<=TextLength);
};
static std::wstring convert(const std::string& CP1251WinEngRusStringSource)
{
assert(CP1251WinEngRusStringSource.c_str()!=NULL);
std::wstring UTF16StringDestination;
std::transform(CP1251WinEngRusStringSource.begin(), CP1251WinEngRusStringSource.end(), std::inserter(UTF16StringDestination, UTF16StringDestination.end())/*std::back_inserter(UTF16StringDestination)*//*VC 6.0 compatible*/, makePointerToFunction(convertChar));
return UTF16StringDestination;
};
private:
static WideChar convertChar(char Source)
{
return convert(Source);
};
};
template<const size_t MaxAmountOfChar>
class TCP1251ToUTF16StringInPlaceConverter
{
public:
TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource)
{
STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
};
TCP1251ToUTF16StringInPlaceConverter(PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
STATIC_ASSERT(MaxAmountOfChar>0, MaxAmountOfChar_must_be_above_zero);
assert(TextLength<=MaxAmountOfChar);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
};
void convert(PChar CP1251WinEngRusStringSource)
{
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, MaxAmountOfChar);
};
void convert(PChar CP1251WinEngRusStringSource, const size_t TextLength)
{
assert(TextLength<=MaxAmountOfChar);
TCP1251ToUTF16StringConverter::convert(&(_buffer[0]), CP1251WinEngRusStringSource, TextLength);
};
PWideChar Get(void) const
{
return &(_buffer[0]);
};
PwideChar Get(void)
{
return &(_buffer[0]);
};
wideChar _buffer[MaxAmountOfChar+1];
};