aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authorIvan Korostelev <ivan.korostelev@gmail.com>2022-02-10 16:46:41 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:46:41 +0300
commitb5e813096385b2d9e16b572711fec5bf2eb5058d (patch)
tree49e222ea1c5804306084bb3ae065bb702625360f /util/string
parentf3a52f9d3e18d1159abbc85fa65eeda69d971657 (diff)
downloadydb-b5e813096385b2d9e16b572711fec5bf2eb5058d.tar.gz
Restoring authorship annotation for Ivan Korostelev <ivan.korostelev@gmail.com>. Commit 2 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/cast.cpp4
-rw-r--r--util/string/strip.h62
-rw-r--r--util/string/strip_ut.cpp12
-rw-r--r--util/string/util.h2
4 files changed, 40 insertions, 40 deletions
diff --git a/util/string/cast.cpp b/util/string/cast.cpp
index eda6fd4ee8..aa1e65a8e9 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 f462e8a17f..d5ef6da96d 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 58f0a9e3df..d1029d1498 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 b806bbf5c7..0d77a5042b 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>