diff options
author | Ivan Korostelev <ivan.korostelev@gmail.com> | 2022-02-10 16:46:41 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:46:41 +0300 |
commit | f3a52f9d3e18d1159abbc85fa65eeda69d971657 (patch) | |
tree | 203885df8c9af6c414a9ec107514b91912970ab9 /util/string | |
parent | 99609724f661f7e21d1cb08e8d80e87c3632fdb3 (diff) | |
download | ydb-f3a52f9d3e18d1159abbc85fa65eeda69d971657.tar.gz |
Restoring authorship annotation for Ivan Korostelev <ivan.korostelev@gmail.com>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r-- | util/string/cast.cpp | 4 | ||||
-rw-r--r-- | util/string/strip.h | 62 | ||||
-rw-r--r-- | util/string/strip_ut.cpp | 12 | ||||
-rw-r--r-- | util/string/util.h | 2 |
4 files changed, 40 insertions, 40 deletions
diff --git a/util/string/cast.cpp b/util/string/cast.cpp index aa1e65a8e9..eda6fd4ee8 100644 --- a/util/string/cast.cpp +++ b/util/string/cast.cpp @@ -468,8 +468,8 @@ DEF_INT_SPEC_I(wchar32, ui64) // wchar32 is always unsigned return FormatFlt<type>(t, buf, len); \ } -DEF_FLT_SPEC(long double) - +DEF_FLT_SPEC(long double) + #undef DEF_FLT_SPEC template <> diff --git a/util/string/strip.h b/util/string/strip.h index d5ef6da96d..f462e8a17f 100644 --- a/util/string/strip.h +++ b/util/string/strip.h @@ -196,40 +196,40 @@ inline TString Strip(const TString& s) { return ret; } -template <class TChar, class TWhitespaceFunc> -size_t CollapseImpl(TChar* s, size_t n, const TWhitespaceFunc& isWhitespace) { - size_t newLen = 0; - for (size_t i = 0; i < n; ++i, ++newLen) { - size_t nextNonSpace = i; - while (nextNonSpace < n && isWhitespace(s[nextNonSpace])) { - ++nextNonSpace; - } - size_t numSpaces = nextNonSpace - i; - if (numSpaces > 1 || (numSpaces == 1 && s[i] != ' ')) { - s[newLen] = ' '; - i = nextNonSpace - 1; - } else { - s[newLen] = s[i]; - } - } - return newLen; -} - +template <class TChar, class TWhitespaceFunc> +size_t CollapseImpl(TChar* s, size_t n, const TWhitespaceFunc& isWhitespace) { + size_t newLen = 0; + for (size_t i = 0; i < n; ++i, ++newLen) { + size_t nextNonSpace = i; + while (nextNonSpace < n && isWhitespace(s[nextNonSpace])) { + ++nextNonSpace; + } + size_t numSpaces = nextNonSpace - i; + if (numSpaces > 1 || (numSpaces == 1 && s[i] != ' ')) { + s[newLen] = ' '; + i = nextNonSpace - 1; + } else { + s[newLen] = s[i]; + } + } + return newLen; +} + template <class TStringType, class TWhitespaceFunc> bool CollapseImpl(const TStringType& from, TStringType& to, size_t maxLen, const TWhitespaceFunc& isWhitespace) { - to = from; + to = from; maxLen = maxLen ? Min(maxLen, to.size()) : to.size(); - for (size_t i = 0; i < maxLen; ++i) { - if (isWhitespace(to[i]) && (to[i] != ' ' || isWhitespace(to[i + 1]))) { - size_t tailSize = maxLen - i; - size_t newTailSize = CollapseImpl(to.begin() + i, tailSize, isWhitespace); - to.remove(i + newTailSize, tailSize - newTailSize); - return true; - } - } - return false; -} - + for (size_t i = 0; i < maxLen; ++i) { + if (isWhitespace(to[i]) && (to[i] != ' ' || isWhitespace(to[i + 1]))) { + size_t tailSize = maxLen - i; + size_t newTailSize = CollapseImpl(to.begin() + i, tailSize, isWhitespace); + to.remove(i + newTailSize, tailSize - newTailSize); + return true; + } + } + return false; +} + bool Collapse(const TString& from, TString& to, size_t maxLen = 0); /// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes) diff --git a/util/string/strip_ut.cpp b/util/string/strip_ut.cpp index d1029d1498..58f0a9e3df 100644 --- a/util/string/strip_ut.cpp +++ b/util/string/strip_ut.cpp @@ -110,17 +110,17 @@ Y_UNIT_TEST_SUITE(TStripStringTest) { Y_UNIT_TEST(TestCollapse) { TString s; Collapse(TString(" 123 456 "), s); - UNIT_ASSERT(s == " 123 456 "); + UNIT_ASSERT(s == " 123 456 "); Collapse(TString(" 123 456 "), s, 10); - UNIT_ASSERT(s == " 123 456 "); - + UNIT_ASSERT(s == " 123 456 "); + s = TString(" a b c "); TString s2 = s; CollapseInPlace(s2); - - UNIT_ASSERT(s == s2); + + UNIT_ASSERT(s == s2); #ifndef TSTRING_IS_STD_STRING - UNIT_ASSERT(s.c_str() == s2.c_str()); // Collapse() does not change the string at all + UNIT_ASSERT(s.c_str() == s2.c_str()); // Collapse() does not change the string at all #endif } diff --git a/util/string/util.h b/util/string/util.h index 0d77a5042b..b806bbf5c7 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -3,7 +3,7 @@ //THIS FILE A COMPAT STUB HEADER #include <cstring> -#include <cstdarg> +#include <cstdarg> #include <algorithm> #include <util/system/defaults.h> |