29ScalarConverter::ScalarConverter() {}
30ScalarConverter::ScalarConverter(
const ScalarConverter &src) { (void)src; }
35ScalarConverter::~ScalarConverter() {}
42static bool isPseudoLiteral(
const std::string &literal) {
43 const std::string pseudoLiterals[] = {
"nan",
"nanf",
"+inf",
"+inff",
"-inf",
"-inff"};
44 for (
size_t i = 0; i <
sizeof(pseudoLiterals) /
sizeof(
std::string); ++i) {
45 if (literal == pseudoLiterals[i]) {
56static void printPseudoLiterals(
const std::string &literal) {
59 if (literal ==
"nan" || literal ==
"nanf") {
62 }
else if (literal ==
"+inf" || literal ==
"+inff" || literal ==
"inf" || literal ==
"inff") {
65 }
else if (literal ==
"-inf" || literal ==
"-inff") {
77static void printConversions(
double d) {
83 }
else if (!std::isprint(
static_cast<char>(d))) {
99 float f =
static_cast<float>(d);
105 if (float_str.
find(
'.') == std::string::npos && float_str.
find(
'e') == std::string::npos &&
std::isfinite(f)) {
116 if (double_str.
find(
'.') == std::string::npos && double_str.
find(
'e') == std::string::npos &&
std::isfinite(d)) {
178 if (literal.
empty()) {
184 if (isPseudoLiteral(literal)) {
185 printPseudoLiterals(literal);
190 if (literal.
length() == 3 && literal[0] ==
'\'' && literal[2] ==
'\'') {
193 printConversions(
static_cast<double>(c));
199 double d = strtod(literal.
c_str(), &endptr);
202 if (endptr == literal.
c_str() || (*endptr !=
'\0' && (*endptr !=
'f' || *(endptr + 1) !=
'\0'))) {
Contains the declaration of the ScalarConverter static class.
A static class to convert string literals to scalar types.
static void convert(const std::string &literal)
The main conversion method.