aboutsummaryrefslogtreecommitdiffstats
path: root/src/lib/utils
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/utils')
-rw-r--r--src/lib/utils/parsing.cpp13
-rw-r--r--src/lib/utils/parsing.h8
-rw-r--r--src/lib/utils/read_cfg.cpp22
3 files changed, 30 insertions, 13 deletions
diff --git a/src/lib/utils/parsing.cpp b/src/lib/utils/parsing.cpp
index cf47e24f8..c5081dcd7 100644
--- a/src/lib/utils/parsing.cpp
+++ b/src/lib/utils/parsing.cpp
@@ -1,6 +1,6 @@
/*
* Various string utils and parsing functions
-* (C) 1999-2007,2013 Jack Lloyd
+* (C) 1999-2007,2013,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
@@ -105,18 +105,21 @@ std::vector<std::string> parse_algorithm_name(const std::string& namex)
return elems;
}
-/*
-* Split the string on slashes
-*/
std::vector<std::string> split_on(const std::string& str, char delim)
{
+ return split_on_pred(str, [delim](char c) { return c == delim; });
+ }
+
+std::vector<std::string> split_on_pred(const std::string& str,
+ std::function<bool (char)> pred)
+ {
std::vector<std::string> elems;
if(str == "") return elems;
std::string substr;
for(auto i = str.begin(); i != str.end(); ++i)
{
- if(*i == delim)
+ if(pred(*i))
{
if(substr != "")
elems.push_back(substr);
diff --git a/src/lib/utils/parsing.h b/src/lib/utils/parsing.h
index b37e3cb62..f2642ff95 100644
--- a/src/lib/utils/parsing.h
+++ b/src/lib/utils/parsing.h
@@ -37,6 +37,14 @@ BOTAN_DLL std::vector<std::string> split_on(
const std::string& str, char delim);
/**
+* Split a string on a character predicate
+* @param str the input string
+*/
+BOTAN_DLL std::vector<std::string>
+split_on_pred(const std::string& str,
+ std::function<bool (char)> pred);
+
+/**
* Erase characters from a string
*/
BOTAN_DLL std::string erase_chars(const std::string& str, const std::set<char>& chars);
diff --git a/src/lib/utils/read_cfg.cpp b/src/lib/utils/read_cfg.cpp
index ad57a8b3e..31348832a 100644
--- a/src/lib/utils/read_cfg.cpp
+++ b/src/lib/utils/read_cfg.cpp
@@ -1,12 +1,12 @@
/*
* Simple config/test file reader
-* (C) 2013 Jack Lloyd
+* (C) 2013,2014 Jack Lloyd
*
* Distributed under the terms of the Botan license
*/
#include <botan/parsing.h>
-#include <boost/algorithm/string.hpp>
+#include <ctype.h>
namespace Botan {
@@ -21,11 +21,18 @@ void lex_cfg(std::istream& is,
while(is.good() && s.back() == '\\')
{
- boost::trim_if(s, boost::is_any_of("\\\n"));
+ while(s.size() && (s.back() == '\\' || s.back() == '\n'))
+ s.resize(s.size()-1);
+
std::string x;
std::getline(is, x);
- boost::trim_left(x);
- s += x;
+
+ size_t i = 0;
+
+ while(i < x.size() && (::isspace(x[i])))
+ ++i;
+
+ s += x.substr(i);
}
auto comment = s.find('#');
@@ -35,10 +42,9 @@ void lex_cfg(std::istream& is,
if(s.empty())
continue;
- std::vector<std::string> parts;
- boost::split(parts, s, boost::is_any_of(" \t\n"), boost::token_compress_on);
+ auto parts = split_on_pred(s, [](char c) { return ::isspace(c); });
- for(auto p : parts)
+ for(auto& p : parts)
{
if(p.empty())
continue;