d06 ex00 all checks are ok

This commit is contained in:
hugogogo
2022-03-07 22:30:41 +01:00
parent 142687283e
commit 4ee3ae3e7d
10 changed files with 234 additions and 73 deletions

View File

@@ -1,23 +1,43 @@
#include <iostream>
#include <string>
#include <cctype> // isdigit()
#include "color.h"
#include "convert.h"
//Char toChar(str) {
//
//}
bool isFloat(std::string str) {
if (str.length() == 4)
size_t l;
// std::string float_xtrem = MAX_FLOAT;
if (str[0] == '+' || str[0] == '-')
str.erase(str.begin());
// if (str.length() == 0 || str.length() > FLOAT_MAX_LENGTH)
if (str.length() == 0)
return false;
if (!str.compare("inff") || !str.compare("nanf"))
return true;
return false;
l = str.find_first_not_of("0123456789");
if (l == std::string::npos || str[l] != '.')
return false;
str.erase(0,l + 1);
l = str.find_first_not_of("0123456789");
if (l == std::string::npos || str[l] != 'f')
return false;
// to work, one should check the decimal and the integer part
// str.erase(str.end() - 1);
// if (str.length() < FLOAT_MAX_LENGTH)
// return true;
// if (str.compare(float_xtrem) > 0)
// return false;
return true;
}
bool checkFloat(std::string str) {
// float f;
std::cout << "in char\n";
std::cout << "float\n";
if (!isFloat(str))
return false;