diff options
author | louiz’ <louiz@louiz.org> | 2016-06-14 20:14:36 +0200 |
---|---|---|
committer | louiz’ <louiz@louiz.org> | 2016-06-14 20:14:36 +0200 |
commit | 80d0c19c5a8d548a8c6019033bf574ff2be4c0ce (patch) | |
tree | c02303b06ee6a7603f175aab767f3d5742152c4b /louloulibs | |
parent | 19bca5c2f2b104d534a7c8be7f61dc48d928cf24 (diff) | |
download | biboumi-80d0c19c5a8d548a8c6019033bf574ff2be4c0ce.tar.gz biboumi-80d0c19c5a8d548a8c6019033bf574ff2be4c0ce.tar.bz2 biboumi-80d0c19c5a8d548a8c6019033bf574ff2be4c0ce.tar.xz biboumi-80d0c19c5a8d548a8c6019033bf574ff2be4c0ce.zip |
Refactor, test and improve the way we cut too-long messages for IRC
Diffstat (limited to 'louloulibs')
-rw-r--r-- | louloulibs/utils/string.cpp | 12 | ||||
-rw-r--r-- | louloulibs/utils/string.hpp | 2 |
2 files changed, 14 insertions, 0 deletions
diff --git a/louloulibs/utils/string.cpp b/louloulibs/utils/string.cpp index 3977feb..7ed1aa3 100644 --- a/louloulibs/utils/string.cpp +++ b/louloulibs/utils/string.cpp @@ -4,3 +4,15 @@ bool to_bool(const std::string& val) { return (val == "1" || val == "true"); } + +std::vector<std::string> cut(const std::string& val, const std::size_t size) +{ + std::vector<std::string> res; + std::string::size_type pos = 0; + while (pos < val.size()) + { + res.emplace_back(val.substr(pos, size)); + pos += size; + } + return res; +} diff --git a/louloulibs/utils/string.hpp b/louloulibs/utils/string.hpp index 3775c36..1c8f001 100644 --- a/louloulibs/utils/string.hpp +++ b/louloulibs/utils/string.hpp @@ -1,8 +1,10 @@ #ifndef STRING_UTILS_HPP_INCLUDED #define STRING_UTILS_HPP_INCLUDED +#include <vector> #include <string> bool to_bool(const std::string& val); +std::vector<std::string> cut(const std::string& val, const std::size_t size); #endif /* STRING_UTILS_HPP_INCLUDED */ |