summaryrefslogtreecommitdiffstats
path: root/base/json
diff options
context:
space:
mode:
authortfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 21:03:16 +0000
committertfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-31 21:03:16 +0000
commit61197dffa1137d7e4fe003281ad3e38108e90411 (patch)
tree5b6b76500ee42dedaa6e8d0bfd994432930fb4a4 /base/json
parent38c93edcd09cf787333470019f2d2c1bb23f8b98 (diff)
downloadchromium_src-61197dffa1137d7e4fe003281ad3e38108e90411.zip
chromium_src-61197dffa1137d7e4fe003281ad3e38108e90411.tar.gz
chromium_src-61197dffa1137d7e4fe003281ad3e38108e90411.tar.bz2
base: Add HexDigitToInt function to string_util.h
Removed duplicated HexToInt functions and converted the callers along the way. BUG=None TEST=trybots and out/Debug/base_unittests --gtest_filter=StringUtilTest.HexDigitToInt Signed-off-by: Thiago Farina <tfarina@chromium.org> Review URL: http://codereview.chromium.org/2836069 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@54473 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/json')
-rw-r--r--base/json/json_reader.cc26
1 files changed, 7 insertions, 19 deletions
diff --git a/base/json/json_reader.cc b/base/json/json_reader.cc
index 1255ac5..0d6abc4 100644
--- a/base/json/json_reader.cc
+++ b/base/json/json_reader.cc
@@ -1,4 +1,4 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2010 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
@@ -20,18 +20,6 @@ static const int kStackLimit = 100;
namespace {
-inline int HexToInt(wchar_t c) {
- if ('0' <= c && c <= '9') {
- return c - '0';
- } else if ('A' <= c && c <= 'F') {
- return c - 'A' + 10;
- } else if ('a' <= c && c <= 'f') {
- return c - 'a' + 10;
- }
- NOTREACHED();
- return 0;
-}
-
// A helper method for ParseNumberToken. It reads an int from the end of
// token. The method returns false if there is no valid integer at the end of
// the token.
@@ -493,15 +481,15 @@ Value* JSONReader::DecodeString(const Token& token) {
break;
case 'x':
- decoded_str.push_back((HexToInt(*(token.begin + i + 1)) << 4) +
- HexToInt(*(token.begin + i + 2)));
+ decoded_str.push_back((HexDigitToInt(*(token.begin + i + 1)) << 4) +
+ HexDigitToInt(*(token.begin + i + 2)));
i += 2;
break;
case 'u':
- decoded_str.push_back((HexToInt(*(token.begin + i + 1)) << 12 ) +
- (HexToInt(*(token.begin + i + 2)) << 8) +
- (HexToInt(*(token.begin + i + 3)) << 4) +
- HexToInt(*(token.begin + i + 4)));
+ decoded_str.push_back((HexDigitToInt(*(token.begin + i + 1)) << 12 ) +
+ (HexDigitToInt(*(token.begin + i + 2)) << 8) +
+ (HexDigitToInt(*(token.begin + i + 3)) << 4) +
+ HexDigitToInt(*(token.begin + i + 4)));
i += 4;
break;