From 80d0c19c5a8d548a8c6019033bf574ff2be4c0ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?louiz=E2=80=99?= Date: Tue, 14 Jun 2016 20:14:36 +0200 Subject: Refactor, test and improve the way we cut too-long messages for IRC --- louloulibs/utils/string.cpp | 12 ++++++++++++ louloulibs/utils/string.hpp | 2 ++ 2 files changed, 14 insertions(+) (limited to 'louloulibs/utils') 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 cut(const std::string& val, const std::size_t size) +{ + std::vector 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 #include bool to_bool(const std::string& val); +std::vector cut(const std::string& val, const std::size_t size); #endif /* STRING_UTILS_HPP_INCLUDED */ -- cgit v1.2.3