diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:17 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:17 +0300 |
commit | d3a398281c6fd1d3672036cb2d63f842d2cb28c5 (patch) | |
tree | dd4bd3ca0f36b817e96812825ffaf10d645803f2 /library/cpp/charset/codepage.h | |
parent | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (diff) | |
download | ydb-d3a398281c6fd1d3672036cb2d63f842d2cb28c5.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/charset/codepage.h')
-rw-r--r-- | library/cpp/charset/codepage.h | 90 |
1 files changed, 45 insertions, 45 deletions
diff --git a/library/cpp/charset/codepage.h b/library/cpp/charset/codepage.h index 2911174dce..30a02a4610 100644 --- a/library/cpp/charset/codepage.h +++ b/library/cpp/charset/codepage.h @@ -1,6 +1,6 @@ #pragma once -#include "doccodes.h" +#include "doccodes.h" #include <util/charset/recode_result.h> #include <util/charset/unidata.h> // all wchar32 functions @@ -8,11 +8,11 @@ #include <util/generic/string.h> #include <util/generic/ylimits.h> #include <util/generic/yexception.h> -#include <util/system/yassert.h> -#include <util/system/defaults.h> - -#include <cctype> - +#include <util/system/yassert.h> +#include <util/system/defaults.h> + +#include <cctype> + struct CodePage; struct Recoder; struct Encoder; @@ -21,10 +21,10 @@ struct Encoder; * struct CodePage * \*****************************************************************/ struct CodePage { - ECharset CPEnum; // int MIBEnum; - const char* Names[30]; // name[0] -- preferred mime-name - wchar32 unicode[256]; - const char* DefaultChar; //[CCL_NUM] + ECharset CPEnum; // int MIBEnum; + const char* Names[30]; // name[0] -- preferred mime-name + wchar32 unicode[256]; + const char* DefaultChar; //[CCL_NUM] bool IsLower(unsigned char ch) const { return ::IsLower(unicode[ch]); @@ -38,7 +38,7 @@ struct CodePage { bool IsDigit(unsigned char ch) const { return ::IsDigit(unicode[ch]); } - bool IsXdigit(unsigned char ch) const { + bool IsXdigit(unsigned char ch) const { return ::IsXdigit(unicode[ch]); } bool IsAlnum(unsigned char ch) const { @@ -62,18 +62,18 @@ struct CodePage { bool IsComposed(unsigned char ch) const { return ::IsComposed(unicode[ch]); } - + // return pointer to char after the last char - char* ToLower(const char* begin, const char* end, char* to) const; + char* ToLower(const char* begin, const char* end, char* to) const; char* ToLower(const char* begin, char* to) const; - // return pointer to char after the last char - char* ToUpper(const char* begin, const char* end, char* to) const; + // return pointer to char after the last char + char* ToUpper(const char* begin, const char* end, char* to) const; char* ToUpper(const char* begin, char* to) const; - - int stricmp(const char* s1, const char* s2) const; - int strnicmp(const char* s1, const char* s2, size_t len) const; - + + int stricmp(const char* s1, const char* s2) const; + int strnicmp(const char* s1, const char* s2, size_t len) const; + inline unsigned char ToUpper(unsigned char ch) const; inline unsigned char ToLower(unsigned char ch) const; inline unsigned char ToTitle(unsigned char ch) const; @@ -131,18 +131,18 @@ namespace NCodepagePrivate { return GetPrivate(e)->Names[0]; } - static const TCodepagesMap& Instance(); - + static const TCodepagesMap& Instance(); + friend class ::TCodePageHash; }; inline bool NativeCodepage(ECharset e) { - return ::NCodepagePrivate::TCodepagesMap::Instance().NativeCodepage(e); + return ::NCodepagePrivate::TCodepagesMap::Instance().NativeCodepage(e); } } inline bool SingleByteCodepage(ECharset e) { - return ::NCodepagePrivate::TCodepagesMap::Instance().SingleByteCodepage(e); + return ::NCodepagePrivate::TCodepagesMap::Instance().SingleByteCodepage(e); } inline bool ValidCodepage(ECharset e) { @@ -150,7 +150,7 @@ inline bool ValidCodepage(ECharset e) { } inline const CodePage* CodePageByCharset(ECharset e) { - return ::NCodepagePrivate::TCodepagesMap::Instance().Get(e); + return ::NCodepagePrivate::TCodepagesMap::Instance().Get(e); } ECharset CharsetByName(TStringBuf name); @@ -163,12 +163,12 @@ inline ECharset CharsetByCodePage(const CodePage* CP) { } inline const char* NameByCharset(ECharset e) { - return ::NCodepagePrivate::TCodepagesMap::Instance().NameByCharset(e); + return ::NCodepagePrivate::TCodepagesMap::Instance().NameByCharset(e); } inline const char* NameByCharsetSafe(ECharset e) { if (CODES_UNKNOWN < e && e < CODES_MAX) - return ::NCodepagePrivate::TCodepagesMap::Instance().NameByCharset(e); + return ::NCodepagePrivate::TCodepagesMap::Instance().NameByCharset(e); else ythrow yexception() << "unknown encoding: " << (int)e; } @@ -194,21 +194,21 @@ struct Encoder { char* Table[256]; const char* DefaultChar; - inline char Code(wchar32 ch) const { + inline char Code(wchar32 ch) const { if (ch > 0xFFFF) return 0; - return (unsigned char)Table[(ch >> 8) & 255][ch & 255]; + return (unsigned char)Table[(ch >> 8) & 255][ch & 255]; } - inline char Tr(wchar32 ch) const { + inline char Tr(wchar32 ch) const { char code = Code(ch); if (code == 0 && ch != 0) - code = DefaultChar[NUnicode::CharType(ch)]; + code = DefaultChar[NUnicode::CharType(ch)]; Y_ASSERT(code != 0 || ch == 0); return code; } - inline unsigned char operator[](wchar32 ch) const { + inline unsigned char operator[](wchar32 ch) const { return Tr(ch); } @@ -223,25 +223,25 @@ struct Encoder { struct Recoder { unsigned char Table[257]; - void Create(const CodePage& source, const CodePage& target); - void Create(const CodePage& source, const Encoder* wideTarget); + void Create(const CodePage& source, const CodePage& target); + void Create(const CodePage& source, const Encoder* wideTarget); - void Create(const CodePage& page, wchar32 (*mapper)(wchar32)); - void Create(const CodePage& page, const Encoder* widePage, wchar32 (*mapper)(wchar32)); + void Create(const CodePage& page, wchar32 (*mapper)(wchar32)); + void Create(const CodePage& page, const Encoder* widePage, wchar32 (*mapper)(wchar32)); - inline unsigned char Tr(unsigned char c) const { + inline unsigned char Tr(unsigned char c) const { return Table[c]; } - inline unsigned char operator[](unsigned char c) const { + inline unsigned char operator[](unsigned char c) const { return Table[c]; } - void Tr(const char* in, char* out, size_t len) const; - void Tr(const char* in, char* out) const; - void Tr(char* in_out, size_t len) const; - void Tr(char* in_out) const; + void Tr(const char* in, char* out, size_t len) const; + void Tr(const char* in, char* out) const; + void Tr(char* in_out, size_t len) const; + void Tr(char* in_out) const; }; -extern const struct Encoder& WideCharToYandex; +extern const struct Encoder& WideCharToYandex; const Encoder& EncoderByCharset(ECharset enc); @@ -255,7 +255,7 @@ namespace NCodepagePrivate { static const Recoder rcdr_to_lower[]; static const Recoder rcdr_to_upper[]; static const Recoder rcdr_to_title[]; - + static const Encoder* const EncodeTo[]; friend struct ::CodePage; @@ -264,7 +264,7 @@ namespace NCodepagePrivate { friend RECODE_RESULT _recodeFromYandex(ECharset, const char*, char*, size_t, size_t, size_t&, size_t&); friend const Encoder& ::EncoderByCharset(ECharset enc); }; -} +} inline const Encoder& EncoderByCharset(ECharset enc) { if (!SingleByteCodepage(enc)) { @@ -319,6 +319,6 @@ inline TString ToTitle(TString s, const CodePage& cp, size_t pos = 0, size_t n = return i == pos ? cp.ToTitle(c) : cp.ToLower(c); }, pos, - n); + n); return s; } |