From 9baaada32b7684efc2438d0346edf47144b55f00 Mon Sep 17 00:00:00 2001 From: aortigos Date: Wed, 18 Mar 2026 15:25:21 +0100 Subject: [PATCH] Converted with no debug prints and only accept 'a' format for chat --- ex00/ScalarConverter/ScalarConverter.cpp | 25 +++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ex00/ScalarConverter/ScalarConverter.cpp b/ex00/ScalarConverter/ScalarConverter.cpp index 657f11e..87e069c 100644 --- a/ex00/ScalarConverter/ScalarConverter.cpp +++ b/ex00/ScalarConverter/ScalarConverter.cpp @@ -73,19 +73,13 @@ bool ScalarConverter::isChar(const std::string &literal) { char c; - if (literal.length() == 3) + if (literal.length() != 3) + return (false); + c = literal[1]; + if (literal[0] == '\'' && literal[2] == '\'' + && (c >= 32 && c < 127)) { - 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 (true); } return (false); } @@ -128,6 +122,7 @@ bool ScalarConverter::isFloat(const std::string &literal) void ScalarConverter::convertFromSpecialCase(const std::string &literal) { + // std::cout << "---- Converting from Special case ----" << std::endl; std::cout << "char: impossible" << std::endl; std::cout << "int: impossible" << std::endl; if (literal == "nanf" || literal == "+inff" || literal == "-inff") @@ -146,8 +141,7 @@ void ScalarConverter::convertFromChar(const std::string &literal) if (literal.length() == 3) c = literal[1]; - else if (literal.length() == 1) - c = literal[0]; + // std::cout << "---- Converting from Char ----" << std::endl; std::cout << "char: '" << c << "'" << std::endl; std::cout << "int: " << static_cast(c) << std::endl; std::cout << std::fixed << std::setprecision(1); @@ -160,6 +154,7 @@ void ScalarConverter::convertFromInt(const std::string &literal) int nb; char *end; + // std::cout << "---- Converting from Int ----" << std::endl; nb = static_cast(std::strtol(literal.c_str(), &end, 10)); if (nb < 0 || nb > 127) std::cout << "char: impossible" << std::endl; @@ -178,6 +173,7 @@ void ScalarConverter::convertFromFloat(const std::string &literal) float nb; char *end; + // std::cout << "---- Converting from Float ----" << std::endl; nb = std::strtof(literal.c_str(), &end); if (nb < 0 || nb > 127) std::cout << "char: impossible" << std::endl; @@ -199,6 +195,7 @@ void ScalarConverter::convertFromDouble(const std::string &literal) double nb; char *end; + // std::cout << "---- Converting from Double ----" << std::endl; nb = std::strtod(literal.c_str(), &end); if (nb < 0 || nb > 127) std::cout << "char: impossible" << std::endl;