2022-02-27 07:53:44 -05:00
|
|
|
#include <STDInclude.hpp>
|
2017-01-19 16:23:59 -05:00
|
|
|
|
|
|
|
namespace Utils
|
|
|
|
{
|
2018-12-17 08:29:18 -05:00
|
|
|
void InfoString::set(const std::string& key, const std::string& value)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
this->keyValuePairs[key] = value;
|
|
|
|
}
|
|
|
|
|
2018-12-17 08:29:18 -05:00
|
|
|
std::string InfoString::get(const std::string& key)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-02-26 17:50:53 -05:00
|
|
|
const auto value = this->keyValuePairs.find(key);
|
|
|
|
if (value != this->keyValuePairs.end())
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-02-26 17:50:53 -05:00
|
|
|
return value->second;
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return "";
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfoString::parse(std::string buffer)
|
|
|
|
{
|
|
|
|
if (buffer[0] == '\\')
|
|
|
|
{
|
|
|
|
buffer = buffer.substr(1);
|
|
|
|
}
|
|
|
|
|
2022-02-26 17:50:53 -05:00
|
|
|
auto KeyValues = Utils::String::Split(buffer, '\\');
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-02-26 17:50:53 -05:00
|
|
|
for (size_t i = 0; !KeyValues.empty() && i < (KeyValues.size() - 1); i += 2)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-02-26 17:50:53 -05:00
|
|
|
const auto& key = KeyValues[i];
|
|
|
|
const auto& value = KeyValues[i + 1];
|
|
|
|
this->keyValuePairs[key] = value;
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string InfoString::build()
|
|
|
|
{
|
|
|
|
std::string infoString;
|
|
|
|
|
2022-02-26 17:50:53 -05:00
|
|
|
auto first = true;
|
2017-01-19 16:23:59 -05:00
|
|
|
|
2022-02-26 17:50:53 -05:00
|
|
|
for (const auto& [key, value] : this->keyValuePairs)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
|
|
|
if (first) first = false;
|
|
|
|
else infoString.append("\\");
|
|
|
|
|
2022-02-26 17:50:53 -05:00
|
|
|
infoString.append(key);
|
2017-01-19 16:23:59 -05:00
|
|
|
infoString.append("\\");
|
2022-02-26 17:50:53 -05:00
|
|
|
infoString.append(value);
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return infoString;
|
|
|
|
}
|
|
|
|
|
|
|
|
void InfoString::dump()
|
|
|
|
{
|
2022-02-26 17:50:53 -05:00
|
|
|
for (const auto& [key, value] : this->keyValuePairs)
|
2017-01-19 16:23:59 -05:00
|
|
|
{
|
2022-02-26 17:50:53 -05:00
|
|
|
OutputDebugStringA(Utils::String::VA("%s: %s\n", key.data(), value.data()));
|
2017-01-19 16:23:59 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
json11::Json InfoString::to_json()
|
|
|
|
{
|
|
|
|
return this->keyValuePairs;
|
|
|
|
}
|
|
|
|
}
|