Util: use case-insensitive matching for parsing bool values
This commit is contained in:
parent
ae10442cf2
commit
e15e893a01
2 changed files with 7 additions and 5 deletions
|
|
@ -99,8 +99,8 @@ namespace util {
|
|||
|
||||
|
||||
namespace {
|
||||
regex trueTokens{ "\\s*(true|True|TRUE|yes|Yes|YES|1|\\+)\\s*", regex::ECMAScript | regex::optimize};
|
||||
regex falseTokens{"\\s*(false|False|FALSE|no|No|NO|0|\\-)\\s*", regex::ECMAScript | regex::optimize};
|
||||
regex trueTokens { "\\s*(true|yes|on|1|\\+)\\s*", regex::icase | regex::optimize };
|
||||
regex falseTokens{ "\\s*(false|no|off|0|\\-)\\s*", regex::icase | regex::optimize };
|
||||
}
|
||||
|
||||
bool
|
||||
|
|
|
|||
|
|
@ -47,6 +47,7 @@ namespace test {
|
|||
CHECK (boolVal ("true"));
|
||||
CHECK (boolVal ("True"));
|
||||
CHECK (boolVal ("TRUE"));
|
||||
CHECK (boolVal ("tRuE"));
|
||||
CHECK (boolVal ("yes"));
|
||||
CHECK (boolVal ("Yes"));
|
||||
CHECK (boolVal ("YES"));
|
||||
|
|
@ -56,6 +57,7 @@ namespace test {
|
|||
CHECK (not boolVal ("false"));
|
||||
CHECK (not boolVal ("False"));
|
||||
CHECK (not boolVal ("FALSE"));
|
||||
CHECK (not boolVal ("fAlSe"));
|
||||
CHECK (not boolVal ("no"));
|
||||
CHECK (not boolVal ("No"));
|
||||
CHECK (not boolVal ("NO"));
|
||||
|
|
@ -69,8 +71,8 @@ namespace test {
|
|||
|
||||
VERIFY_ERROR (INVALID, boolVal("") );
|
||||
VERIFY_ERROR (INVALID, boolVal(" ") );
|
||||
VERIFY_ERROR (INVALID, boolVal("yEs") );
|
||||
VERIFY_ERROR (INVALID, boolVal("tRuE") );
|
||||
VERIFY_ERROR (INVALID, boolVal("Ja") );
|
||||
VERIFY_ERROR (INVALID, boolVal("truth") );
|
||||
VERIFY_ERROR (INVALID, boolVal("falsehood"));
|
||||
VERIFY_ERROR (INVALID, boolVal("11") );
|
||||
VERIFY_ERROR (INVALID, boolVal("+1") );
|
||||
|
|
@ -79,6 +81,7 @@ namespace test {
|
|||
|
||||
CHECK (isYes ("true"));
|
||||
CHECK (isYes ("True"));
|
||||
CHECK (isYes ("tRuE"));
|
||||
CHECK (isYes ("TRUE"));
|
||||
CHECK (isYes ("yes"));
|
||||
CHECK (isYes ("Yes"));
|
||||
|
|
@ -89,7 +92,6 @@ namespace test {
|
|||
CHECK (isYes (" \n\n 1 \t "));
|
||||
|
||||
CHECK (not isYes (" True and False"));
|
||||
CHECK (not isYes ("tRuE"));
|
||||
CHECK (not isYes ("+2"));
|
||||
CHECK (not isYes ("no"));
|
||||
CHECK (not isYes ("1010"));
|
||||
|
|
|
|||
Loading…
Reference in a new issue