diff options
| author | Yuqian Yang <crupest@crupest.life> | 2025-11-04 22:06:39 +0800 |
|---|---|---|
| committer | Yuqian Yang <crupest@crupest.life> | 2025-11-04 22:06:39 +0800 |
| commit | 8bea03e0811588e741050b598b8123865b333999 (patch) | |
| tree | dab70865e53fca11960cb899454d64db9e8ed98d /src/toml/TomlParser.cpp | |
| parent | 1a6111e3f02b0a9cff0f81fb524b4dfb7d69854b (diff) | |
| download | cru-8bea03e0811588e741050b598b8123865b333999.tar.gz cru-8bea03e0811588e741050b598b8123865b333999.tar.bz2 cru-8bea03e0811588e741050b598b8123865b333999.zip | |
Move toml to base.
Diffstat (limited to 'src/toml/TomlParser.cpp')
| -rw-r--r-- | src/toml/TomlParser.cpp | 45 |
1 files changed, 0 insertions, 45 deletions
diff --git a/src/toml/TomlParser.cpp b/src/toml/TomlParser.cpp deleted file mode 100644 index 1aea5b73..00000000 --- a/src/toml/TomlParser.cpp +++ /dev/null @@ -1,45 +0,0 @@ -#include "cru/toml/TomlParser.h" -#include "cru/base/StringUtil.h" -#include "cru/toml/TomlDocument.h" - -namespace cru::toml { -TomlParser::TomlParser(std::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) { - std::vector<std::string> lines = cru::string::Split(input_, "\n", cru::string::SplitOptions::RemoveSpace); - - std::string current_section_name; - - for (auto& line : lines) { - line = cru::string::Trim(line); - if (line.starts_with("[") && line.ends_with("]")) { - current_section_name = line.substr(1, line.size() - 2); - } else if (line.starts_with("#")) { - // Ignore comments. - } else { - auto equal_index = line.find('='); - - if (equal_index == std::string::npos) { - throw TomlParsingException("Invalid TOML line: " + line); - } - - auto key = cru::string::Trim(line.substr(0, equal_index)); - auto value = cru::string::Trim(line.substr(equal_index + 1)); - - document.GetSectionOrCreate(current_section_name)->SetValue(key, value); - } - } -} -} // namespace cru::toml |
