8#include <botan/internal/parsing.h>
10#include <botan/exceptn.h>
16std::string clean_ws(std::string_view s) {
17 const char* ws =
" \t\n";
18 auto start = s.find_first_not_of(ws);
19 auto end = s.find_last_not_of(ws);
21 if(start == std::string::npos) {
25 if(end == std::string::npos) {
26 return std::string(s.substr(start, end));
28 return std::string(s.substr(start, start + end + 1));
34std::map<std::string, std::string>
read_cfg(std::istream& is) {
35 std::map<std::string, std::string> kv;
45 if(s.empty() || s[0] ==
'#') {
49 s = clean_ws(s.substr(0, s.find(
'#')));
55 auto eq = s.find(
'=');
57 if(eq == std::string::npos || eq == 0 || eq == s.size() - 1) {
58 throw Decoding_Error(
"Bad read_cfg input '" + s +
"' on line " + std::to_string(line));
61 const std::string key = clean_ws(s.substr(0, eq));
62 const std::string val = clean_ws(s.substr(eq + 1, std::string::npos));
std::map< std::string, std::string > read_cfg(std::istream &is)