diff options
author | Devtools Arcadia <arcadia-devtools@yandex-team.ru> | 2022-02-07 18:08:42 +0300 |
---|---|---|
committer | Devtools Arcadia <arcadia-devtools@mous.vla.yp-c.yandex.net> | 2022-02-07 18:08:42 +0300 |
commit | 1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch) | |
tree | e26c9fed0de5d9873cce7e00bc214573dc2195b7 /library/cpp/charset/ci_string.cpp | |
download | ydb-1110808a9d39d4b808aef724c861a2e1a38d2a69.tar.gz |
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'library/cpp/charset/ci_string.cpp')
-rw-r--r-- | library/cpp/charset/ci_string.cpp | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/library/cpp/charset/ci_string.cpp b/library/cpp/charset/ci_string.cpp new file mode 100644 index 0000000000..634b05ec68 --- /dev/null +++ b/library/cpp/charset/ci_string.cpp @@ -0,0 +1,42 @@ +#include "ci_string.h" +#include "wide.h" + +int TCiString::compare(const TCiString& s1, const TCiString& s2, const CodePage& cp) { + return cp.stricmp(s1.data(), s2.data()); +} + +int TCiString::compare(const char* p, const TCiString& s2, const CodePage& cp) { + return cp.stricmp(p, s2.data()); +} + +int TCiString::compare(const TCiString& s1, const char* p, const CodePage& cp) { + return cp.stricmp(s1.data(), p); +} + +int TCiString::compare(const TStringBuf& p1, const TStringBuf& p2, const CodePage& cp) { + int rv = cp.strnicmp(p1.data(), p2.data(), Min(p1.size(), p2.size())); + return rv ? rv : p1.size() < p2.size() ? -1 : p1.size() == p2.size() ? 0 : 1; +} + +bool TCiString::is_prefix(const TStringBuf& what, const TStringBuf& of, const CodePage& cp) { + size_t len = what.size(); + return len <= of.size() && cp.strnicmp(what.data(), of.data(), len) == 0; +} + +bool TCiString::is_suffix(const TStringBuf& what, const TStringBuf& of, const CodePage& cp) { + size_t len = what.size(); + size_t slen = of.size(); + return (len <= slen) && (0 == cp.strnicmp(what.data(), of.data() + slen - len, len)); +} + +size_t TCiString::hashVal(const char* s, size_t len, const CodePage& cp) { + size_t h = len; + for (; /* (*s) && */ len--; ++s) + h = 5 * h + cp.ToLower(*s); + return h; +} + +template <> +void Out<TCiString>(IOutputStream& o, const TCiString& p) { + o.Write(p.data(), p.size()); +} |