Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(335)

Side by Side Diff: net/spdy/spdy_alt_svc_wire_format.cc

Issue 2558643002: Remove some uses of isdigit in net/, as it can be locale depedent. (Closed)
Patch Set: Response Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/quic/core/quic_spdy_stream_test.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2015 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/spdy/spdy_alt_svc_wire_format.h" 5 #include "net/spdy/spdy_alt_svc_wire_format.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 #include <string> 9 #include <string>
10 10
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "base/strings/string_util.h"
12 #include "base/strings/stringprintf.h" 13 #include "base/strings/stringprintf.h"
13 14
14 namespace net { 15 namespace net {
15 16
16 using base::StringPiece; 17 using base::StringPiece;
17 18
18 namespace { 19 namespace {
19 20
20 template <class T> 21 template <class T>
21 bool ParsePositiveIntegerImpl(StringPiece::const_iterator c, 22 bool ParsePositiveIntegerImpl(StringPiece::const_iterator c,
22 StringPiece::const_iterator end, 23 StringPiece::const_iterator end,
23 T* value) { 24 T* value) {
24 *value = 0; 25 *value = 0;
25 for (; c != end && isdigit(*c); ++c) { 26 // TODO(mmenke): This really should be using methods in parse_number.h.
27 for (; c != end && '0' <= *c && *c <= '9'; ++c) {
26 if (*value > std::numeric_limits<T>::max() / 10) { 28 if (*value > std::numeric_limits<T>::max() / 10) {
27 return false; 29 return false;
28 } 30 }
29 *value *= 10; 31 *value *= 10;
30 if (*value > std::numeric_limits<T>::max() - (*c - '0')) { 32 if (*value > std::numeric_limits<T>::max() - (*c - '0')) {
31 return false; 33 return false;
32 } 34 }
33 *value += *c - '0'; 35 *value += *c - '0';
34 } 36 }
35 return (c == end && *value > 0); 37 return (c == end && *value > 0);
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 StringPiece::const_iterator end, 272 StringPiece::const_iterator end,
271 std::string* output) { 273 std::string* output) {
272 output->clear(); 274 output->clear();
273 for (; c != end; ++c) { 275 for (; c != end; ++c) {
274 if (*c != '%') { 276 if (*c != '%') {
275 output->push_back(*c); 277 output->push_back(*c);
276 continue; 278 continue;
277 } 279 }
278 DCHECK_EQ('%', *c); 280 DCHECK_EQ('%', *c);
279 ++c; 281 ++c;
280 if (c == end || !isxdigit(*c)) { 282 if (c == end || !base::IsHexDigit(*c)) {
281 return false; 283 return false;
282 } 284 }
283 char decoded = tolower(*c);
284 // '0' is 0, 'a' is 10.
285 decoded += isdigit(*c) ? (0 - '0') : (10 - 'a');
286 // Network byte order is big-endian. 285 // Network byte order is big-endian.
287 decoded <<= 4; 286 int decoded = base::HexDigitToInt(*c) << 4;
287
288 ++c; 288 ++c;
289 if (c == end || !isxdigit(*c)) { 289 if (c == end || !base::IsHexDigit(*c)) {
290 return false; 290 return false;
291 } 291 }
292 decoded += tolower(*c); 292 // Network byte order is big-endian.
293 // '0' is 0, 'a' is 10. 293 decoded += base::HexDigitToInt(*c);
294 decoded += isdigit(*c) ? (0 - '0') : (10 - 'a'); 294
295 output->push_back(decoded); 295 output->push_back(static_cast<char>(decoded));
296 } 296 }
297 return true; 297 return true;
298 } 298 }
299 299
300 // static 300 // static
301 bool SpdyAltSvcWireFormat::ParseAltAuthority(StringPiece::const_iterator c, 301 bool SpdyAltSvcWireFormat::ParseAltAuthority(StringPiece::const_iterator c,
302 StringPiece::const_iterator end, 302 StringPiece::const_iterator end,
303 std::string* host, 303 std::string* host,
304 uint16_t* port) { 304 uint16_t* port) {
305 host->clear(); 305 host->clear();
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
353 353
354 // static 354 // static
355 bool SpdyAltSvcWireFormat::ParsePositiveInteger32( 355 bool SpdyAltSvcWireFormat::ParsePositiveInteger32(
356 StringPiece::const_iterator c, 356 StringPiece::const_iterator c,
357 StringPiece::const_iterator end, 357 StringPiece::const_iterator end,
358 uint32_t* value) { 358 uint32_t* value) {
359 return ParsePositiveIntegerImpl<uint32_t>(c, end, value); 359 return ParsePositiveIntegerImpl<uint32_t>(c, end, value);
360 } 360 }
361 361
362 } // namespace net 362 } // namespace net
OLDNEW
« no previous file with comments | « net/quic/core/quic_spdy_stream_test.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698