aboutsummaryrefslogtreecommitdiff
path: root/src/toml
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2022-01-08 16:31:09 +0800
committercrupest <crupest@outlook.com>2022-01-08 16:31:09 +0800
commit431cbdbe7d3ae8c45458dcf914717b0365ecd99a (patch)
treec5e593ee1149d0fe3359c010b305ca4e14b8f1c0 /src/toml
parent9bd6a3a18422e8d176ecb52471af69db41d6683c (diff)
downloadcru-431cbdbe7d3ae8c45458dcf914717b0365ecd99a.tar.gz
cru-431cbdbe7d3ae8c45458dcf914717b0365ecd99a.tar.bz2
cru-431cbdbe7d3ae8c45458dcf914717b0365ecd99a.zip
...
Diffstat (limited to 'src/toml')
-rw-r--r--src/toml/CMakeLists.txt5
-rw-r--r--src/toml/TomlDocument.cpp40
-rw-r--r--src/toml/TomlParser.cpp22
3 files changed, 67 insertions, 0 deletions
diff --git a/src/toml/CMakeLists.txt b/src/toml/CMakeLists.txt
new file mode 100644
index 00000000..0285b454
--- /dev/null
+++ b/src/toml/CMakeLists.txt
@@ -0,0 +1,5 @@
+add_library(cru_toml SHARED
+ TomlDocument.cpp
+ TomlParser.cpp
+)
+target_link_libraries(cru_toml PUBLIC cru_base)
diff --git a/src/toml/TomlDocument.cpp b/src/toml/TomlDocument.cpp
new file mode 100644
index 00000000..a785b4e4
--- /dev/null
+++ b/src/toml/TomlDocument.cpp
@@ -0,0 +1,40 @@
+#include "cru/toml/TomlDocument.hpp"
+
+namespace cru::toml {
+std::optional<String> TomlSection::GetValue(const String& key) const {
+ auto it = values_.find(key);
+ if (it == values_.end()) {
+ return std::nullopt;
+ }
+ return it->second;
+}
+
+void TomlSection::SetValue(const String& key, String value) {
+ values_[key] = std::move(value);
+}
+
+void TomlSection::DeleteValue(const String& key) { values_.erase(key); }
+
+TomlSection* TomlDocument::GetSection(const String& name) {
+ auto it = sections_.find(name);
+ if (it == sections_.end()) {
+ return nullptr;
+ }
+ return &it->second;
+}
+
+const TomlSection* TomlDocument::GetSection(const String& name) const {
+ auto it = sections_.find(name);
+ if (it == sections_.end()) {
+ return nullptr;
+ }
+ return &it->second;
+}
+
+void TomlDocument::SetSection(const String& name, TomlSection section) {
+ sections_[name] = std::move(section);
+}
+
+void TomlDocument::DeleteSection(const String& name) { sections_.erase(name); }
+
+} // namespace cru::toml
diff --git a/src/toml/TomlParser.cpp b/src/toml/TomlParser.cpp
new file mode 100644
index 00000000..d54624f6
--- /dev/null
+++ b/src/toml/TomlParser.cpp
@@ -0,0 +1,22 @@
+#include "cru/toml/TomlParser.hpp"
+#include "cru/toml/TomlDocument.hpp"
+
+namespace cru::toml {
+TomlParser::TomlParser(String input) : input_(std::move(input)) {}
+
+TomlParser::~TomlParser() = default;
+
+TomlDocument TomlParser::Parse() {
+ if (cache_) {
+ return *cache_;
+ }
+
+ cache_ = TomlDocument();
+ DoParse(*cache_);
+ return *cache_;
+}
+
+void TomlParser::DoParse(TomlDocument& document) {
+ // TODO: Implement this.
+}
+} // namespace cru::toml