small refactor

This commit is contained in:
2023-04-30 12:03:08 +01:00
parent af1c9f12d8
commit 3189442299
7 changed files with 56 additions and 119 deletions

View File

@ -17,7 +17,7 @@ std::string info_string::get(const std::string& key) const {
return value->second;
}
return "";
return {};
}
void info_string::parse(std::string buffer) {
@ -25,24 +25,25 @@ void info_string::parse(std::string buffer) {
buffer = buffer.substr(1);
}
auto key_values = string::split(buffer, '\\');
const auto key_values = string::split(buffer, '\\');
for (size_t i = 0; !key_values.empty() && i < (key_values.size() - 1);
i += 2) {
const auto& key = key_values[i];
const auto& value = key_values[i + 1];
this->key_value_pairs_[key] = value;
if (!this->key_value_pairs_.contains(key)) {
this->key_value_pairs_[key] = value;
}
}
}
std::string info_string::build() const {
std::string info_string;
for (auto i = this->key_value_pairs_.begin();
i != this->key_value_pairs_.end(); ++i) {
for (const auto& [key, value] : this->key_value_pairs_) {
info_string.append("\\");
info_string.append(i->first); // Key
info_string.append(key);
info_string.append("\\");
info_string.append(i->second); // Value
info_string.append(value);
}
return info_string;