ascii_to() utility for boolean values

Also, Genode::Arg was adapted to use the new utility for boolean tokens
and strings.

Issue #1648
This commit is contained in:
Emery Hemingway
2015-08-28 14:42:22 +02:00
committed by Christian Helmuth
parent ce354d6fd9
commit df0bbe0b0e
2 changed files with 33 additions and 21 deletions

View File

@@ -309,6 +309,24 @@ namespace Genode {
}
/**
* Read boolean value from string
*
* \return number of consumed characters
*/
inline size_t ascii_to(char const *s, bool &result)
{
if (!strcmp(s, "yes", 3)) { result = true; return 3; }
if (!strcmp(s, "true", 4)) { result = true; return 4; }
if (!strcmp(s, "on", 2)) { result = true; return 2; }
if (!strcmp(s, "no", 2)) { result = false; return 2; }
if (!strcmp(s, "false", 5)) { result = false; return 5; }
if (!strcmp(s, "off", 3)) { result = false; return 3; }
return 0;
}
/**
* Read unsigned long value from string
*