summaryrefslogtreecommitdiff
path: root/bot/src/utils/string.cpp
diff options
context:
space:
mode:
authorilotterytea <iltsu@alright.party>2024-12-09 11:06:46 +0500
committerilotterytea <iltsu@alright.party>2024-12-09 11:06:46 +0500
commitad05411350f1152cc3c86cebb5b8492d34507b33 (patch)
treed577d9adf03b80bb1ab5c2fc4a91f097d1ce5f83 /bot/src/utils/string.cpp
parent99d1a1563676c2bb95574fb079a9367fbd1acf34 (diff)
feat: an util for separating string vectors by text length
Diffstat (limited to 'bot/src/utils/string.cpp')
-rw-r--r--bot/src/utils/string.cpp22
1 files changed, 22 insertions, 0 deletions
diff --git a/bot/src/utils/string.cpp b/bot/src/utils/string.cpp
index 71c06bf..0fd01ec 100644
--- a/bot/src/utils/string.cpp
+++ b/bot/src/utils/string.cpp
@@ -61,6 +61,28 @@ namespace bot {
return false;
}
+
+ std::vector<std::vector<std::string>> separate_by_length(
+ const std::vector<std::string> &vector, const int &max_length) {
+ std::vector<std::vector<std::string>> output;
+ std::vector<std::string> active;
+ int length = 0;
+
+ for (const std::string &str : vector) {
+ length += str.length();
+
+ if (length >= max_length) {
+ output.push_back(active);
+ active = {str};
+ } else {
+ active.push_back(str);
+ }
+ }
+
+ if (!active.empty()) output.push_back(active);
+
+ return output;
+ }
}
}
}