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/yson_pull/detail/cescape.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/yson_pull/detail/cescape.h')
-rw-r--r-- | library/cpp/yson_pull/detail/cescape.h | 172 |
1 files changed, 86 insertions, 86 deletions
diff --git a/library/cpp/yson_pull/detail/cescape.h b/library/cpp/yson_pull/detail/cescape.h index d12936e63c..1ea150e69a 100644 --- a/library/cpp/yson_pull/detail/cescape.h +++ b/library/cpp/yson_pull/detail/cescape.h @@ -35,109 +35,109 @@ * */ -namespace NYsonPull { - namespace NDetail { - namespace NCEscape { +namespace NYsonPull { + namespace NDetail { + namespace NCEscape { inline void encode(TString& dest, TStringBuf data) { - NImpl::escape_impl( - reinterpret_cast<const ui8*>(data.data()), - data.size(), - [&](const ui8* str, size_t size) { - dest.append( - reinterpret_cast<const char*>(str), - size); - }); - } + NImpl::escape_impl( + reinterpret_cast<const ui8*>(data.data()), + data.size(), + [&](const ui8* str, size_t size) { + dest.append( + reinterpret_cast<const char*>(str), + size); + }); + } - // dest must have at least 4*data.size() bytes available - inline size_t encode(ui8* dest, TStringBuf data) { - auto* dest_begin = dest; - NImpl::escape_impl( - reinterpret_cast<const ui8*>(data.data()), - data.size(), - [&](const ui8* str, size_t size) { - ::memcpy(dest, str, size); - dest += size; - }); - return dest - dest_begin; - } + // dest must have at least 4*data.size() bytes available + inline size_t encode(ui8* dest, TStringBuf data) { + auto* dest_begin = dest; + NImpl::escape_impl( + reinterpret_cast<const ui8*>(data.data()), + data.size(), + [&](const ui8* str, size_t size) { + ::memcpy(dest, str, size); + dest += size; + }); + return dest - dest_begin; + } - template <typename U> - void encode(byte_writer<U>& dest, TStringBuf data) { - auto& buffer = dest.stream().buffer(); + template <typename U> + void encode(byte_writer<U>& dest, TStringBuf data) { + auto& buffer = dest.stream().buffer(); if (Y_LIKELY(buffer.available() >= data.size() * 4)) { - auto size = encode(buffer.pos(), data); - dest.advance(size); - } else { - NImpl::escape_impl( - reinterpret_cast<const ui8*>(data.data()), - data.size(), - [&](const ui8* str, size_t size) { - dest.write(str, size); - }); - } - } + auto size = encode(buffer.pos(), data); + dest.advance(size); + } else { + NImpl::escape_impl( + reinterpret_cast<const ui8*>(data.data()), + data.size(), + [&](const ui8* str, size_t size) { + dest.write(str, size); + }); + } + } inline TString encode(TStringBuf data) { TString result; - result.reserve(data.size()); - encode(result, data); - return result; + result.reserve(data.size()); + encode(result, data); + return result; } inline void decode(TString& dest, TStringBuf data) { - NImpl::unescape_impl( - reinterpret_cast<const ui8*>(data.begin()), - reinterpret_cast<const ui8*>(data.end()), - [&](ui8 c) { - dest += c; - }, - [&](const ui8* p, size_t len) { - dest.append(reinterpret_cast<const char*>(p), len); - }); - } + NImpl::unescape_impl( + reinterpret_cast<const ui8*>(data.begin()), + reinterpret_cast<const ui8*>(data.end()), + [&](ui8 c) { + dest += c; + }, + [&](const ui8* p, size_t len) { + dest.append(reinterpret_cast<const char*>(p), len); + }); + } inline void decode_inplace(TVector<ui8>& data) { - auto* out = static_cast<ui8*>( - ::memchr(data.data(), '\\', data.size())); - if (out == nullptr) { - return; - } - NImpl::unescape_impl( - out, - data.data() + data.size(), - [&](ui8 c) { - *out++ = c; - }, - [&](const ui8* p, size_t len) { - ::memmove(out, p, len); - out += len; - }); - data.resize(out - &data[0]); - } + auto* out = static_cast<ui8*>( + ::memchr(data.data(), '\\', data.size())); + if (out == nullptr) { + return; + } + NImpl::unescape_impl( + out, + data.data() + data.size(), + [&](ui8 c) { + *out++ = c; + }, + [&](const ui8* p, size_t len) { + ::memmove(out, p, len); + out += len; + }); + data.resize(out - &data[0]); + } inline TString decode(TStringBuf data) { TString result; - result.reserve(data.size()); - decode(result, data); - return result; - } + result.reserve(data.size()); + decode(result, data); + return result; + } - ATTRIBUTE(noinline, cold) + ATTRIBUTE(noinline, cold) inline TString quote(TStringBuf str) { TString result; - result.reserve(str.size() + 16); - result += '"'; - encode(result, str); - result += '"'; - return result; - } + result.reserve(str.size() + 16); + result += '"'; + encode(result, str); + result += '"'; + return result; + } - ATTRIBUTE(noinline, cold) + ATTRIBUTE(noinline, cold) inline TString quote(ui8 ch) { - char c = ch; - return quote(TStringBuf(&c, 1)); - } - } - } // namespace NDetail -} + char c = ch; + return quote(TStringBuf(&c, 1)); + } + } + } // namespace NDetail +} |