#include "ScalarConverter.hpp" bool ischar(const std::string& input) { return (input.length() == 1); } bool isInt(const std::string& input) { if (input.empty()) return false; size_t i = 0; if (input[0] == '+' || input[0] == '-') i = 1; if (i >= input.length()) return false; while (i < input.length()) { if (!std::isdigit(input[i])) return false; i++; } return true; } bool isFloat(const std::string& input) { if (input.empty()) return false; size_t i = 0; bool hasPoint = false; bool hasDigit = false; if (input[0] == '+' || input[0] == '-') i = 1; while (i < input.length()) { if (std::isdigit(input[i])) hasDigit = true; else if (input[i] == '.' && !hasPoint) hasPoint = true; else if (input[i] == 'f' && i == input.length() - 1 && hasDigit) return true; else return false; i++; } return (hasDigit && hasPoint); } bool isDouble(const std::string& input) { if (input.empty()) return false; size_t i = 0; bool hasPoint = false; bool hasDigit = false; if (input[0] == '+' || input[0] == '-') i = 1; while (i < input.length()) { if (std::isdigit(input[i])) hasDigit = true; else if (input[i] == '.' && !hasPoint) hasPoint = true; else return false; i++; } return (hasDigit && hasPoint); } void ScalarConverter::toChar(const std::string &input) { char c = input[0]; int i = static_cast(c); float f = static_cast(c); double d = static_cast(c); if (input.size() == 3) if (input[0] == '\'' && input[2] == '\''); c = input[1]; if (isprint(c)) std::cout << "char: \t'" << c << "'" << std::endl; else std::cout << "char: \t" << "non displayable" << std::endl; std::cout << "int: \t" << i << std::endl; std::cout << "float: \t" << std::fixed << std::setprecision(1) << f << "f" << std::endl; std::cout << "double: \t" << d << std::endl; }