Преглед на файлове

Add IniParser::GetSections

ithewei преди 3 години
родител
ревизия
fe2cb726b3
променени са 2 файла, в които са добавени 15 реда и са изтрити 3 реда
  1. 13 2
      cpputil/iniparser.cpp
  2. 2 1
      cpputil/iniparser.h

+ 13 - 2
cpputil/iniparser.cpp

@@ -285,8 +285,19 @@ int IniParser::SaveAs(const char* filepath) {
     return 0;
 }
 
-std::list<std::string> IniParser::GetKeys(const std::string& section)
-{
+std::list<std::string> IniParser::GetSections() {
+    std::list<std::string> ret;
+    if (root_ == NULL) return std::move(ret);
+
+    for (auto pNode : root_->children) {
+        if (pNode->type == IniNode::INI_NODE_TYPE_SECTION) {
+            ret.push_back(pNode->label);
+        }
+    }
+    return std::move(ret);
+}
+
+std::list<std::string> IniParser::GetKeys(const std::string& section) {
     std::list<std::string> ret;
     if (root_ == NULL) return std::move(ret);
 

+ 2 - 1
cpputil/iniparser.h

@@ -25,7 +25,8 @@ public:
     std::string DumpString();
     int Save();
     int SaveAs(const char* filepath);
-    
+
+    std::list<std::string> GetSections();
     std::list<std::string> GetKeys(const std::string& section = "");
     std::string GetValue(const std::string& key, const std::string& section = "");
     void        SetValue(const std::string& key, const std::string& value, const std::string& section = "");