add internal replacement for boost::split and use it

This commit is contained in:
Arne Morten Kvarving
2020-02-18 14:35:24 +01:00
parent 57d88dea7e
commit 2b6754151f
4 changed files with 61 additions and 9 deletions

View File

@@ -3,7 +3,9 @@
#include <algorithm>
#include <cctype>
#include <sstream>
#include <string>
#include <vector>
namespace Opm {
@@ -68,6 +70,39 @@ void replaceAll(T& data, const T& toSearch, const T& replace)
}
}
inline std::vector<std::string> split_string(const std::string& input,
char delimiter)
{
std::vector<std::string> result;
std::string token;
std::istringstream tokenStream(input);
while (std::getline(tokenStream, token, delimiter))
result.push_back(token);
return result;
}
inline std::vector<std::string> split_string(const std::string& input,
const std::string& delimiters)
{
std::vector<std::string> result;
std::string::size_type start = 0;
while (start < input.size()) {
auto end = input.find_first_of(delimiters, start);
if (end == std::string::npos) {
result.push_back(input.substr(start));
end = input.size() - 1;
} else if (end != start)
result.push_back(input.substr(start, end-start));
start = end + 1;
}
return result;
}
}
#endif //OPM_UTILITY_STRING_HPP