6 #ifndef BASE_STRING_UTIL_H__
7 #define BASE_STRING_UTIL_H__
13 #include <boost/algorithm/string.hpp>
14 #include <boost/uuid/nil_generator.hpp>
15 #include <boost/uuid/uuid.hpp>
16 #include <boost/uuid/uuid_io.hpp>
19 template <
typename NumberType>
29 inline const std::string integerToString<>(
const int8_t &
num) {
38 inline const std::string integerToString<>(
const uint8_t &
num) {
45 template <
typename NumberType>
48 ss << std::hex <<
num;
55 inline const std::string integerToHexString<>(
const int8_t &
num) {
57 ss << std::hex << (int16_t)
num;
64 inline const std::string integerToHexString<>(
const uint8_t &
num) {
66 ss << std::hex << (uint16_t)
num;
71 template <
typename NumberType>
74 num = strtoul(str.c_str(), &endptr, 10);
75 return endptr[0] ==
'\0';
78 template <
typename NumberType>
81 num = strtoull(str.c_str(), &endptr, 10);
82 return endptr[0] ==
'\0';
86 inline bool stringToInteger<>(
const std::string& str, int64_t &
num) {
91 inline bool stringToInteger<>(
const std::string& str, uint64_t &
num) {
96 inline bool stringToInteger<>(
const std::string& str,
double &
num) {
98 num = strtod(str.c_str(), &endptr);
99 return endptr[0] ==
'\0';
107 template<
typename NumberType>
109 std::string seperator,
110 std::vector<NumberType> &entries) {
111 std::vector<std::string> tokens;
113 boost::split(tokens, input, boost::is_any_of(seperator),
114 boost::token_compress_on);
116 if (!tokens.size()) {
120 std::vector<std::string>::iterator iter;
122 for (iter = tokens.begin(); iter != tokens.end(); iter++) {
123 std::stringstream ss(*iter);
133 entries.push_back(value);
141 std::stringstream uuidstring;
143 return uuidstring.str();
149 std::stringstream uuidstring(str);
163 if (in_string.compare(
"true") == 0) {
166 if (in_string.compare(
"false") == 0) {
bool stringToInteger(const std::string &str, NumberType &num)
static boost::uuids::uuid StringToUuid(const std::string &str)
static std::string BoolToString(const bool &val)
static bool stringToIntegerList(std::string input, std::string seperator, std::vector< NumberType > &entries)
bool stringToLongLong(const std::string &str, NumberType &num)
static bool StringToBool(const std::string &in_string)
static std::string UuidToString(const boost::uuids::uuid &id)
static const std::string integerToString(const NumberType &num)
static const std::string integerToHexString(const NumberType &num)