41#include <boost/spirit/include/qi_parse.hpp>
42#include <boost/spirit/include/qi_numeric.hpp>
47 template <
typename CharT,
typename Traits>
48 inline int32_t
string_to_int32(
const std::basic_string_view<CharT, Traits>& aStringView)
50 namespace qi = boost::spirit::qi;
52 qi::parse(aStringView.begin(), aStringView.end(), qi::int_, result);
56 template <
typename CharT,
typename Traits,
typename Alloc>
57 inline int32_t
string_to_int32(
const std::basic_string<CharT, Traits, Alloc>& aString,
int aBase = 10)
60 string_to_int32(
static_cast<std::basic_string_view<CharT, Traits>
>(aString));
61 return strtol(aString.c_str(),
nullptr, aBase);
64 template <
typename CharT,
typename Traits>
65 inline int64_t
string_to_int64(
const std::basic_string_view<CharT, Traits>& aStringView)
67 namespace qi = boost::spirit::qi;
69 qi::parse(aStringView.begin(), aStringView.end(), qi::long_long, result);
73 template <
typename CharT,
typename Traits,
typename Alloc>
74 inline int64_t
string_to_int64(
const std::basic_string<CharT, Traits, Alloc>& aString,
int aBase = 10)
77 return string_to_int64(
static_cast<std::basic_string_view<CharT, Traits>
>(aString));
78 return strtoll(aString.c_str(),
nullptr, aBase);
81 template <
typename CharT,
typename Traits>
82 inline uint32_t
string_to_uint32(
const std::basic_string_view<CharT, Traits>& aStringView)
84 namespace qi = boost::spirit::qi;
86 qi::parse(aStringView.begin(), aStringView.end(), qi::uint_, result);
90 template <
typename CharT,
typename Traits,
typename Alloc>
91 inline uint32_t
string_to_uint32(
const std::basic_string<CharT, Traits, Alloc>& aString,
int aBase = 10)
94 return string_to_uint32(
static_cast<std::basic_string_view<CharT, Traits>
>(aString));
95 return strtoul(aString.c_str(), 0, aBase);
98 template <
typename CharT,
typename Traits>
99 inline uint64_t
string_to_uint64(
const std::basic_string_view<CharT, Traits>& aStringView)
101 namespace qi = boost::spirit::qi;
102 uint64_t result = 0ull;
103 qi::parse(aStringView.begin(), aStringView.end(), qi::ulong_long, result);
107 template <
typename CharT,
typename Traits,
typename Alloc>
108 inline uint64_t
string_to_uint64(
const std::basic_string<CharT, Traits, Alloc>& aString,
int aBase = 10)
111 return string_to_uint64(
static_cast<std::basic_string_view<CharT, Traits>
>(aString));
112 return strtoull(aString.c_str(), 0, aBase);
119 template <
typename CharT,
typename Traits>
122 namespace qi = boost::spirit::qi;
125 if (qi::parse(aStringView.begin(), aStringView.end(), qi::int_, result))
129 uint32_t result = 0u;
130 if (qi::parse(aStringView.begin(), aStringView.end(), qi::uint_, result))
134 int64_t result = 0ll;
135 if (qi::parse(aStringView.begin(), aStringView.end(), qi::long_long, result))
139 uint64_t result = 0ull;
140 if (qi::parse(aStringView.begin(), aStringView.end(), qi::ulong_long, result))
145 if (qi::parse(aStringView.begin(), aStringView.end(), qi::double_, result))
151 template <
typename CharT,
typename Traits>
154 namespace qi = boost::spirit::qi;
156 qi::parse(aStringView.begin(), aStringView.end(), qi::double_, result);
160 template <
typename CharT,
typename Traits,
typename Alloc>
163 return string_to_double(
static_cast<std::basic_string_view<CharT, Traits>
>(aString));
166 template <
typename CharT,
typename Traits = std::
char_traits<CharT>,
typename Alloc = std::allocator<CharT>>
167 inline std::basic_string<CharT, Traits, Alloc>
int32_to_string(int32_t aint32,
int aBase = 10, std::size_t aWidth = 0, CharT aFill =
'0')
169 std::basic_stringstream<CharT, Traits, Alloc>
string;
171 string << std::hex << std::uppercase;
174 string.width(aWidth);
181 template <
typename CharT,
typename Traits = std::
char_traits<CharT>,
typename Alloc = std::allocator<CharT>>
182 inline std::basic_string<CharT, Traits, Alloc>
int64_to_string(int64_t aint32,
int aBase = 10, std::size_t aWidth = 0, CharT aFill =
'0')
184 std::basic_stringstream<CharT, Traits, Alloc>
string;
191 string << std::hex << std::uppercase;
196 string.width(aWidth);
203 template <
typename CharT,
typename Traits = std::
char_traits<CharT>,
typename Alloc = std::allocator<CharT>>
204 inline std::basic_string<CharT, Traits, Alloc>
uint32_to_string(uint32_t aint32,
int aBase = 10, std::size_t aWidth = 0, CharT aFill =
'0')
206 std::basic_stringstream<CharT, Traits, Alloc>
string;
208 string << std::hex << std::uppercase;
211 string.width(aWidth);
218 template <
typename CharT,
typename Traits = std::
char_traits<CharT>,
typename Alloc = std::allocator<CharT>>
219 inline std::basic_string<CharT, Traits, Alloc>
uint64_to_string(uint64_t aint32,
int aBase = 10, std::size_t aWidth = 0, CharT aFill =
'0')
221 std::basic_stringstream<CharT, Traits, Alloc>
string;
223 string << std::hex << std::uppercase;
226 string.width(aWidth);
233 template <
typename CharT,
typename Traits = std::
char_traits<CharT>,
typename Alloc = std::allocator<CharT>>
234 inline std::basic_string<CharT, Traits, Alloc>
double_to_string(
double aDouble, std::size_t aPrecision = 0,
bool aFixed =
true, std::size_t aWidth = 0, CharT aFill =
'0')
236 std::basic_stringstream<CharT, Traits, Alloc>
string;
238 string.precision(aPrecision);
240 string << std::fixed;
242 string << std::scientific;
245 string.width(aWidth);
int32_t string_to_int32(const std::basic_string_view< CharT, Traits > &aStringView)
uint64_t string_to_uint64(const std::basic_string_view< CharT, Traits > &aStringView)
number_t string_to_number(const std::basic_string_view< CharT, Traits > &aStringView)
std::basic_string< CharT, Traits, Alloc > uint32_to_string(uint32_t aint32, int aBase=10, std::size_t aWidth=0, CharT aFill='0')
variant< double, int32_t, uint32_t, int64_t, uint64_t > number_t
int64_t string_to_int64(const std::basic_string_view< CharT, Traits > &aStringView)
std::basic_string< CharT, Traits, Alloc > double_to_string(double aDouble, std::size_t aPrecision=0, bool aFixed=true, std::size_t aWidth=0, CharT aFill='0')
uint32_t string_to_uint32(const std::basic_string_view< CharT, Traits > &aStringView)
std::basic_string< CharT, Traits, Alloc > int32_to_string(int32_t aint32, int aBase=10, std::size_t aWidth=0, CharT aFill='0')
std::basic_string< CharT, Traits, Alloc > uint64_to_string(uint64_t aint32, int aBase=10, std::size_t aWidth=0, CharT aFill='0')
std::basic_string< CharT, Traits, Alloc > int64_to_string(int64_t aint32, int aBase=10, std::size_t aWidth=0, CharT aFill='0')
double string_to_double(const std::basic_string_view< CharT, Traits > &aStringView)
string_to_number_failure()