summaryrefslogtreecommitdiffstats
path: root/util/string/strip.cpp
diff options
context:
space:
mode:
authorDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
committerDevtools Arcadia <[email protected]>2022-02-07 18:08:42 +0300
commit1110808a9d39d4b808aef724c861a2e1a38d2a69 (patch)
treee26c9fed0de5d9873cce7e00bc214573dc2195b7 /util/string/strip.cpp
intermediate changes
ref:cde9a383711a11544ce7e107a78147fb96cc4029
Diffstat (limited to 'util/string/strip.cpp')
-rw-r--r--util/string/strip.cpp23
1 files changed, 23 insertions, 0 deletions
diff --git a/util/string/strip.cpp b/util/string/strip.cpp
new file mode 100644
index 00000000000..c921571cf06
--- /dev/null
+++ b/util/string/strip.cpp
@@ -0,0 +1,23 @@
+#include "strip.h"
+#include "ascii.h"
+
+#include <util/string/reverse.h>
+
+bool Collapse(const TString& from, TString& to, size_t maxLen) {
+ return CollapseImpl<TString, bool (*)(unsigned char)>(from, to, maxLen, IsAsciiSpace);
+}
+
+void CollapseText(const TString& from, TString& to, size_t maxLen) {
+ Collapse(from, to, maxLen);
+ StripInPlace(to);
+ if (to.size() >= maxLen) {
+ to.remove(maxLen - 5); // " ..."
+ ReverseInPlace(to);
+ size_t pos = to.find_first_of(" .,;");
+ if (pos != TString::npos && pos < 32) {
+ to.remove(0, pos + 1);
+ }
+ ReverseInPlace(to);
+ to.append(" ...");
+ }
+}