[Utils]: Small cleanup (#893)
This commit is contained in:
parent
1b16af8c68
commit
3f5db59ff1
@ -10,17 +10,17 @@ namespace Utils
|
|||||||
|
|
||||||
void InfoString::set(const std::string& key, const std::string& value)
|
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)
|
void InfoString::remove(const std::string& key)
|
||||||
{
|
{
|
||||||
this->keyValuePairs.erase(key);
|
this->keyValuePairs_.erase(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string InfoString::get(const std::string& key) const
|
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;
|
return value->second;
|
||||||
}
|
}
|
||||||
@ -35,13 +35,16 @@ namespace Utils
|
|||||||
buffer = buffer.substr(1);
|
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)
|
for (std::size_t i = 0; !keyValues.empty() && i < (keyValues.size() - 1); i += 2)
|
||||||
{
|
{
|
||||||
const auto& key = keyValues[i];
|
const auto& key = keyValues[i];
|
||||||
const auto& value = keyValues[i + 1];
|
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;
|
std::string infoString;
|
||||||
|
|
||||||
auto first = true;
|
auto first = true;
|
||||||
|
for (const auto& [key, value] : this->keyValuePairs_)
|
||||||
for (const auto& [key, value] : this->keyValuePairs)
|
|
||||||
{
|
{
|
||||||
if (first) first = false;
|
if (first) first = false;
|
||||||
else infoString.append("\\");
|
else infoString.append("\\");
|
||||||
@ -67,7 +69,7 @@ namespace Utils
|
|||||||
#ifdef _DEBUG
|
#ifdef _DEBUG
|
||||||
void InfoString::dump()
|
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()));
|
OutputDebugStringA(String::VA("%s: %s\n", key.data(), value.data()));
|
||||||
}
|
}
|
||||||
@ -76,6 +78,6 @@ namespace Utils
|
|||||||
|
|
||||||
nlohmann::json InfoString::to_json() const
|
nlohmann::json InfoString::to_json() const
|
||||||
{
|
{
|
||||||
return this->keyValuePairs;
|
return this->keyValuePairs_;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,8 @@ namespace Utils
|
|||||||
[[nodiscard]] nlohmann::json to_json() const;
|
[[nodiscard]] nlohmann::json to_json() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unordered_map<std::string, std::string> keyValuePairs;
|
std::unordered_map<std::string, std::string> keyValuePairs_;
|
||||||
|
|
||||||
void parse(std::string buffer);
|
void parse(std::string buffer);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user