2018-01-24 21:29:39 -08:00
|
|
|
#include <sstream>
|
|
|
|
|
#include <string>
|
|
|
|
|
#include <ctime>
|
2018-01-29 01:43:33 -08:00
|
|
|
#include <algorithm>
|
2018-01-24 21:29:39 -08:00
|
|
|
#include <boost/algorithm/string/split.hpp>
|
|
|
|
|
|
|
|
|
|
#include "database.h"
|
2018-01-29 01:43:33 -08:00
|
|
|
#include "io_primitives.h"
|
2018-01-24 21:29:39 -08:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
2018-01-29 01:43:33 -08:00
|
|
|
stringvec
|
|
|
|
|
split_on(string_view words, char sep)
|
2018-01-24 21:29:39 -08:00
|
|
|
{
|
2018-01-29 01:43:33 -08:00
|
|
|
using namespace boost::algorithm;
|
|
|
|
|
stringvec res;
|
|
|
|
|
split(res, words, [sep](char c) { return c == sep; }, token_compress_on);
|
2018-01-24 21:29:39 -08:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Turn a space-seperated list of words into a set of words
|
2018-01-25 21:43:10 -08:00
|
|
|
stringset
|
2018-01-29 01:43:33 -08:00
|
|
|
split_words(string_view words)
|
2018-01-24 21:29:39 -08:00
|
|
|
{
|
|
|
|
|
using namespace boost::algorithm;
|
2018-01-25 21:43:10 -08:00
|
|
|
stringset res;
|
2018-01-29 01:43:33 -08:00
|
|
|
split(res, words, [](char c) { return c == ' '; }, token_compress_on);
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
stringvec
|
|
|
|
|
split_words_vec(string_view words)
|
|
|
|
|
{
|
|
|
|
|
auto res = split_on(words, ' ');
|
|
|
|
|
std::sort(res.begin(), res.end());
|
2018-01-24 21:29:39 -08:00
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::string
|
2018-01-25 21:43:10 -08:00
|
|
|
join_words(const stringset &words)
|
2018-01-24 21:29:39 -08:00
|
|
|
{
|
|
|
|
|
std::ostringstream out;
|
|
|
|
|
|
|
|
|
|
for (const auto &w : words) {
|
|
|
|
|
out << w;
|
|
|
|
|
out << ' ';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto res = out.str();
|
|
|
|
|
|
|
|
|
|
if (res.back() == ' ') {
|
|
|
|
|
res.pop_back();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-29 01:43:33 -08:00
|
|
|
std::string
|
|
|
|
|
join_words(const stringvec &words)
|
|
|
|
|
{
|
|
|
|
|
std::string res;
|
|
|
|
|
|
|
|
|
|
for (auto i = words.begin(); i != words.end(); ++i) {
|
|
|
|
|
if (i != words.begin()) {
|
|
|
|
|
res += ' ';
|
|
|
|
|
}
|
|
|
|
|
res += *i;
|
|
|
|
|
}
|
|
|
|
|
return res;
|
|
|
|
|
}
|
|
|
|
|
|
2018-01-24 21:29:39 -08:00
|
|
|
std::string
|
|
|
|
|
get_time()
|
|
|
|
|
{
|
|
|
|
|
std::time_t now = time(nullptr);
|
|
|
|
|
std::string nowstr = std::ctime(&now);
|
|
|
|
|
if (nowstr.back() == '\n') {
|
|
|
|
|
nowstr.pop_back();
|
|
|
|
|
}
|
|
|
|
|
return nowstr;
|
|
|
|
|
}
|