mirror of
https://github.com/GothenburgBitFactory/timewarrior.git
synced 2025-06-26 10:54:28 +02:00
Add defaultValue argument to Rules::getInteger
The defaultValue can be used for callers who do not want 0 to be returned when conversion fails since strtoimax returns 0 when the conversion fails.
This commit is contained in:
parent
6557814909
commit
c33a3a9d9a
2 changed files with 9 additions and 5 deletions
|
@ -149,13 +149,17 @@ std::string Rules::get (const std::string& key) const
|
|||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
int Rules::getInteger (const std::string& key) const
|
||||
int Rules::getInteger (const std::string& key, int defaultValue) const
|
||||
{
|
||||
auto found = _settings.find (key);
|
||||
if (found != _settings.end ())
|
||||
return strtoimax (found->second.c_str (), nullptr, 10);
|
||||
if (found != _settings.end ()) {
|
||||
int tmp = strtoimax (found->second.c_str (), nullptr, 10);
|
||||
// If conversion has performed, return the conversion.
|
||||
if (tmp != 0)
|
||||
return tmp;
|
||||
}
|
||||
|
||||
return 0;
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue