Chromium Code Reviews| Index: net/spdy/spdy_alt_svc_wire_format.cc |
| diff --git a/net/spdy/spdy_alt_svc_wire_format.cc b/net/spdy/spdy_alt_svc_wire_format.cc |
| index e94b4fa719569e1bebd5d8a29fe21a2b2849fbd6..58de84e3befbec6594e3f2311d23eb44c42ae334 100644 |
| --- a/net/spdy/spdy_alt_svc_wire_format.cc |
| +++ b/net/spdy/spdy_alt_svc_wire_format.cc |
| @@ -9,6 +9,7 @@ |
| #include <string> |
| #include "base/logging.h" |
| +#include "base/strings/string_util.h" |
| #include "base/strings/stringprintf.h" |
| namespace net { |
| @@ -22,7 +23,8 @@ bool ParsePositiveIntegerImpl(StringPiece::const_iterator c, |
| StringPiece::const_iterator end, |
| T* value) { |
| *value = 0; |
| - for (; c != end && isdigit(*c); ++c) { |
| + // TODO(mmenke): This really should be using methods in parse_number.h. |
| + for (; c != end && '0' <= *c && *c <= '9'; ++c) { |
| if (*value > std::numeric_limits<T>::max() / 10) { |
| return false; |
| } |
| @@ -277,21 +279,19 @@ bool SpdyAltSvcWireFormat::PercentDecode(StringPiece::const_iterator c, |
| } |
| DCHECK_EQ('%', *c); |
| ++c; |
| - if (c == end || !isxdigit(*c)) { |
| + if (c == end || !base::IsHexDigit(*c)) { |
| return false; |
| } |
| - char decoded = tolower(*c); |
| - // '0' is 0, 'a' is 10. |
| - decoded += isdigit(*c) ? (0 - '0') : (10 - 'a'); |
| // Network byte order is big-endian. |
| - decoded <<= 4; |
| + char decoded = base::HexDigitToInt(*c) << 4; |
| + |
| ++c; |
| - if (c == end || !isxdigit(*c)) { |
| + if (c == end || !base::IsHexDigit(*c)) { |
| return false; |
| } |
| - decoded += tolower(*c); |
| - // '0' is 0, 'a' is 10. |
| - decoded += isdigit(*c) ? (0 - '0') : (10 - 'a'); |
| + // Network byte order is big-endian. |
| + decoded += base::HexDigitToInt(*c); |
|
eroman
2016/12/07 18:40:11
Hmm.
Signed overflow is undefined, so this additi
mmenke
2016/12/07 19:02:50
SGTM, done, though still have to cast the int to c
|
| + |
| output->push_back(decoded); |
| } |
| return true; |