| 47 | } |
| 48 | |
| 49 | inline RECODE_RESULT _recodeFromUTF8(ECharset to, const char* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { |
| 50 | if (to == CODES_UTF8) |
| 51 | return _recodeCopy(in, out, in_size, out_size, in_readed, out_writed); |
| 52 | Y_ASSERT(CODES_UNKNOWN < to && to < CODES_MAX); |
| 53 | const Encoder* enc = &EncoderByCharset(to); |
| 54 | |
| 55 | const unsigned char* in_start = (const unsigned char*)in; |
| 56 | const unsigned char* in_end = in_start + in_size; |
| 57 | const unsigned char* out_start = (unsigned char*)out; |
| 58 | const unsigned char* out_end = out_start + out_size; |
| 59 | |
| 60 | wchar32 rune; |
| 61 | size_t rune_len; |
| 62 | RECODE_RESULT res = RECODE_OK; |
| 63 | while ((const unsigned char*)in < in_end && (res == RECODE_OK || res == RECODE_BROKENSYMBOL)) { |
| 64 | res = SafeReadUTF8Char(rune, rune_len, (const unsigned char*)in, in_end); |
| 65 | if (res == RECODE_BROKENSYMBOL) |
| 66 | rune_len = 1; |
| 67 | if (res != RECODE_EOINPUT) |
| 68 | *out++ = enc->Tr(rune); |
| 69 | in += rune_len; |
| 70 | if (res == RECODE_OK && (const unsigned char*)in < in_end && (unsigned char*)out >= out_end) |
| 71 | res = RECODE_EOOUTPUT; |
| 72 | } |
| 73 | in_readed = (unsigned char*)in - in_start; |
| 74 | out_writed = (unsigned char*)out - out_start; |
| 75 | return res; |
| 76 | } |
| 77 | |
| 78 | inline RECODE_RESULT _recodeToYandex(ECharset From, const char* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { |
| 79 | if (From == CODES_YANDEX) |
no test coverage detected