summaryrefslogtreecommitdiffstats
path: root/library/cpp/charset/wide.cpp
blob: ae75f45355b0d3a1f5e556fe4ab29178d175081f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
#include "wide.h"

bool CanBeEncoded(TWtringBuf text, ECharset encoding) { 
    const size_t LEN = 16; 
    const size_t BUFSIZE = LEN * 4; 
    char encodeBuf[BUFSIZE]; 
    wchar16 decodeBuf[BUFSIZE]; 
 
    while (!text.empty()) { 
        TWtringBuf src = text.NextTokAt(LEN); 
        TStringBuf encoded = NDetail::NBaseOps::Recode(src, encodeBuf, encoding); 
        TWtringBuf decoded = NDetail::NBaseOps::Recode(encoded, decodeBuf, encoding); 
        if (decoded != src) 
            return false; 
    } 
 
    return true; 
}