summaryrefslogtreecommitdiffstats
path: root/base/string_util.h
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/string_util.h
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/string_util.h')
-rw-r--r--base/string_util.h12
1 files changed, 12 insertions, 0 deletions
diff --git a/base/string_util.h b/base/string_util.h
index 762779c..97b5100 100644
--- a/base/string_util.h
+++ b/base/string_util.h
@@ -380,6 +380,18 @@ inline bool IsHexDigit(Char c) {
(c >= 'a' && c <= 'f');
}
+template <typename Char>
+inline Char HexDigitToInt(Char c) {
+ DCHECK(IsHexDigit(c));
+ if (c >= '0' && c <= '9')
+ return c - '0';
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ return 0;
+}
+
// Returns true if it's a whitespace character.
inline bool IsWhitespace(wchar_t c) {
return wcschr(kWhitespaceWide, c) != NULL;