diff --git a/inferno/src/inferno/render/font.cpp b/inferno/src/inferno/render/font.cpp index 4038a0b..f42f8a5 100644 --- a/inferno/src/inferno/render/font.cpp +++ b/inferno/src/inferno/render/font.cpp @@ -1,11 +1,11 @@ #include // std::numeric_limits -#include // std::getline +#include // std::getline, std::stoi #include "inferno/assert.h" #include "inferno/io/file.h" #include "inferno/render/font.h" #include "inferno/render/texture.h" -#include "inferno/util/string.h" +#include "inferno/util/integer.h" namespace Inferno { diff --git a/inferno/src/inferno/util/integer.h b/inferno/src/inferno/util/integer.h new file mode 100644 index 0000000..7df8e70 --- /dev/null +++ b/inferno/src/inferno/util/integer.h @@ -0,0 +1,27 @@ +#ifndef INTEGER_UTIL_H +#define INTEGER_UTIL_H + +#include // std::numeric_limits +#include // std::string, std::stoul + +#include "inferno/assert.h" + +namespace std { + + // Can't believe this is not in the standard library + + inline uint32_t stou(const std::string& string) + { + unsigned long size = std::stoul(string); + ASSERT(size <= std::numeric_limits::max(), "String util not in uint32_t range '{}'", string); + return static_cast(size); + } + + inline uint32_t stou(const char* string) + { + return stou(std::string(string)); + } + +} // namespace std + +#endif // INTEGER_UTIL_H diff --git a/inferno/src/inferno/util/string.h b/inferno/src/inferno/util/string.h index 0b1a24d..2dd0c40 100644 --- a/inferno/src/inferno/util/string.h +++ b/inferno/src/inferno/util/string.h @@ -1,27 +1,22 @@ -#ifndef UTIL_STRING_H -#define UTIL_STRING_H +#ifndef STRING_UTIL_H +#define STRING_UTIL_H -#include // std::numeric_limits -#include // std::string, std::stoul +#include // std::setfill, std::setw +#include // std::stringstream -#include "inferno/assert.h" +namespace Inferno { -namespace std { - - // Can't believe this is not in the standard library - - inline uint32_t stou(const std::string& string) + template + std::string intToHex(T i) { - unsigned long size = std::stoul(string); - ASSERT(size <= std::numeric_limits::max(), "String util not in uint32_t range '{}'", string); - return static_cast(size); - } + std::stringstream stream; + stream << "0x" + << std::setfill('0') << std::setw(sizeof(T) * 2) + << std::hex << i; - inline uint32_t stou(const char* string) - { - return stou(std::string(string)); + return stream.str(); } -} // namespace std +} // namespace Inferno -#endif // UTIL_STRING_H +#endif // STRING_UTIL_H