Skip to content
Snippets Groups Projects
Commit 233624b5 authored by René Fritze's avatar René Fritze
Browse files

[string] fixes non-string tokenizer

parent 7b2c0d96
No related branches found
No related tags found
No related merge requests found
...@@ -95,11 +95,26 @@ inline std::vector<T> ...@@ -95,11 +95,26 @@ inline std::vector<T>
tokenize(const std::string& msg, const std::string& seperators, tokenize(const std::string& msg, const std::string& seperators,
const boost::algorithm::token_compress_mode_type mode = boost::algorithm::token_compress_off) const boost::algorithm::token_compress_mode_type mode = boost::algorithm::token_compress_off)
{ {
std::vector<T> strings; std::vector<std::string> strings;
boost::algorithm::split(strings, msg, boost::algorithm::is_any_of(seperators), mode);
std::vector<T> ret(strings.size());
size_t i = 0;
// special case for empty strings to avoid non-default init
std::generate(
std::begin(ret), std::end(ret), [&]() { return strings[i++].empty() ? T() : convertFrom<T>(strings[i - 1]); });
return ret;
}
template <>
inline std::vector<std::string> tokenize(const std::string& msg, const std::string& seperators,
const boost::algorithm::token_compress_mode_type mode)
{
std::vector<std::string> strings;
boost::algorithm::split(strings, msg, boost::algorithm::is_any_of(seperators), mode); boost::algorithm::split(strings, msg, boost::algorithm::is_any_of(seperators), mode);
return strings; return strings;
} }
//! returns string with local time in current locale's format
inline std::string fromTime(time_t cur_time = time(NULL)) inline std::string fromTime(time_t cur_time = time(NULL))
{ {
return ctime(&cur_time); return ctime(&cur_time);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment