Fixed char without quotes
This commit is contained in:
@@ -49,12 +49,12 @@ void ScalarConverter::convert(const std::string &literal)
|
||||
convertFromSpecialCase(literal);
|
||||
else if (isChar(literal))
|
||||
convertFromChar(literal);
|
||||
else if(isInt(literal))
|
||||
convertFromInt(literal);
|
||||
else if(isFloat(literal))
|
||||
convertFromFloat(literal);
|
||||
else if (isDouble(literal))
|
||||
convertFromDouble(literal);
|
||||
else if(isInt(literal))
|
||||
convertFromInt(literal);
|
||||
else
|
||||
std::cout << "Error: invalid literal" << std::endl;
|
||||
}
|
||||
@@ -73,14 +73,20 @@ bool ScalarConverter::isChar(const std::string &literal)
|
||||
{
|
||||
char c;
|
||||
|
||||
if (literal.length() != 3)
|
||||
return (false);
|
||||
if (literal.length() == 3)
|
||||
{
|
||||
c = literal[1];
|
||||
if (literal[0] == '\'' && literal[2] == '\''
|
||||
&& (c >= 32 && c < 127))
|
||||
{
|
||||
return (true);
|
||||
}
|
||||
} else if (literal.length() == 1)
|
||||
{
|
||||
c = literal[0];
|
||||
if (c >= 32 && c < 127 && !std::isdigit(c))
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
@@ -101,6 +107,8 @@ bool ScalarConverter::isDouble(const std::string &literal)
|
||||
{
|
||||
char *end;
|
||||
|
||||
if (literal.find('.') == std::string::npos)
|
||||
return (false);
|
||||
strtod(literal.c_str(), &end);
|
||||
if (*end != '\0')
|
||||
return (false);
|
||||
@@ -134,9 +142,12 @@ void ScalarConverter::convertFromSpecialCase(const std::string &literal)
|
||||
|
||||
void ScalarConverter::convertFromChar(const std::string &literal)
|
||||
{
|
||||
char c;
|
||||
char c = 0;
|
||||
|
||||
if (literal.length() == 3)
|
||||
c = literal[1];
|
||||
else if (literal.length() == 1)
|
||||
c = literal[0];
|
||||
std::cout << "char: '" << c << "'" << std::endl;
|
||||
std::cout << "int: " << static_cast<int>(c) << std::endl;
|
||||
std::cout << std::fixed << std::setprecision(1);
|
||||
|
||||
Reference in New Issue
Block a user