diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-11-20 11:14:58 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-11-20 11:14:58 +0000 |
commit | 31773f157bf8164364649b5f470f52dece0a4317 (patch) | |
tree | 33d0f7eef45303ab68cf08ab381ce5e5e36c5240 /util/string/util.h | |
parent | 2c7938962d8689e175574fc1e817c05049f27905 (diff) | |
parent | eff600952d5dfe17942f38f510a8ac2b203bb3a5 (diff) | |
download | ydb-31773f157bf8164364649b5f470f52dece0a4317.tar.gz |
Merge branch 'rightlib' into mergelibs-241120-1113
Diffstat (limited to 'util/string/util.h')
-rw-r--r-- | util/string/util.h | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/util/string/util.h b/util/string/util.h index 47651adb71..4b79d768bf 100644 --- a/util/string/util.h +++ b/util/string/util.h @@ -18,8 +18,9 @@ int a2i(const TString& s); template <class T> inline void RemoveIfLast(T& s, int c) { const size_t length = s.length(); - if (length && s[length - 1] == c) + if (length && s[length - 1] == c) { s.remove(length - 1); + } } /// Adds lastCh symbol to the the of the string if it is not already there. @@ -72,28 +73,32 @@ public: /// 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]) + while (c_chars_table[(ui8)*s]) { ++s; + } return s; } const char* brk(const char* s, const char* e) const { - while (s < e && c_chars_table[(ui8)*s]) + while (s < e && c_chars_table[(ui8)*s]) { ++s; + } return s; } /// 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]) + while (chars_table[(ui8)*s]) { ++s; + } return s; } const char* cbrk(const char* s, const char* e) const { - while (s < e && chars_table[(ui8)*s]) + while (s < e && chars_table[(ui8)*s]) { ++s; + } return s; } @@ -131,8 +136,9 @@ public: /// 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) { @@ -161,17 +167,20 @@ 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; } void Do(char* s, size_t l) const { - for (size_t i = 0; i < l && s[i]; i++) + for (size_t i = 0; i < l && s[i]; i++) { s[i] = ConvertChar(s[i]); + } } void Do(TString& str) const; @@ -185,8 +194,9 @@ private: template <typename TStringType> void RemoveAll(TStringType& str, typename TStringType::char_type ch) { size_t pos = str.find(ch); // 'find' to avoid cloning of string in 'TString.begin()' - if (pos == TStringType::npos) + if (pos == TStringType::npos) { return; + } typename TStringType::iterator begin = str.begin(); typename TStringType::iterator end = begin + str.length(); |