summaryrefslogtreecommitdiffstats
path: root/util/string/util.h
diff options
context:
space:
mode:
authorAnton Samokhvalov <[email protected]>2022-02-10 16:45:15 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:45:15 +0300
commit72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch)
treeda2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /util/string/util.h
parent778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff)
Restoring authorship annotation for Anton Samokhvalov <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'util/string/util.h')
-rw-r--r--util/string/util.h82
1 files changed, 41 insertions, 41 deletions
diff --git a/util/string/util.h b/util/string/util.h
index 0d77a5042b8..bcc989d67ea 100644
--- a/util/string/util.h
+++ b/util/string/util.h
@@ -1,7 +1,7 @@
#pragma once
-//THIS FILE A COMPAT STUB HEADER
-
+//THIS FILE A COMPAT STUB HEADER
+
#include <cstring>
#include <cstdarg>
#include <algorithm>
@@ -9,7 +9,7 @@
#include <util/system/defaults.h>
#include <util/generic/string.h>
#include <util/generic/strbuf.h>
-
+
/// @addtogroup Strings_Miscellaneous
/// @{
int a2i(const TString& s);
@@ -24,23 +24,23 @@ inline void RemoveIfLast(T& s, int c) {
/// Adds lastCh symbol to the the of the string if it is not already there.
inline void addIfNotLast(TString& s, int lastCh) {
- size_t len = s.length();
- if (!len || s[len - 1] != lastCh) {
- s.append(char(lastCh));
- }
+ size_t len = s.length();
+ if (!len || s[len - 1] != lastCh) {
+ s.append(char(lastCh));
+ }
}
/// @details Finishes the string with lastCh1 if lastCh2 is not present in the string and lastCh1 is not already at the end of the string.
/// Else, if lastCh2 is not equal to the symbol before the last, it finishes the string with lastCh2.
/// @todo ?? Define, when to apply the function. Is in use several times for URLs parsing.
inline void addIfAbsent(TString& s, char lastCh1, char lastCh2) {
- size_t pos = s.find(lastCh2);
+ size_t pos = s.find(lastCh2);
if (pos == TString::npos) {
- //s.append((char)lastCh1);
- addIfNotLast(s, lastCh1);
- } else if (pos < s.length() - 1) {
- addIfNotLast(s, lastCh2);
- }
+ //s.append((char)lastCh1);
+ addIfNotLast(s, lastCh1);
+ } else if (pos < s.length() - 1) {
+ addIfNotLast(s, lastCh2);
+ }
}
/// @}
@@ -60,9 +60,9 @@ struct ui8_256 {
ui8 c_chars_table[256];
};
-class str_spn: public ui8_256 {
-public:
- explicit str_spn(const char* charset, bool extended = false) {
+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);
@@ -71,8 +71,8 @@ public:
/// 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])
+ const char* brk(const char* s) const {
+ while (c_chars_table[(ui8)*s])
++s;
return s;
}
@@ -85,8 +85,8 @@ public:
/// 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])
+ const char* cbrk(const char* s) const {
+ while (chars_table[(ui8)*s])
++s;
return s;
}
@@ -98,43 +98,43 @@ public:
}
/// Offset of the first character not in table, like strspn().
- size_t spn(const char* s) const {
- return cbrk(s) - s;
- }
+ size_t spn(const char* s) const {
+ return cbrk(s) - s;
+ }
size_t spn(const char* s, const char* e) const {
return cbrk(s, e) - s;
}
/// Offset of the first character in table, like strcspn().
- size_t cspn(const char* s) const {
- return brk(s) - s;
- }
+ size_t cspn(const char* s) const {
+ return brk(s) - s;
+ }
size_t cspn(const char* s, const char* e) const {
return brk(s, e) - s;
}
- char* brk(char* s) const {
+ char* brk(char* s) const {
return const_cast<char*>(brk((const char*)s));
- }
+ }
- char* cbrk(char* s) const {
+ char* cbrk(char* s) const {
return const_cast<char*>(cbrk((const char*)s));
- }
-
+ }
+
/// See strsep [BUT argument is *&, not **]
- char* sep(char*& s) const {
+ char* sep(char*& s) const {
char sep_char; // unused;
return sep(s, sep_char);
}
/// strsep + remember character that was destroyed
- char* sep(char*& s, char& sep_char) const {
+ char* sep(char*& s, char& sep_char) const {
if (!s)
return nullptr;
- char* ret = s;
- char* next = brk(ret);
+ char* ret = s;
+ char* next = brk(ret);
if (*next) {
sep_char = *next;
*next = 0;
@@ -146,30 +146,30 @@ public:
return ret;
}
-protected:
- void init(const char* charset, bool extended);
+protected:
+ void init(const char* charset, bool extended);
str_spn() = default;
};
// an analogue of tr/$from/$to/
class Tr {
public:
- Tr(const char* from, const char* to);
+ Tr(const char* from, const char* to);
char ConvertChar(char ch) const {
return Map[(ui8)ch];
}
- void Do(char* s) const {
+ void Do(char* s) const {
for (; *s; s++)
*s = ConvertChar(*s);
}
- void Do(const char* src, char* dst) const {
+ void Do(const char* src, char* dst) const {
for (; *src; src++)
*dst++ = ConvertChar(*src);
*dst = 0;
}
- void Do(char* s, size_t l) const {
+ void Do(char* s, size_t l) const {
for (size_t i = 0; i < l && s[i]; i++)
s[i] = ConvertChar(s[i]);
}