5 #ifndef BASE_STRING_UTIL_H__
6 #define BASE_STRING_UTIL_H__
12 #include <boost/algorithm/string.hpp>
13 #include <boost/uuid/nil_generator.hpp>
14 #include <boost/uuid/uuid.hpp>
15 #include <boost/uuid/uuid_io.hpp>
18 template <
typename NumberType>
28 inline const std::string integerToString<>(
const int8_t &
num) {
37 inline const std::string integerToString<>(
const uint8_t &
num) {
44 template <
typename NumberType>
47 ss << std::hex <<
num;
54 inline const std::string integerToHexString<>(
const int8_t &
num) {
56 ss << std::hex << (int16_t)
num;
63 inline const std::string integerToHexString<>(
const uint8_t &
num) {
65 ss << std::hex << (uint16_t)
num;
70 template <
typename NumberType>
73 num = strtoul(str.c_str(), &endptr, 10);
74 return endptr[0] ==
'\0';
77 template <
typename NumberType>
80 num = strtoull(str.c_str(), &endptr, 10);
81 return endptr[0] ==
'\0';
85 inline bool stringToInteger<>(
const std::string& str, int64_t &
num) {
90 inline bool stringToInteger<>(
const std::string& str, uint64_t &
num) {
95 inline bool stringToInteger<>(
const std::string& str,
double &
num) {
97 num = strtod(str.c_str(), &endptr);
98 return endptr[0] ==
'\0';
106 template<
typename NumberType>
108 std::string seperator,
109 std::vector<NumberType> &entries) {
110 std::vector<std::string> tokens;
112 boost::split(tokens, input, boost::is_any_of(seperator),
113 boost::token_compress_on);
115 if (!tokens.size()) {
119 std::vector<std::string>::iterator iter;
121 for (iter = tokens.begin(); iter != tokens.end(); iter++) {
122 std::stringstream ss(*iter);
132 entries.push_back(value);
140 std::stringstream uuidstring;
142 return uuidstring.str();
148 std::stringstream uuidstring(str);
162 if (in_string.compare(
"true") == 0) {
165 if (in_string.compare(
"false") == 0) {
171 #endif // BASE_STRING_UTIL_H__
static const std::string integerToHexString(const NumberType &num)
static boost::uuids::uuid StringToUuid(const std::string &str)
bool stringToInteger(const std::string &str, NumberType &num)
bool stringToLongLong(const std::string &str, NumberType &num)
static std::string UuidToString(const boost::uuids::uuid &id)
static const std::string integerToString(const NumberType &num)
static bool stringToIntegerList(std::string input, std::string seperator, std::vector< NumberType > &entries)
static bool StringToBool(const std::string &in_string)
static std::string BoolToString(const bool &val)