Browse Source

improved handling of commas in fast_atof

Léo Terziman 10 years ago
parent
commit
18e6a8fbdb
1 changed files with 2 additions and 2 deletions
  1. 2 2
      code/fast_atof.h

+ 2 - 2
code/fast_atof.h

@@ -260,14 +260,14 @@ inline const char* fast_atoreal_move(const char* c, Real& out, bool check_comma
 	}
 	}
 
 
 	if (!(c[0] >= '0' && c[0] <= '9') &&
 	if (!(c[0] >= '0' && c[0] <= '9') &&
-	    !(c[0] == '.' && c[1] >= '0' && c[1] <= '9'))
+	    !((c[0] == '.' || (check_comma && c[0] == ',')) && c[1] >= '0' && c[1] <= '9'))
 	{
 	{
 		throw std::invalid_argument("Cannot parse string "
 		throw std::invalid_argument("Cannot parse string "
 		                            "as real number: does not start with digit "
 		                            "as real number: does not start with digit "
 		                            "or decimal point followed by digit.");
 		                            "or decimal point followed by digit.");
 	}
 	}
 
 
-	if (*c != '.')
+	if (*c != '.' && (! check_comma || c[0] != ','))
 	{
 	{
 		f = static_cast<Real>( strtoul10_64 ( c, &c) );
 		f = static_cast<Real>( strtoul10_64 ( c, &c) );
 	}
 	}