aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-06-30 23:47:04 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-06-30 23:47:04 -0700
commitedcdec855e90b01dafc6248a79b1275da8069c38 (patch)
treee3f2cabeda492347c45c940d84366762b0a9493e
parentb57bf0b772c5cfef789363b9951f737d9e92a28a (diff)
Refactoring
Extracted IsCharacterInSet function
-rw-r--r--src/Uri.cpp47
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;