Don't use FromString for integers

feature/19
Daniel Warner 2014-03-08 18:39:32 +00:00
parent a10a6a89f0
commit 956b670b0a
1 changed files with 6 additions and 7 deletions

View File

@ -168,15 +168,15 @@ bool Tle::IsValidLineLength(const std::string& str)
*/ */
void Tle::ExtractInteger(const std::string& str, unsigned int& val) void Tle::ExtractInteger(const std::string& str, unsigned int& val)
{ {
std::string temp;
bool found_digit = false; bool found_digit = false;
unsigned int temp = 0;
for (std::string::const_iterator i = str.begin(); i != str.end(); ++i) for (std::string::const_iterator i = str.begin(); i != str.end(); ++i)
{ {
if (isdigit(*i)) if (isdigit(*i))
{ {
found_digit = true; found_digit = true;
temp += *i; temp = (temp * 10) + (*i - '0');
} }
else if (found_digit) else if (found_digit)
{ {
@ -188,14 +188,13 @@ void Tle::ExtractInteger(const std::string& str, unsigned int& val)
} }
} }
if (temp.length() == 0) if (!found_digit)
{ {
temp += '0'; val = 0;
} }
else
if (!Util::FromString<unsigned int>(temp, val))
{ {
throw TleException("Failed to convert value to integer"); val = temp;
} }
} }