[Utils]: Small cleanup (#893)

This commit is contained in:
Edo 2023-04-02 21:53:45 +02:00 committed by GitHub
parent 1b16af8c68
commit 3f5db59ff1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 11 deletions

View File

@ -10,17 +10,17 @@ namespace Utils
void InfoString::set(const std::string& key, const std::string& value)
{
this->keyValuePairs[key] = value;
this->keyValuePairs_[key] = value;
}
void InfoString::remove(const std::string& key)
{
this->keyValuePairs.erase(key);
this->keyValuePairs_.erase(key);
}
std::string InfoString::get(const std::string& key) const
{
if (const auto value = this->keyValuePairs.find(key); value != this->keyValuePairs.end())
if (const auto value = this->keyValuePairs_.find(key); value != this->keyValuePairs_.end())
{
return value->second;
}
@ -35,13 +35,16 @@ namespace Utils
buffer = buffer.substr(1);
}
const auto keyValues = Utils::String::Split(buffer, '\\');
const auto keyValues = String::Split(buffer, '\\');
for (std::size_t i = 0; !keyValues.empty() && i < (keyValues.size() - 1); i += 2)
{
const auto& key = keyValues[i];
const auto& value = keyValues[i + 1];
this->keyValuePairs[key] = value;
if (!this->keyValuePairs_.contains(key))
{
this->keyValuePairs_[key] = value;
}
}
}
@ -50,8 +53,7 @@ namespace Utils
std::string infoString;
auto first = true;
for (const auto& [key, value] : this->keyValuePairs)
for (const auto& [key, value] : this->keyValuePairs_)
{
if (first) first = false;
else infoString.append("\\");
@ -67,7 +69,7 @@ namespace Utils
#ifdef _DEBUG
void InfoString::dump()
{
for (const auto& [key, value] : this->keyValuePairs)
for (const auto& [key, value] : this->keyValuePairs_)
{
OutputDebugStringA(String::VA("%s: %s\n", key.data(), value.data()));
}
@ -76,6 +78,6 @@ namespace Utils
nlohmann::json InfoString::to_json() const
{
return this->keyValuePairs;
return this->keyValuePairs_;
}
}

View File

@ -21,7 +21,8 @@ namespace Utils
[[nodiscard]] nlohmann::json to_json() const;
private:
std::unordered_map<std::string, std::string> keyValuePairs;
std::unordered_map<std::string, std::string> keyValuePairs_;
void parse(std::string buffer);
};
}