diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-07 04:48:35 +0000 |
commit | 207df6fc406e81bfeebdff7f404bd242ff3f099f (patch) | |
tree | a1a796b056909dd0a04ffec163db9363a8757808 /src/base/string_util.hh | |
parent | Releasing progress-linux version 0.11.2-1~progress7.99u1. (diff) | |
download | lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.tar.xz lnav-207df6fc406e81bfeebdff7f404bd242ff3f099f.zip |
Merging upstream version 0.12.2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | src/base/string_util.hh | 68 |
1 files changed, 67 insertions, 1 deletions
diff --git a/src/base/string_util.hh b/src/base/string_util.hh index 73a8b87..886fb6c 100644 --- a/src/base/string_util.hh +++ b/src/base/string_util.hh @@ -100,7 +100,12 @@ endswith(const std::string& str, const char (&suffix)[N]) void truncate_to(std::string& str, size_t max_char_len); -std::string scrub_ws(const char* in); +std::string scrub_ws(const char* in, ssize_t len = -1); +inline std::string +scrub_ws(const string_fragment& sf) +{ + return scrub_ws(sf.data(), sf.length()); +} inline std::string trim(const std::string& str) @@ -115,6 +120,16 @@ trim(const std::string& str) return str.substr(start, end - start); } +inline const char* +ltrim(const char* str) +{ + while (isspace(*str)) { + str += 1; + } + + return str; +} + inline std::string rtrim(const std::string& str) { @@ -213,6 +228,8 @@ bool is_blank(const std::string& str); size_t abbreviate_str(char* str, size_t len, size_t max_len); +size_t last_word_str(char* str, size_t len, size_t max_len); + void split_ws(const std::string& str, std::vector<std::string>& toks_out); std::string repeat(const std::string& input, size_t num); @@ -229,4 +246,53 @@ on_blank(const std::string& str, const std::string& def) return str; } +namespace lnav { +class tainted_string { +public: + explicit tainted_string(std::string s) : ts_str(std::move(s)) {} + + bool operator==(const tainted_string& other) const + { + return this->ts_str == other.ts_str; + } + + bool operator!=(const tainted_string& other) const + { + return this->ts_str != other.ts_str; + } + + bool operator<(const tainted_string& other) const + { + return this->ts_str < other.ts_str; + } + + bool empty() const { return this->ts_str.empty(); } + + size_t length() const { return this->ts_str.length(); } + + size_t size() const { return this->ts_str.size(); } + + friend fmt::formatter<lnav::tainted_string>; + +private: + const std::string ts_str; +}; +} // namespace lnav + +namespace fmt { +template<> +struct formatter<lnav::tainted_string> : formatter<string_view> { + auto format(const lnav::tainted_string& ts, + format_context& ctx) -> decltype(ctx.out()) const; +}; +} // namespace fmt + +namespace lnav { +namespace pcre2pp { + +std::string quote(string_fragment sf); + +} +} // namespace lnav + #endif |