diff options
author | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 01:10:46 +0000 |
---|---|---|
committer | tfarina@chromium.org <tfarina@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-23 01:10:46 +0000 |
commit | b8c1eb454dc4f246c64a6b1b5b472af102e88103 (patch) | |
tree | 6413d1400ee4ade44838ecd530736840d1f4f64b | |
parent | be2da4de5227f4f1cbb8455a58045c5e51076474 (diff) | |
download | chromium_src-b8c1eb454dc4f246c64a6b1b5b472af102e88103.zip chromium_src-b8c1eb454dc4f246c64a6b1b5b472af102e88103.tar.gz chromium_src-b8c1eb454dc4f246c64a6b1b5b472af102e88103.tar.bz2 |
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 <tfarina@chromium.org>
Review URL: http://codereview.chromium.org/2870058
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53428 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r-- | base/string_util.h | 7 | ||||
-rw-r--r-- | net/base/escape.cc | 12 | ||||
-rw-r--r-- | net/base/net_util.cc | 7 | ||||
-rw-r--r-- | net/tools/dump_cache/url_to_filename_encoder.cc | 8 |
4 files changed, 12 insertions, 22 deletions
diff --git a/base/string_util.h b/base/string_util.h index 11a9fd2..d7c5635 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -363,6 +363,13 @@ inline bool IsAsciiDigit(Char c) { return c >= '0' && c <= '9'; } +template <typename Char> +inline bool IsHexDigit(Char c) { + return (c >= '0' && c <= '9') || + (c >= 'A' && c <= 'F') || + (c >= 'a' && c <= 'f'); +} + // Returns true if it's a whitespace character. inline bool IsWhitespace(wchar_t c) { return wcschr(kWhitespaceWide, c) != NULL; 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 <class char_type> -inline bool IsHex(char_type ch) { - return (ch >= '0' && ch <= '9') || - (ch >= 'A' && ch <= 'F') || - (ch >= 'a' && ch <= 'f'); -} - -template <class char_type> 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<typename STR::value_type>(escaped_text[i + 1])); const typename STR::value_type least_sig_digit( static_cast<typename STR::value_type>(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}; diff --git a/net/tools/dump_cache/url_to_filename_encoder.cc b/net/tools/dump_cache/url_to_filename_encoder.cc index 89a1ca4..1462faa 100644 --- a/net/tools/dump_cache/url_to_filename_encoder.cc +++ b/net/tools/dump_cache/url_to_filename_encoder.cc @@ -11,18 +11,14 @@ using std::string; namespace { -inline bool IsHexDigit(unsigned char c) { - return (('0' <= c && c <= '9') || ('A' <= c && c <= 'F') || - ('a' <= c && c <= 'f')); -} - // Returns 1 if buf is prefixed by "num_digits" of hex digits // Teturns 0 otherwise. // The function checks for '\0' for string termination. int HexDigitsPrefix(const char* buf, int num_digits) { - for (int i = 0; i < num_digits; i++) + for (int i = 0; i < num_digits; i++) { if (!IsHexDigit(buf[i])) return 0; // This also detects end of string as '\0' is not xdigit. + } return 1; } |