mirror of
https://github.com/micsthepick/dsi2key.git
synced 2025-06-18 16:55:33 -04:00
39 lines
682 B
C++
39 lines
682 B
C++
#include "misc.h"
|
|
#include <sstream> // std::stringstream
|
|
#include <algorithm> // std::min, std::max
|
|
|
|
namespace D2K {
|
|
|
|
std::string ltos(long i)
|
|
{
|
|
std::stringstream stream;
|
|
stream << i;
|
|
|
|
return stream.str();
|
|
}
|
|
|
|
const char* ltoa(long t)
|
|
{
|
|
return ltos(t).c_str();
|
|
}
|
|
|
|
long stol(const std::string& str)
|
|
{
|
|
std::stringstream stream(str);
|
|
long return_value;
|
|
|
|
return !(stream >> return_value) ? 0L : return_value;
|
|
}
|
|
|
|
uint8_t string_to_uint8_t(const std::string& str)
|
|
{
|
|
return (uint8_t)D2K::clamp(D2K::stol(str), 0L, (long)UINT8_MAX);
|
|
}
|
|
|
|
uint16_t string_to_uint16_t(const std::string& str)
|
|
{
|
|
return (uint16_t)D2K::clamp(D2K::stol(str), 0L, (long)UINT16_MAX);
|
|
}
|
|
|
|
} // namespace D2K
|