소스 검색

include mechanism

Patrick Brosi 5 년 전
부모
커밋
afacc8bc77
2개의 변경된 파일23개의 추가작업 그리고 2개의 파일을 삭제
  1. 21 2
      ConfigFileParser.cpp
  2. 2 0
      ConfigFileParser.h

+ 21 - 2
ConfigFileParser.cpp

@@ -44,7 +44,7 @@ void ConfigFileParser::parse(const std::string& path) {
44 44
     switch (s) {
45 45
       case NONE:
46 46
         if (std::isspace(c)) continue;
47
-        if (c == '[') {
47
+        if (c == '[' || c == '<') {
48 48
           if (tmp.size()) curKV[tmp] = Val{trim(tmp2), valLine, valPos, path};
49 49
           tmp.clear();
50 50
           tmp2.clear();
@@ -58,7 +58,8 @@ void ConfigFileParser::parse(const std::string& path) {
58 58
           }
59 59
           headers.clear();
60 60
           curKV.clear();
61
-          s = IN_HEAD;
61
+          if (c == '[') s = IN_HEAD;
62
+          if (c == '<') s = IN_INC;
62 63
           continue;
63 64
         }
64 65
         if (isKeyChar(c)) {
@@ -69,6 +70,19 @@ void ConfigFileParser::parse(const std::string& path) {
69 70
         }
70 71
         throw ParseExc(l, pos, "header or key", std::string("'") + c + "'",
71 72
                        path);
73
+
74
+      case IN_INC:
75
+        if (c == '\n') {
76
+          throw ParseExc(l, pos, ">", "<newline>", path);
77
+        } else if (c == '>') {
78
+          parse(tmp);
79
+          tmp.clear();
80
+          s = NONE;
81
+        } else {
82
+          tmp += c;
83
+        }
84
+        continue;
85
+
72 86
       case IN_HEAD:
73 87
         if (std::isspace(c)) continue;
74 88
         if (isKeyChar(c)) {
@@ -319,6 +333,11 @@ const Val& ConfigFileParser::getVal(Sec section, Key key) const {
319 333
 }
320 334
 
321 335
 // _____________________________________________________________________________
336
+const KeyVals& ConfigFileParser::getKeyVals(Sec section) const {
337
+  return _kvs[_secs.find(section)->second];
338
+}
339
+
340
+// _____________________________________________________________________________
322 341
 bool ConfigFileParser::hasKey(Sec section, Key key) const {
323 342
   if (_secs.find(section) == _secs.end()) return false;
324 343
   if (_kvs[_secs.find(section)->second].find(key) ==

+ 2 - 0
ConfigFileParser.h

@@ -26,6 +26,7 @@ typedef std::unordered_map<std::string, Val> KeyVals;
26 26
 enum State {
27 27
   NONE,
28 28
   IN_HEAD,
29
+  IN_INC,
29 30
   IN_HEAD_KEY,
30 31
   IN_HEAD_AW_COM_OR_END,
31 32
   IN_KEY_VAL_KEY,
@@ -87,6 +88,7 @@ class ConfigFileParser {
87 88
   bool hasKey(Sec section, Key key) const;
88 89
 
89 90
   const Val& getVal(Sec section, Key key) const;
91
+  const KeyVals& getKeyVals(Sec section) const;
90 92
 
91 93
  private:
92 94
   std::unordered_map<std::string, size_t> _secs;