diff options
| author | babenko <[email protected]> | 2025-12-24 23:29:35 +0300 |
|---|---|---|
| committer | babenko <[email protected]> | 2025-12-24 23:45:58 +0300 |
| commit | 4dbf62fd2f8cc5ece53cc1446561cf71476bdd12 (patch) | |
| tree | 9aab73c043bf8f6dc177b06f69dab4336dadfcba /library/cpp/containers/cow_string/output.cpp | |
| parent | dba8986f6b1a5fc7c4f230bee510113995a48970 (diff) | |
Explicitly use TCowString in TYsonString
Для ревьюеров: изменения вне `library/cpp/yt` убирают `using namespace NYT` из хедера. Эта конструкция приводила к клешу имен глобального неймспейса и `NYT` и ошибкам сборки.
commit_hash:f598da488a6dd8671af9f1f02870ab5612ae46eb
Diffstat (limited to 'library/cpp/containers/cow_string/output.cpp')
| -rw-r--r-- | library/cpp/containers/cow_string/output.cpp | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/library/cpp/containers/cow_string/output.cpp b/library/cpp/containers/cow_string/output.cpp new file mode 100644 index 00000000000..e0b4924ad31 --- /dev/null +++ b/library/cpp/containers/cow_string/output.cpp @@ -0,0 +1,46 @@ +#include "cow_string.h" + +#include <util/charset/wide.h> +#include <util/stream/input.h> +#include <util/string/cast.h> + +constexpr size_t MAX_UTF8_BYTES = 4; // UTF-8-encoded code point takes between 1 and 4 bytes + +template <typename TCharType> +static void WriteString(IOutputStream& o, const TCharType* w, size_t n) { + const size_t buflen = (n * MAX_UTF8_BYTES); // * 4 because the conversion functions can convert unicode character into maximum 4 bytes of UTF8 + TTempBuf buffer(buflen + 1); + size_t written = 0; + WideToUTF8(w, n, buffer.Data(), written); + o.Write(buffer.Data(), written); +} + +template <> +void Out<TCowString>(IOutputStream& o, const TCowString& p) { + o.Write(p.data(), p.size()); +} + +template <> +void Out<TUtf16CowString>(IOutputStream& o, const TUtf16CowString& w) { + WriteString(o, w.c_str(), w.size()); +} + +template <> +void Out<TUtf32CowString>(IOutputStream& o, const TUtf32CowString& w) { + WriteString(o, w.c_str(), w.size()); +} + +template <> +void Out<TBasicCharRef<TCowString>>(IOutputStream& o, const TBasicCharRef<TCowString>& c) { + o << static_cast<char>(c); +} + +template <> +void Out<TBasicCharRef<TUtf16CowString>>(IOutputStream& o, const TBasicCharRef<TUtf16CowString>& c) { + o << static_cast<wchar16>(c); +} + +template <> +void Out<TBasicCharRef<TUtf32CowString>>(IOutputStream& o, const TBasicCharRef<TUtf32CowString>& c) { + o << static_cast<wchar32>(c); +} |
