Bläddra i källkod

allow string parsing

Patrick Brosi 4 år sedan
förälder
incheckning
6c777a5aec
2 ändrade filer med 21 tillägg och 4 borttagningar
  1. 17 4
      ConfigFileParser.cpp
  2. 4 0
      ConfigFileParser.h

+ 17 - 4
ConfigFileParser.cpp

@@ -16,17 +16,30 @@ using namespace configparser;
16 16
 ConfigFileParser::ConfigFileParser() {}
17 17
 
18 18
 // _____________________________________________________________________________
19
+void ConfigFileParser::parseStr(const std::string& str) {
20
+  std::stringstream ss;
21
+  ss << str;
22
+  parse(ss, "<string literal>");
23
+}
24
+
25
+// _____________________________________________________________________________
19 26
 void ConfigFileParser::parse(const std::string& path) {
20
-  State s = NONE;
21
-  std::set<std::string> headers;
22
-  KeyVals curKV;
23
-  std::string tmp, tmp2;
24 27
   std::ifstream is(path);
25 28
 
26 29
   if (!is.good()) {
27 30
     throw ParseFileExc(path);
28 31
   }
29 32
 
33
+  parse(is, path);
34
+}
35
+
36
+// _____________________________________________________________________________
37
+void ConfigFileParser::parse(std::istream& is, const std::string& path) {
38
+  State s = NONE;
39
+  std::set<std::string> headers;
40
+  KeyVals curKV;
41
+  std::string tmp, tmp2;
42
+
30 43
   char c;
31 44
   size_t l = 1, pos = 0, valLine = 0, valPos = 0;
32 45
 

+ 4 - 0
ConfigFileParser.h

@@ -70,6 +70,10 @@ class ConfigFileParser {
70 70
  public:
71 71
   ConfigFileParser();
72 72
   void parse(const std::string& path);
73
+  void parse(std::istream& is, const std::string& path);
74
+  void parseStr(const std::string& str);
75
+
76
+  void addKV(const std::string& sec, const std::string& k, const std::string& v);
73 77
 
74 78
   const std::string& getStr(Sec sec, const Key& key) const;
75 79
   int getInt(Sec sec, const Key& key) const;