From b8c1eb454dc4f246c64a6b1b5b472af102e88103 Mon Sep 17 00:00:00 2001 From: "tfarina@chromium.org" Date: Fri, 23 Jul 2010 01:10:46 +0000 Subject: base: Add IsHexDigit function to string_util.h Removed duplicated IsHex functions and converted the callers along the way. (Note: this was a TODO for jungshik). BUG=None TEST=trybots Signed-off-by: Thiago Farina Review URL: http://codereview.chromium.org/2870058 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53428 0039d316-1c4b-4281-b951-d872f2087c98 --- net/base/escape.cc | 12 +++--------- net/base/net_util.cc | 7 ------- 2 files changed, 3 insertions(+), 16 deletions(-) (limited to 'net/base') diff --git a/net/base/escape.cc b/net/base/escape.cc index bc01e11..d9bfcee 100644 --- a/net/base/escape.cc +++ b/net/base/escape.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. @@ -9,19 +9,13 @@ #include "base/i18n/icu_string_conversions.h" #include "base/logging.h" #include "base/string_piece.h" +#include "base/string_util.h" #include "base/utf_string_conversions.h" #include "base/utf_offset_string_conversions.h" namespace { template -inline bool IsHex(char_type ch) { - return (ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'F') || - (ch >= 'a' && ch <= 'f'); -} - -template inline char_type HexToInt(char_type ch) { if (ch >= '0' && ch <= '9') return ch - '0'; @@ -141,7 +135,7 @@ STR UnescapeURLImpl(const STR& escaped_text, static_cast(escaped_text[i + 1])); const typename STR::value_type least_sig_digit( static_cast(escaped_text[i + 2])); - if (IsHex(most_sig_digit) && IsHex(least_sig_digit)) { + if (IsHexDigit(most_sig_digit) && IsHexDigit(least_sig_digit)) { unsigned char value = HexToInt(most_sig_digit) * 16 + HexToInt(least_sig_digit); if (value >= 0x80 || // Unescape all high-bit characters. diff --git a/net/base/net_util.cc b/net/base/net_util.cc index c7b6a6f..d521439 100644 --- a/net/base/net_util.cc +++ b/net/base/net_util.cc @@ -184,13 +184,6 @@ STR GetSpecificHeaderT(const STR& headers, const STR& name) { return ret; } -// TODO(jungshik): We have almost identical hex-decoding code else where. -// Consider refactoring and moving it somewhere(base?). Bug 1224311 -inline bool IsHexDigit(unsigned char c) { - return (('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || - ('a' <= c && c <= 'f')); -} - inline unsigned char HexToInt(unsigned char c) { DCHECK(IsHexDigit(c)); static unsigned char kOffset[4] = {0, 0x30u, 0x37u, 0x57u}; -- cgit v1.1