diff options
Diffstat (limited to 'src/toml')
| -rw-r--r-- | src/toml/TomlDocument.cpp | 16 | ||||
| -rw-r--r-- | src/toml/TomlParser.cpp | 23 |
2 files changed, 20 insertions, 19 deletions
diff --git a/src/toml/TomlDocument.cpp b/src/toml/TomlDocument.cpp index e9351538..af9e2ac8 100644 --- a/src/toml/TomlDocument.cpp +++ b/src/toml/TomlDocument.cpp @@ -1,7 +1,7 @@ #include "cru/toml/TomlDocument.h" namespace cru::toml { -std::optional<String> TomlSection::GetValue(const String& key) const { +std::optional<std::string> TomlSection::GetValue(const std::string& key) const { auto it = values_.find(key); if (it == values_.end()) { return std::nullopt; @@ -9,13 +9,13 @@ std::optional<String> TomlSection::GetValue(const String& key) const { return it->second; } -void TomlSection::SetValue(const String& key, String value) { +void TomlSection::SetValue(const std::string& key, std::string value) { values_[key] = std::move(value); } -void TomlSection::DeleteValue(const String& key) { values_.erase(key); } +void TomlSection::DeleteValue(const std::string& key) { values_.erase(key); } -TomlSection* TomlDocument::GetSection(const String& name) { +TomlSection* TomlDocument::GetSection(const std::string& name) { auto it = sections_.find(name); if (it == sections_.end()) { return nullptr; @@ -23,7 +23,7 @@ TomlSection* TomlDocument::GetSection(const String& name) { return &it->second; } -const TomlSection* TomlDocument::GetSection(const String& name) const { +const TomlSection* TomlDocument::GetSection(const std::string& name) const { auto it = sections_.find(name); if (it == sections_.end()) { return nullptr; @@ -31,7 +31,7 @@ const TomlSection* TomlDocument::GetSection(const String& name) const { return &it->second; } -TomlSection* TomlDocument::GetSectionOrCreate(const String& name) { +TomlSection* TomlDocument::GetSectionOrCreate(const std::string& name) { auto it = sections_.find(name); if (it == sections_.end()) { sections_[name] = TomlSection(); @@ -40,10 +40,10 @@ TomlSection* TomlDocument::GetSectionOrCreate(const String& name) { return &it->second; } -void TomlDocument::SetSection(const String& name, TomlSection section) { +void TomlDocument::SetSection(const std::string& name, TomlSection section) { sections_[name] = std::move(section); } -void TomlDocument::DeleteSection(const String& name) { sections_.erase(name); } +void TomlDocument::DeleteSection(const std::string& name) { sections_.erase(name); } } // namespace cru::toml diff --git a/src/toml/TomlParser.cpp b/src/toml/TomlParser.cpp index 14442c3c..1aea5b73 100644 --- a/src/toml/TomlParser.cpp +++ b/src/toml/TomlParser.cpp @@ -1,8 +1,9 @@ #include "cru/toml/TomlParser.h" +#include "cru/base/StringUtil.h" #include "cru/toml/TomlDocument.h" namespace cru::toml { -TomlParser::TomlParser(String input) : input_(std::move(input)) {} +TomlParser::TomlParser(std::string input) : input_(std::move(input)) {} TomlParser::~TomlParser() = default; @@ -17,25 +18,25 @@ TomlDocument TomlParser::Parse() { } void TomlParser::DoParse(TomlDocument& document) { - std::vector<String> lines = input_.SplitToLines(true); + std::vector<std::string> lines = cru::string::Split(input_, "\n", cru::string::SplitOptions::RemoveSpace); - String current_section_name; + std::string current_section_name; for (auto& line : lines) { - line.Trim(); - if (line.StartWith(u"[") && line.EndWith(u"]")) { + line = cru::string::Trim(line); + if (line.starts_with("[") && line.ends_with("]")) { current_section_name = line.substr(1, line.size() - 2); - } else if (line.StartWith(u"#")) { + } else if (line.starts_with("#")) { // Ignore comments. } else { - auto equal_index = line.Find(u'='); + auto equal_index = line.find('='); - if (equal_index == -1) { - throw TomlParsingException("Invalid TOML line: " + line.ToUtf8()); + if (equal_index == std::string::npos) { + throw TomlParsingException("Invalid TOML line: " + line); } - auto key = line.substr(0, equal_index).Trim(); - auto value = line.substr(equal_index + 1).Trim(); + 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); } |
