summaryrefslogtreecommitdiffstats
path: root/net
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 /net
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 'net')
-rw-r--r--net/base/escape.cc16
-rw-r--r--net/base/net_util.cc9
2 files changed, 4 insertions, 21 deletions
diff --git a/net/base/escape.cc b/net/base/escape.cc
index d9bfcee..3c39f95 100644
--- a/net/base/escape.cc
+++ b/net/base/escape.cc
@@ -15,18 +15,6 @@
namespace {
-template <class char_type>
-inline char_type HexToInt(char_type ch) {
- if (ch >= '0' && ch <= '9')
- return ch - '0';
- if (ch >= 'A' && ch <= 'F')
- return ch - 'A' + 10;
- if (ch >= 'a' && ch <= 'f')
- return ch - 'a' + 10;
- NOTREACHED();
- return 0;
-}
-
static const char* const kHexString = "0123456789ABCDEF";
inline char IntToHex(int i) {
DCHECK(i >= 0 && i <= 15) << i << " not a hex value";
@@ -136,8 +124,8 @@ STR UnescapeURLImpl(const STR& escaped_text,
const typename STR::value_type least_sig_digit(
static_cast<typename STR::value_type>(escaped_text[i + 2]));
if (IsHexDigit(most_sig_digit) && IsHexDigit(least_sig_digit)) {
- unsigned char value = HexToInt(most_sig_digit) * 16 +
- HexToInt(least_sig_digit);
+ unsigned char value = HexDigitToInt(most_sig_digit) * 16 +
+ HexDigitToInt(least_sig_digit);
if (value >= 0x80 || // Unescape all high-bit characters.
// For 7-bit characters, the lookup table tells us all valid chars.
(kUrlUnescape[value] ||
diff --git a/net/base/net_util.cc b/net/base/net_util.cc
index e25eb50..1d903b8 100644
--- a/net/base/net_util.cc
+++ b/net/base/net_util.cc
@@ -186,12 +186,6 @@ STR GetSpecificHeaderT(const STR& headers, const STR& name) {
return ret;
}
-inline unsigned char HexToInt(unsigned char c) {
- DCHECK(IsHexDigit(c));
- static unsigned char kOffset[4] = {0, 0x30u, 0x37u, 0x57u};
- return c - kOffset[(c >> 5) & 3];
-}
-
// Similar to Base64Decode. Decodes a Q-encoded string to a sequence
// of bytes. If input is invalid, return false.
bool QPDecode(const std::string& input, std::string* output) {
@@ -207,7 +201,8 @@ bool QPDecode(const std::string& input, std::string* output) {
}
if (IsHexDigit(static_cast<unsigned char>(*(it + 1))) &&
IsHexDigit(static_cast<unsigned char>(*(it + 2)))) {
- unsigned char ch = HexToInt(*(it + 1)) * 16 + HexToInt(*(it + 2));
+ unsigned char ch = HexDigitToInt(*(it + 1)) * 16 +
+ HexDigitToInt(*(it + 2));
temp.push_back(static_cast<char>(ch));
++it;
++it;