osquery-1/osquery/core/text.cpp

30 lines
700 B
C++
Raw Normal View History

2014-08-04 21:12:06 +00:00
// Copyright 2004-present Facebook. All Rights Reserved.
#include "osquery/core.h"
2014-08-04 23:08:49 +00:00
#include <boost/algorithm/string/split.hpp>
2014-08-06 22:55:46 +00:00
#include <boost/algorithm/string/trim.hpp>
2014-08-04 21:12:06 +00:00
namespace osquery { namespace core {
2014-08-04 23:08:49 +00:00
std::vector<std::string> split(const std::string& s) {
return split(s, "\t ");
}
std::vector<std::string> split(const std::string& s,
2014-08-06 22:55:46 +00:00
const std::string& delim) {
2014-08-04 21:12:06 +00:00
std::vector<std::string> elems;
2014-08-06 22:55:46 +00:00
boost::split(elems, s, boost::is_any_of(delim));
2014-08-04 21:12:06 +00:00
auto start = std::remove_if(elems.begin(), elems.end(),
[](const std::string &s) { return s == ""; }
2014-08-04 21:12:06 +00:00
);
elems.erase(start, elems.end());
2014-08-04 23:08:49 +00:00
for (auto& each : elems) {
2014-08-06 22:55:46 +00:00
boost::algorithm::trim(each);
2014-08-04 23:08:49 +00:00
}
2014-08-04 21:12:06 +00:00
return elems;
}
}}