osquery-1/osquery/core/text.cpp

30 lines
846 B
C++
Raw Normal View History

/*
* Copyright (c) 2014, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
2014-08-04 21:12:06 +00:00
#include <osquery/core.h>
2014-08-04 21:12:06 +00:00
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
2014-08-15 07:25:30 +00:00
namespace osquery {
2014-08-04 21:12:06 +00:00
2014-08-15 07:25:30 +00:00
std::vector<std::string> split(const std::string& s, 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-15 07:25:30 +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;
}
2014-08-15 07:25:30 +00:00
}