diff options
author | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:54:11 -0700 |
---|---|---|
committer | Richard Walters <rwalters@digitalstirling.com> | 2018-07-01 23:54:11 -0700 |
commit | 4f143b56b5ec2bc686a999571c825a7e9fa0d139 (patch) | |
tree | 4b5d356a1d81fbdae3904e8fd08e61c2b4c78007 | |
parent | f7bfd92051c004a37e7b6e38c2b2001764eeef74 (diff) |
Refactoring
We don't really need a formal state machine for
decoding percent-encoded characters. We really just
need to shift in two hex digits and we're done.
-rw-r--r-- | src/PercentEncodedCharacterDecoder.cpp | 29 |
1 files changed, 7 insertions, 22 deletions
diff --git a/src/PercentEncodedCharacterDecoder.cpp b/src/PercentEncodedCharacterDecoder.cpp index c34b817..4fb92c0 100644 --- a/src/PercentEncodedCharacterDecoder.cpp +++ b/src/PercentEncodedCharacterDecoder.cpp @@ -42,12 +42,10 @@ namespace Uri { int decodedCharacter = 0; /** - * This is the current state of the decoder's state machine. - * - 0: we haven't yet received the first hex digit. - * - 1: we received the first hex digit but not the second. - * - 2: we received both hex digits + * This is the number of digits that we still need to shift in + * to decode the character. */ - size_t decoderState = 0; + size_t digitsLeft = 2; // Methods @@ -87,28 +85,15 @@ namespace Uri { } bool PercentEncodedCharacterDecoder::NextEncodedCharacter(char c) { - switch(impl_->decoderState) { - case 0: { // % ... - impl_->decoderState = 1; - if (!impl_->ShiftInHexDigit(c)) { - return false; - } - } break; - - case 1: { // %[0-9A-F] ... - impl_->decoderState = 2; - if (!impl_->ShiftInHexDigit(c)) { - return false; - } - } break; - - default: break; + if (!impl_->ShiftInHexDigit(c)) { + return false; } + --impl_->digitsLeft; return true; } bool PercentEncodedCharacterDecoder::Done() const { - return (impl_->decoderState == 2); + return (impl_->digitsLeft == 0); } char PercentEncodedCharacterDecoder::GetDecodedCharacter() const { |