diff options
author | sereglond <sereglond@yandex-team.ru> | 2022-02-10 16:47:47 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:47:47 +0300 |
commit | 73bb02f2495181e0719a800f979df508924f4b71 (patch) | |
tree | c0748b5dcbade83af788c0abfa89c0383d6b779c /library/cpp/charset/recyr_int.hh | |
parent | eb3d925534734c808602b31b38b953677f0a279f (diff) | |
download | ydb-73bb02f2495181e0719a800f979df508924f4b71.tar.gz |
Restoring authorship annotation for <sereglond@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/charset/recyr_int.hh')
-rw-r--r-- | library/cpp/charset/recyr_int.hh | 62 |
1 files changed, 31 insertions, 31 deletions
diff --git a/library/cpp/charset/recyr_int.hh b/library/cpp/charset/recyr_int.hh index ddd3fa26ad..353af53305 100644 --- a/library/cpp/charset/recyr_int.hh +++ b/library/cpp/charset/recyr_int.hh @@ -2,16 +2,16 @@ #include <util/charset/recode_result.h> #include <util/charset/utf8.h> -#include <util/generic/ptr.h> +#include <util/generic/ptr.h> #include <util/generic/string.h> #include <util/system/defaults.h> -#include "codepage.h" +#include "codepage.h" #include "doccodes.h" -#include "iconv.h" -#include "wide.h" +#include "iconv.h" +#include "wide.h" -namespace NCodepagePrivate { +namespace NCodepagePrivate { inline RECODE_RESULT _recodeCopy(const char* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { in_readed = in_size; RECODE_RESULT res = RECODE_OK; @@ -120,14 +120,14 @@ namespace NCodepagePrivate { break; } inp += rune_len; - } + } } in_readed = inp - (const unsigned char*)in; out_writed = outp - out; - + if ((res == RECODE_OK || res == RECODE_BROKENSYMBOL) && in_readed != in_size) return RECODE_EOOUTPUT; - + return res; } @@ -156,7 +156,7 @@ namespace NCodepagePrivate { size_t rune_len; wchar32 rune; RECODE_RESULT res = RECODE_OK; - + while ((res == RECODE_OK || res == RECODE_BROKENSYMBOL) && inp != in_end) { rune = ReadSymbolAndAdvance(inp, in_end); res = SafeWriteUTF8Char(rune, rune_len, outp, out_end); @@ -175,44 +175,44 @@ namespace NCodepagePrivate { template <class TCharType, int Size = sizeof(TCharType)> struct TCharTypeSwitch; - + template <class TCharType> struct TCharTypeSwitch<TCharType, 2> { using TRealCharType = wchar16; }; - + template <class TCharType> struct TCharTypeSwitch<TCharType, 4> { using TRealCharType = wchar32; }; - + template <class TCharType> inline RECODE_RESULT _recodeUnicodeToUTF8(const TCharType* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { static_assert(sizeof(TCharType) > 1, "expect some wide type"); using TRealCharType = typename TCharTypeSwitch<TCharType>::TRealCharType; - + return _recodeUnicodeToUTF8Impl(reinterpret_cast<const TRealCharType*>(in), out, in_size, out_size, in_readed, out_writed); } - + template <class TCharType> inline RECODE_RESULT _recodeUnicodeToSB(ECharset To, const TCharType* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { const TCharType* inp = in; const TCharType* in_end = in + in_size; const char* out_begin = out; const char* out_end = out + out_size; - + const Encoder* enc = &EncoderByCharset(To); while (inp != in_end && out != out_end) { *out++ = enc->Tr(ReadSymbolAndAdvance(inp, in_end)); } - + in_readed = inp - in; out_writed = out - out_begin; - + if (in_readed != in_size) return RECODE_EOOUTPUT; - + return RECODE_OK; } @@ -279,27 +279,27 @@ namespace NCodepagePrivate { inline RECODE_RESULT _recodeToUnicode(ECharset From, const char* in, TCharType* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { if (!ValidCodepage(From)) return RECODE_ERROR; - + if (!NCodepagePrivate::NativeCodepage(From)) return NICONVPrivate::RecodeToUnicodeNoThrow(From, in, out, in_size, out_size, in_readed, out_writed); - + if (From == CODES_UTF8) return _recodeUTF8ToUnicode(in, out, in_size, out_size, in_readed, out_writed); - + return _recodeSBToUnicode(From, in, out, in_size, out_size, in_readed, out_writed); } - + template <class TCharType> inline RECODE_RESULT _recodeFromUnicode(ECharset To, const TCharType* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { if (!ValidCodepage(To)) return RECODE_ERROR; - + if (!NCodepagePrivate::NativeCodepage(To)) return NICONVPrivate::RecodeFromUnicodeNoThrow(To, in, out, in_size, out_size, in_readed, out_writed); - + if (To == CODES_UTF8) return NCodepagePrivate::_recodeUnicodeToUTF8(in, out, in_size, out_size, in_readed, out_writed); - + return NCodepagePrivate::_recodeUnicodeToSB(To, in, out, in_size, out_size, in_readed, out_writed); } @@ -314,23 +314,23 @@ namespace NCodepagePrivate { if (To == CODES_UTF8) return NCodepagePrivate::_recodeUnicodeToUTF8(rune, out, out_size, nwritten); - + return NCodepagePrivate::_recodeUnicodeToSB(To, rune, out, out_size, nwritten); } - + inline RECODE_RESULT _recodeToHTMLEntities(ECharset From, const char* in, char* out, size_t in_size, size_t out_size, size_t& in_readed, size_t& out_writed) { TArrayHolder<wchar32> bufHolder(new wchar32[in_size]); wchar32* buf = bufHolder.Get(); size_t unicode_size; RECODE_RESULT res1, res2; - + //first pass - to unicode res1 = _recodeToUnicode(From, in, buf, in_size, in_size, in_readed, unicode_size); - + //second pass - to entities res2 = _recodeUnicodeToHTMLEntities(buf, out, in_size, out_size, in_readed, out_writed); - + return (res2 != RECODE_OK) ? res2 : res1; } - + } |