MT#64469 AmUtils: fix str2int (double) helper

It's been noticed actually no result is written
by the reference given to a funciton helper.

Also it's not convenient with a rest of other
helpers, which return either true/false
on successfull or failed conversion, but just
directly return the result of atof() as a bool,
which is a mistake.

Also add a comment to a function declaration.

Change-Id: I4f18ce527638a3575ef7446a549650a951a0b583
mr26.0
Donat Zenichev 6 months ago
parent d1553a761e
commit d800d8f00e

@ -269,8 +269,27 @@ bool str2int(const string& str, int& result)
bool str2int(const string& str, double& result)
{
char* s = (char*)str.c_str();
return atof(s);
try
{
size_t pos;
result = std::stod(str, &pos);
/* check whether the whole stirng was converted */
if (pos != str.length())
return false;
return true;
}
catch (const std::invalid_argument)
{
return false;
}
catch (const std::out_of_range)
{
return false;
}
return false;
}
bool str2int(char*& str, int& result, char sep)

@ -143,6 +143,12 @@ bool str2int(char*& str, unsigned int& result, char sep = ' ');
*/
bool str2int(const string& str, int& result);
/**
* Convert a string to the double.
* @param str [in] string to convert.
* @param result [out] result integer.
* @return true on success
*/
bool str2int(const string& str, double& result);
/**

Loading…
Cancel
Save