aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/libs/libxml/yencoding.cpp
blob: 8092bbfb1c6dc4148aa3e02561b919d4cb64b9d9 (plain) (blame)
1
2
3
4
5
6
7
8
9
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
#include "yencoding.h"

#include <library/cpp/charset/codepage.h>
#include <library/cpp/charset/recyr.hh>


int
win1251ToUTF8(unsigned char* out, int *outlen,
              const unsigned char* in, int *inlen) {
    size_t in_readed, out_writed;
    RECODE_RESULT res = Recode(CODES_WIN, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
    *inlen = (int)in_readed;
    *outlen = (int)out_writed;
    return (res == RECODE_OK)? 0 : -1;
}

int
UTF8Towin1251(unsigned char* out, int *outlen,
              const unsigned char* in, int *inlen) {
    size_t in_readed, out_writed;
    RECODE_RESULT res = Recode(CODES_UTF8, CODES_WIN, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
    *inlen = (int)in_readed;
    *outlen = (int)out_writed;
    return (res == RECODE_OK)? 0 : -1;
}


int
koi8ToUTF8(unsigned char* out, int *outlen,
              const unsigned char* in, int *inlen) {
    size_t in_readed, out_writed;
    RECODE_RESULT res = Recode(CODES_KOI8, CODES_UTF8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
    *inlen = (int)in_readed;
    *outlen = (int)out_writed;
    return (res == RECODE_OK)? 0 : -1;
}

int
UTF8Tokoi8(unsigned char* out, int *outlen,
              const unsigned char* in, int *inlen) {
    size_t in_readed, out_writed;
    RECODE_RESULT res = Recode(CODES_UTF8, CODES_KOI8, (const char*)in, (char*)out, (size_t)*inlen, (size_t)*outlen, in_readed, out_writed);
    *inlen = (int)in_readed;
    *outlen = (int)out_writed;
    return (res == RECODE_OK)? 0 : -1;
}