aboutsummaryrefslogtreecommitdiff
path: root/src/PercentEncodedCharacterDecoder.cpp
diff options
context:
space:
mode:
authorRichard Walters <rwalters@digitalstirling.com>2018-07-01 16:58:37 -0700
committerRichard Walters <rwalters@digitalstirling.com>2018-07-01 16:58:37 -0700
commit16b5c56c4ecbbb5c6153f9e16228a8d8cf95c50d (patch)
tree9bf5689b45b08c4d6a9319651a6ca80e4f7830c6 /src/PercentEncodedCharacterDecoder.cpp
parentcdc3f449812d0d45a3ea271636d669eb05ba3751 (diff)
Refactoring
Added CharacterSet as a class to represent character sets, allowing us to build singletons and composite character sets more concisely.
Diffstat (limited to 'src/PercentEncodedCharacterDecoder.cpp')
-rw-r--r--src/PercentEncodedCharacterDecoder.cpp23
1 files changed, 19 insertions, 4 deletions
diff --git a/src/PercentEncodedCharacterDecoder.cpp b/src/PercentEncodedCharacterDecoder.cpp
index d3bc0d9..890d392 100644
--- a/src/PercentEncodedCharacterDecoder.cpp
+++ b/src/PercentEncodedCharacterDecoder.cpp
@@ -10,6 +10,21 @@
#include "IsCharacterInSet.hpp"
#include "PercentEncodedCharacterDecoder.hpp"
+namespace {
+
+ /**
+ * This is the character set containing just numbers.
+ */
+ const Uri::CharacterSet DIGIT('0', '9');
+
+ /**
+ * This is the character set containing just the upper-case
+ * letters 'A' through 'F', used in upper-case hexadecimal.
+ */
+ const Uri::CharacterSet HEX('A', 'F');
+
+}
+
namespace Uri {
struct PercentEncodedCharacterDecoder::Impl {
@@ -41,9 +56,9 @@ namespace Uri {
case 0: { // % ...
impl_->decoderState = 1;
impl_->decodedCharacter <<= 4;
- if (IsCharacterInSet(c, {'0','9'})) {
+ if (IsCharacterInSet(c, DIGIT)) {
impl_->decodedCharacter += (int)(c - '0');
- } else if (IsCharacterInSet(c, {'A','F'})) {
+ } else if (IsCharacterInSet(c, HEX)) {
impl_->decodedCharacter += (int)(c - 'A') + 10;
} else {
return false;
@@ -53,9 +68,9 @@ namespace Uri {
case 1: { // %[0-9A-F] ...
impl_->decoderState = 2;
impl_->decodedCharacter <<= 4;
- if (IsCharacterInSet(c, {'0','9'})) {
+ if (IsCharacterInSet(c, DIGIT)) {
impl_->decodedCharacter += (int)(c - '0');
- } else if (IsCharacterInSet(c, {'A','F'})) {
+ } else if (IsCharacterInSet(c, HEX)) {
impl_->decodedCharacter += (int)(c - 'A') + 10;
} else {
return false;