iw4x-client/src/Utils/InfoString.cpp

67 lines
1.3 KiB
C++
Raw Normal View History

2016-07-11 11:14:58 -04:00
#include "STDInclude.hpp"
namespace Utils
{
void InfoString::set(std::string key, std::string value)
2016-07-11 11:14:58 -04:00
{
this->keyValuePairs[key] = value;
2016-07-11 11:14:58 -04:00
}
std::string InfoString::get(std::string key)
2016-07-11 11:14:58 -04:00
{
if (this->keyValuePairs.find(key) != this->keyValuePairs.end())
2016-07-11 11:14:58 -04:00
{
return this->keyValuePairs[key];
2016-07-11 11:14:58 -04:00
}
return "";
}
void InfoString::parse(std::string buffer)
2016-07-11 11:14:58 -04:00
{
if (buffer[0] == '\\')
{
buffer = buffer.substr(1);
}
std::vector<std::string> KeyValues = Utils::String::Explode(buffer, '\\');
for (unsigned int i = 0; i < (KeyValues.size() - 1); i += 2)
{
this->keyValuePairs[KeyValues[i]] = KeyValues[i + 1];
2016-07-11 11:14:58 -04:00
}
}
std::string InfoString::build()
2016-07-11 11:14:58 -04:00
{
std::string infoString;
bool first = true;
for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i)
2016-07-11 11:14:58 -04:00
{
if (first) first = false;
else infoString.append("\\");
infoString.append(i->first); // Key
infoString.append("\\");
infoString.append(i->second); // Value
}
return infoString;
}
void InfoString::dump()
2016-07-11 11:14:58 -04:00
{
for (auto i = this->keyValuePairs.begin(); i != this->keyValuePairs.end(); ++i)
2016-07-11 11:14:58 -04:00
{
OutputDebugStringA(Utils::String::VA("%s: %s", i->first.data(), i->second.data()));
}
}
json11::Json InfoString::to_json()
{
return this->keyValuePairs;
2016-07-11 11:14:58 -04:00
}
}