summaryrefslogtreecommitdiffstats
path: root/util/string/strip.h
diff options
context:
space:
mode:
authorppavel96 <[email protected]>2023-06-22 11:25:00 +0300
committerppavel96 <[email protected]>2023-06-22 11:25:00 +0300
commit6e1cc98994e9cfbd532fbc9ab707bd56373245f5 (patch)
treeeda42f6fa64a7120f930ca1f940248a050fd572f /util/string/strip.h
parentd845680738f3051ec12fac59188c70ee1a623a88 (diff)
[util] Turn all Collapse / CollapseInPlace overloads into template functions to support arbitrary string types
Diffstat (limited to 'util/string/strip.h')
-rw-r--r--util/string/strip.h13
1 files changed, 8 insertions, 5 deletions
diff --git a/util/string/strip.h b/util/string/strip.h
index 599fdd93ad5..666300e0e71 100644
--- a/util/string/strip.h
+++ b/util/string/strip.h
@@ -246,12 +246,14 @@ std::enable_if_t<std::is_invocable_v<TWhitespaceFunc, typename TStringType::valu
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);
+template <class TStringType>
+inline bool Collapse(const TStringType& from, TStringType& to, size_t maxLen = 0) {
+ return Collapse(from, to, IsAsciiSpace<typename TStringType::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) {
+template <class TStringType>
+inline TStringType& CollapseInPlace(TStringType& s, size_t maxLen = 0) {
Collapse(s, s, maxLen);
return s;
}
@@ -262,8 +264,9 @@ inline TStringType& CollapseInPlace(TStringType& s, TWhitespaceFunc isWhitespace
}
/// Replaces several consequtive space symbols with one (processing is limited to maxLen bytes)
-[[nodiscard]] inline TString Collapse(const TString& s, size_t maxLen = 0) {
- TString ret;
+template <class TStringType>
+[[nodiscard]] inline TStringType Collapse(const TStringType& s, size_t maxLen = 0) {
+ TStringType ret;
Collapse(s, ret, maxLen);
return ret;
}