mirror of
https://github.com/wesnoth/wesnoth
synced 2025-05-04 05:58:06 +00:00
lexical_cast_default<double> : useful for attack/defense weight
This commit is contained in:
parent
94dd723db4
commit
1aefd4b986
14
src/util.cpp
14
src/util.cpp
@ -66,3 +66,17 @@ int lexical_cast_default<int, const char*>(const char* a, int def)
|
||||
}
|
||||
}
|
||||
|
||||
template<>
|
||||
double lexical_cast_default<double, const std::string&>(const std::string& a, double def)
|
||||
{
|
||||
char* endptr;
|
||||
double res = strtod(a.c_str(), &endptr);
|
||||
|
||||
if (a.empty() || *endptr != '\0') {
|
||||
return def;
|
||||
} else {
|
||||
return res;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user