aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp')
-rw-r--r--src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp63
1 files changed, 63 insertions, 0 deletions
diff --git a/src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp b/src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp
new file mode 100644
index 0000000000..bf68c04792
--- /dev/null
+++ b/src/libs/3rdparty/botan/src/lib/utils/read_cfg.cpp
@@ -0,0 +1,63 @@
+/*
+* Simple config/test file reader
+* (C) 2013,2014,2015 Jack Lloyd
+*
+* Botan is released under the Simplified BSD License (see license.txt)
+*/
+
+#include <botan/parsing.h>
+#include <botan/exceptn.h>
+
+namespace Botan {
+
+std::string clean_ws(const std::string& s)
+ {
+ const char* ws = " \t\n";
+ auto start = s.find_first_not_of(ws);
+ auto end = s.find_last_not_of(ws);
+
+ if(start == std::string::npos)
+ return "";
+
+ if(end == std::string::npos)
+ return s.substr(start, end);
+ else
+ return s.substr(start, start + end + 1);
+ }
+
+std::map<std::string, std::string> read_cfg(std::istream& is)
+ {
+ std::map<std::string, std::string> kv;
+ size_t line = 0;
+
+ while(is.good())
+ {
+ std::string s;
+
+ std::getline(is, s);
+
+ ++line;
+
+ if(s.empty() || s[0] == '#')
+ continue;
+
+ s = clean_ws(s.substr(0, s.find('#')));
+
+ if(s.empty())
+ continue;
+
+ auto eq = s.find("=");
+
+ if(eq == std::string::npos || eq == 0 || eq == s.size() - 1)
+ throw Exception("Bad read_cfg input '" + s + "' on line " + std::to_string(line));
+
+ const std::string key = clean_ws(s.substr(0, eq));
+ const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
+
+ kv[key] = val;
+ }
+
+ return kv;
+ }
+
+}