aboutsummaryrefslogtreecommitdiffstats
path: root/util/string/strip.h
diff options
context:
space:
mode:
authorOleg Sidorkin <osidorkin@gmail.com>2022-04-16 13:43:06 +0300
committerOleg Sidorkin <osidorkin@gmail.com>2022-04-16 13:43:06 +0300
commitc1e51b5d64d252145765d1529a71271ee4d33812 (patch)
treeaee1d5a24b2035a857fdf47ac4788b2278a088f5 /util/string/strip.h
parent09be10fcbbf04de7c78405d5bf7c18117a1b339f (diff)
downloadydb-c1e51b5d64d252145765d1529a71271ee4d33812.tar.gz
Add Collapse variant for utf-32 strings
ref:5897581c4d2be8d8775525221d2d910c04d788b8
Diffstat (limited to 'util/string/strip.h')
-rw-r--r--util/string/strip.h16
1 files changed, 15 insertions, 1 deletions
diff --git a/util/string/strip.h b/util/string/strip.h
index d5ef6da96d..a65d3fe069 100644
--- a/util/string/strip.h
+++ b/util/string/strip.h
@@ -230,13 +230,27 @@ bool CollapseImpl(const TStringType& from, TStringType& to, size_t maxLen, const
return false;
}
-bool Collapse(const TString& from, TString& to, size_t maxLen = 0);
+template <class TStringType, class TWhitespaceFunc>
+std::enable_if_t<std::is_invocable_v<TWhitespaceFunc, typename TStringType::value_type>, bool> Collapse(
+ const TStringType& from, TStringType& to, TWhitespaceFunc isWhitespace, size_t maxLen = 0)
+{
+ return CollapseImpl(from, to, maxLen, isWhitespace);
+}
+
+inline bool Collapse(const TString& from, TString& to, size_t maxLen = 0) {
+ return Collapse(from, to, IsAsciiSpace<typename TString::value_type>, maxLen);
+}
/// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes)
inline TString& CollapseInPlace(TString& s, size_t maxLen = 0) {
Collapse(s, s, maxLen);
return s;
}
+template <class TStringType, class TWhitespaceFunc>
+inline TStringType& CollapseInPlace(TStringType& s, TWhitespaceFunc isWhitespace, size_t maxLen = 0) {
+ Collapse(s, s, isWhitespace, maxLen);
+ return s;
+}
/// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes)
inline TString Collapse(const TString& s, size_t maxLen = 0) Y_WARN_UNUSED_RESULT;