1#ifndef ROSE_StringUtility_StringToNumber_H
2#define ROSE_StringUtility_StringToNumber_H
4#include <Rose/StringUtility/NumberToString.h>
6#include <Rose/StringUtility/Diagnostics.h>
7#include <Rose/Exception.h>
10#include <Sawyer/Parse.h>
15namespace StringUtility {
56template<
class Container,
class Stringifier>
60template<
class Iterator,
class Stringifier>
62 std::vector<std::string> retval;
63 for (; begin!=end; ++begin)
64 retval.push_back(stringifier(*begin));
73template<
class IntegralType>
75toDigit(
char ch, IntegralType radix = 10) {
77 assert(!std::numeric_limits<IntegralType>::is_signed || radix >= 0);
79 if (ch >=
'0' && ch <=
'9') {
81 }
else if (ch >=
'a' && ch <=
'f') {
82 digit = ch -
'a' + 10;
83 }
else if (ch >=
'A' && ch <=
'F') {
84 digit = ch -
'A' + 10;
107template<
class IntegralType>
110 return Sawyer::parse<IntegralType>(s);
117template<
class IntegralType>
118typename std::enable_if<std::is_integral<IntegralType>::value, IntegralType>::type
120 return toNumber<IntegralType>(s).template orThrow<Exception>();
Shortens names of int64_t stringifiers.
Holds a value or nothing.
Result containing a value or an error.
ROSE_UTIL_API std::string numberToString(long long)
Convert an integer to a string.
std::vector< std::string > toStrings(const Container &numbers, const Stringifier &stringifier=numberToString)
Converts a bunch of numbers to strings.
std::vector< std::string > toStrings_range(Iterator begin, Iterator end, const Stringifier &stringifier=numberToString)
Converts a bunch of numbers to strings.
std::enable_if< std::is_integral< IntegralType >::value, Sawyer::Result< IntegralType, std::string > >::type toNumber(const std::string &s)
Safely convert a string to a number using C++ style syntax.
ROSE_UTIL_API unsigned hexadecimalToInt(char)
Convert an ASCII hexadecimal character to an integer.
std::enable_if< std::is_integral< IntegralType >::value, IntegralType >::type toNumberOrThrow(const std::string &s)
Safely convert a string to a number using C++ style syntax.
Sawyer::Optional< typename std::enable_if< std::is_integral< IntegralType >::value, IntegralType >::type > toDigit(char ch, IntegralType radix=10)
Convert a character to a numeric digit.