Move Config ValueToString to StringUtil

An identical implementation is used by IniFile, so move those functions
to StringUtil. A future commit will modify IniFile to use them.
This commit is contained in:
Léo Lam
2018-06-03 14:10:52 +02:00
parent 66ee47c417
commit fc0193c4b1
6 changed files with 61 additions and 57 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included.
#include <algorithm>
#include <cinttypes>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
@ -291,11 +292,51 @@ bool TryParse(const std::string& str, bool* const output)
return true;
}
std::string StringFromBool(bool value)
std::string ValueToString(u16 value)
{
return StringFromFormat("0x%04x", value);
}
std::string ValueToString(u32 value)
{
return StringFromFormat("0x%08x", value);
}
std::string ValueToString(u64 value)
{
return StringFromFormat("0x%016" PRIx64, value);
}
std::string ValueToString(float value)
{
return StringFromFormat("%#.9g", value);
}
std::string ValueToString(double value)
{
return StringFromFormat("%#.17g", value);
}
std::string ValueToString(int value)
{
return std::to_string(value);
}
std::string ValueToString(s64 value)
{
return StringFromFormat("%" PRId64, value);
}
std::string ValueToString(bool value)
{
return value ? "True" : "False";
}
std::string ValueToString(const std::string& value)
{
return value;
}
bool SplitPath(const std::string& full_path, std::string* _pPath, std::string* _pFilename,
std::string* _pExtension)
{