diff options
Diffstat (limited to 'src/Uri.cpp')
-rw-r--r-- | src/Uri.cpp | 47 |
1 files changed, 23 insertions, 24 deletions
diff --git a/src/Uri.cpp b/src/Uri.cpp index da1b9f8..5c4002d 100644 --- a/src/Uri.cpp +++ b/src/Uri.cpp @@ -80,6 +80,27 @@ namespace { return !stillPassing(' ', true); } + bool IsCharacterInSet( + char c, + std::initializer_list< char > characterSet + ) { + for ( + auto charInSet = characterSet.begin(); + charInSet != characterSet.end(); + ++charInSet + ) { + const auto first = *charInSet++; + const auto last = *charInSet; + if ( + (c >= first) + && (c <= last) + ) { + return true; + } + } + return false; + } + /** * This function returns a strategy function that * may be used with the FailsMatch function to test a scheme @@ -98,31 +119,9 @@ namespace { } else { bool check; if (*isFirstCharacter) { - check = ( - ( - (c >= 'a') - && (c <= 'z') - ) || ( - (c >= 'A') - && (c <= 'Z') - ) - ); + check = IsCharacterInSet(c, { 'a','z', 'A','Z' }); } else { - check = ( - ( - (c >= 'a') - && (c <= 'z') - ) || ( - (c >= 'A') - && (c <= 'Z') - ) || ( - (c >= '0') - && (c <= '9') - ) - || (c == '+') - || (c == '-') - || (c == '.') - ); + check = IsCharacterInSet(c, { 'a','z', 'A','Z', '0','9', '+','+', '-','-', '.','.' }); } *isFirstCharacter = false; return check; |