aboutsummaryrefslogtreecommitdiffstats
path: root/util/string
diff options
context:
space:
mode:
authormelkov <melkov@yandex-team.ru>2022-02-10 16:48:13 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:48:13 +0300
commit438546c8737d5c1fdeb31157dcf999717d930eec (patch)
treed29d229abd2f9f889b9b7eb148d635059dc26acf /util/string
parent96647fad5355ff5ef45a00a6d85c097028584ab0 (diff)
downloadydb-438546c8737d5c1fdeb31157dcf999717d930eec.tar.gz
Restoring authorship annotation for <melkov@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'util/string')
-rw-r--r--util/string/escape.h8
-rw-r--r--util/string/split.cpp6
-rw-r--r--util/string/split.h16
-rw-r--r--util/string/split_ut.cpp4
-rw-r--r--util/string/util.cpp42
-rw-r--r--util/string/util.h88
-rw-r--r--util/string/util_ut.cpp6
7 files changed, 85 insertions, 85 deletions
diff --git a/util/string/escape.h b/util/string/escape.h
index b01be65b0e..ac52685f31 100644
--- a/util/string/escape.h
+++ b/util/string/escape.h
@@ -1,7 +1,7 @@
#pragma once
#include <util/generic/string.h>
-#include <util/generic/strbuf.h>
+#include <util/generic/strbuf.h>
template <class TChar>
TBasicString<TChar>& EscapeCImpl(const TChar* str, size_t len, TBasicString<TChar>&);
@@ -26,9 +26,9 @@ static inline TBasicString<TChar> EscapeC(const TChar* str, size_t len) {
template <typename TChar>
static inline TBasicString<TChar> EscapeC(const TBasicStringBuf<TChar>& str) {
return EscapeC(str.data(), str.size());
-}
-
-template <typename TChar>
+}
+
+template <typename TChar>
static inline TBasicString<TChar>& UnescapeC(const TChar* str, size_t len, TBasicString<TChar>& s) {
return UnescapeCImpl(str, len, s);
}
diff --git a/util/string/split.cpp b/util/string/split.cpp
index 7d26857cc7..e3fc1444f5 100644
--- a/util/string/split.cpp
+++ b/util/string/split.cpp
@@ -8,7 +8,7 @@ inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values)
if (ptr && *ptr) {
size_t epos = strcspn(ptr, delim);
assert(epos);
- values.push_back(TValue(ptr, epos));
+ values.push_back(TValue(ptr, epos));
ptr += epos;
}
}
@@ -17,8 +17,8 @@ inline size_t Split(const char* ptr, const char* delim, TVector<TValue>& values)
size_t Split(const char* ptr, const char* delim, TVector<TString>& values) {
return Split<TString>(ptr, delim, values);
-}
-
+}
+
size_t Split(const TString& in, const TString& delim, TVector<TString>& res) {
return Split(in.data(), delim.data(), res);
}
diff --git a/util/string/split.h b/util/string/split.h
index bc46d9e64c..50aa32210e 100644
--- a/util/string/split.h
+++ b/util/string/split.h
@@ -408,21 +408,21 @@ static inline void Split(char* buf, char ch, T* res) {
}
/// Split string into res vector. Res vector is cleared before split.
-/// Old good slow split function.
-/// Field delimter is any number of symbols specified in delim (no empty strings in res vector)
+/// Old good slow split function.
+/// Field delimter is any number of symbols specified in delim (no empty strings in res vector)
/// @return number of elements created
size_t Split(const char* in, const char* delim, TVector<TString>& res);
size_t Split(const TString& in, const TString& delim, TVector<TString>& res);
-
-/// Old split reimplemented for TStringBuf using the new code
-/// Note that delim can be constructed from char* automatically (it is not cheap though)
+
+/// Old split reimplemented for TStringBuf using the new code
+/// Note that delim can be constructed from char* automatically (it is not cheap though)
inline size_t Split(const TStringBuf s, const TSetDelimiter<const char>& delim, TVector<TStringBuf>& res) {
- res.clear();
+ res.clear();
TContainerConsumer<TVector<TStringBuf>> res1(&res);
TSkipEmptyTokens<TContainerConsumer<TVector<TStringBuf>>> consumer(&res1);
SplitString(s.data(), s.data() + s.size(), delim, consumer);
- return res.size();
-}
+ return res.size();
+}
template <class P, class D>
void GetNext(TStringBuf& s, D delim, P& param) {
diff --git a/util/string/split_ut.cpp b/util/string/split_ut.cpp
index 43e59f2d75..54c9b4c833 100644
--- a/util/string/split_ut.cpp
+++ b/util/string/split_ut.cpp
@@ -245,10 +245,10 @@ Y_UNIT_TEST_SUITE(SplitStringTest) {
TVector<TString> test;
Split(data, delim, test);
Cmp(good, test);
-
+
TVector<TStringBuf> test1;
Split(data, delim.data(), test1);
- Cmp(good, test1);
+ Cmp(good, test1);
}
Y_UNIT_TEST(ConvenientSplitTest) {
diff --git a/util/string/util.cpp b/util/string/util.cpp
index b14f20bf75..41dd7db624 100644
--- a/util/string/util.cpp
+++ b/util/string/util.cpp
@@ -10,44 +10,44 @@ int a2i(const TString& s) {
return atoi(s.c_str());
}
-//============================== span =====================================
-
+//============================== span =====================================
+
void str_spn::init(const char* charset, bool extended) {
// chars_table_1 is necessary to avoid some unexpected
// multi-threading issues
- ui8 chars_table_1[256];
- memset(chars_table_1, 0, sizeof(chars_table_1));
- if (extended) {
+ ui8 chars_table_1[256];
+ memset(chars_table_1, 0, sizeof(chars_table_1));
+ if (extended) {
for (const char* cs = charset; *cs; cs++) {
- if (cs[1] == '-' && cs[2] != 0) {
+ if (cs[1] == '-' && cs[2] != 0) {
for (int c = (ui8)*cs; c <= (ui8)cs[2]; c++) {
- chars_table_1[c] = 1;
+ chars_table_1[c] = 1;
}
- cs += 2;
- continue;
- }
- chars_table_1[(ui8)*cs] = 1;
- }
- } else {
+ cs += 2;
+ continue;
+ }
+ chars_table_1[(ui8)*cs] = 1;
+ }
+ } else {
for (; *charset; charset++) {
- chars_table_1[(ui8)*charset] = 1;
+ chars_table_1[(ui8)*charset] = 1;
}
- }
- memcpy(chars_table, chars_table_1, 256);
+ }
+ memcpy(chars_table, chars_table_1, 256);
chars_table_1[0] = 1;
for (int n = 0; n < 256; n++) {
c_chars_table[n] = !chars_table_1[n];
}
-}
-
+}
+
Tr::Tr(const char* from, const char* to) {
for (size_t n = 0; n < 256; n++) {
- Map[n] = (char)n;
+ Map[n] = (char)n;
}
for (; *from && *to; from++, to++) {
- Map[(ui8)*from] = *to;
+ Map[(ui8)*from] = *to;
}
-}
+}
size_t Tr::FindFirstChangePosition(const TString& str) const {
for (auto it = str.begin(); it != str.end(); ++it) {
diff --git a/util/string/util.h b/util/string/util.h
index 0d77a5042b..0c41a3459e 100644
--- a/util/string/util.h
+++ b/util/string/util.h
@@ -53,24 +53,24 @@ inline void addIfAbsent(TString& s, char lastCh1, char lastCh2) {
*
* ------------------------------------------------------------------
*/
-struct ui8_256 {
+struct ui8_256 {
// forward chars table
- ui8 chars_table[256];
+ ui8 chars_table[256];
// reverse (for c* functions) chars table
ui8 c_chars_table[256];
-};
-
+};
+
class str_spn: public ui8_256 {
public:
explicit str_spn(const char* charset, bool extended = false) {
- // exteneded: if true, treat charset string more like
- // interior of brackets [ ], e.g. "a-z0-9"
- init(charset, extended);
- }
-
- /// Return first character in table, like strpbrk()
- /// That is, skip all characters not in table
- /// [DIFFERENCE FOR NOT_FOUND CASE: Returns end of string, not NULL]
+ // exteneded: if true, treat charset string more like
+ // interior of brackets [ ], e.g. "a-z0-9"
+ init(charset, extended);
+ }
+
+ /// Return first character in table, like strpbrk()
+ /// That is, skip all characters not in table
+ /// [DIFFERENCE FOR NOT_FOUND CASE: Returns end of string, not NULL]
const char* brk(const char* s) const {
while (c_chars_table[(ui8)*s])
++s;
@@ -83,13 +83,13 @@ public:
return s;
}
- /// Return first character not in table, like strpbrk() for inverted table.
- /// That is, skip all characters in table
+ /// Return first character not in table, like strpbrk() for inverted table.
+ /// That is, skip all characters in table
const char* cbrk(const char* s) const {
while (chars_table[(ui8)*s])
++s;
- return s;
- }
+ return s;
+ }
const char* cbrk(const char* s, const char* e) const {
while (s < e && chars_table[(ui8)*s])
@@ -97,7 +97,7 @@ public:
return s;
}
- /// Offset of the first character not in table, like strspn().
+ /// Offset of the first character not in table, like strspn().
size_t spn(const char* s) const {
return cbrk(s) - s;
}
@@ -106,7 +106,7 @@ public:
return cbrk(s, e) - s;
}
- /// Offset of the first character in table, like strcspn().
+ /// Offset of the first character in table, like strcspn().
size_t cspn(const char* s) const {
return brk(s) - s;
}
@@ -123,35 +123,35 @@ public:
return const_cast<char*>(cbrk((const char*)s));
}
- /// See strsep [BUT argument is *&, not **]
+ /// See strsep [BUT argument is *&, not **]
char* sep(char*& s) const {
- char sep_char; // unused;
- return sep(s, sep_char);
- }
-
- /// strsep + remember character that was destroyed
+ char sep_char; // unused;
+ return sep(s, sep_char);
+ }
+
+ /// strsep + remember character that was destroyed
char* sep(char*& s, char& sep_char) const {
- if (!s)
+ if (!s)
return nullptr;
char* ret = s;
char* next = brk(ret);
- if (*next) {
- sep_char = *next;
- *next = 0;
- s = next + 1;
- } else {
- sep_char = 0;
+ if (*next) {
+ sep_char = *next;
+ *next = 0;
+ s = next + 1;
+ } else {
+ sep_char = 0;
s = nullptr;
- }
- return ret;
- }
-
+ }
+ return ret;
+ }
+
protected:
void init(const char* charset, bool extended);
str_spn() = default;
-};
-
-// an analogue of tr/$from/$to/
+};
+
+// an analogue of tr/$from/$to/
class Tr {
public:
Tr(const char* from, const char* to);
@@ -161,14 +161,14 @@ public:
}
void Do(char* s) const {
- for (; *s; s++)
+ for (; *s; s++)
*s = ConvertChar(*s);
- }
+ }
void Do(const char* src, char* dst) const {
- for (; *src; src++)
+ for (; *src; src++)
*dst++ = ConvertChar(*src);
- *dst = 0;
- }
+ *dst = 0;
+ }
void Do(char* s, size_t l) const {
for (size_t i = 0; i < l && s[i]; i++)
s[i] = ConvertChar(s[i]);
@@ -179,7 +179,7 @@ private:
char Map[256];
size_t FindFirstChangePosition(const TString& str) const;
-};
+};
// Removes all occurrences of given character from string
template <typename TStringType>
diff --git a/util/string/util_ut.cpp b/util/string/util_ut.cpp
index 18a2d8e195..5c6e003132 100644
--- a/util/string/util_ut.cpp
+++ b/util/string/util_ut.cpp
@@ -10,8 +10,8 @@ class TStrUtilTest: public TTestBase {
public:
void TestSpn() {
- str_spn rul("a-z", true);
- char s[] = "!@#$ab%^&c+-";
+ str_spn rul("a-z", true);
+ char s[] = "!@#$ab%^&c+-";
UNIT_ASSERT_EQUAL(rul.brk(s), s + 4);
UNIT_ASSERT_EQUAL(rul.brk(s + 4), s + 4);
UNIT_ASSERT_EQUAL(rul.brk(s + 10), s + 12);
@@ -21,7 +21,7 @@ public:
UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "%^&"), 0);
UNIT_ASSERT_EQUAL(strcmp(rul.sep(s1), "+-"), 0);
UNIT_ASSERT_EQUAL(rul.sep(s1), nullptr);
- }
+ }
void TestRemoveAll() {
static const struct T {