summaryrefslogtreecommitdiff
path: root/bot/src/utils/string.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2025-04-17 03:03:03 +0500
committerilotterytea <iltsu@alright.party>2025-04-17 03:03:03 +0500
commitcbd5810df1f051a56a052fd4ad48c9629e884d26 (patch)
treeadd3ba61fa3289f71f50c599ff4008372144f885 /bot/src/utils/string.cpp
parentd54fa21b30a52c453aaa03c734e278f9fc8adb02 (diff)
feat: separate strings by length (new function)
Diffstat (limited to 'bot/src/utils/string.cpp')
-rw-r--r--bot/src/utils/string.cpp30
1 files changed, 30 insertions, 0 deletions
diff --git a/bot/src/utils/string.cpp b/bot/src/utils/string.cpp
index 0fd01ec..38087dc 100644
--- a/bot/src/utils/string.cpp
+++ b/bot/src/utils/string.cpp
@@ -1,5 +1,6 @@
#include "string.hpp"
+#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
@@ -83,6 +84,35 @@ namespace bot {
return output;
}
+
+ std::vector<std::string> separate_by_length(
+ const std::string &base, const std::vector<std::string> &values,
+ const std::string &prefix, const std::string &separator,
+ const long long &max_length) {
+ std::vector<std::string> lines = {""};
+ int index = 0;
+
+ std::for_each(values.begin(), values.end(),
+ [&lines, &prefix, &separator, &base, &index,
+ &max_length](const std::string &v) {
+ const std::string &m = lines.at(index);
+ std::string x = prefix + v;
+
+ if (base.length() + m.length() + x.length() +
+ separator.length() >=
+ max_length) {
+ index += 1;
+ }
+
+ if (index > lines.size() - 1) {
+ lines.push_back(x);
+ } else {
+ lines[index] = m + separator + x;
+ }
+ });
+
+ return lines;
+ }
}
}
}