From e0e922db5fb77df9a5a9cc802096f484ed21da1c Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Tue, 3 Nov 2015 14:54:35 -0500 Subject: Revert "Revert "Cleanup some numeric code."" This reverts commit 23d576f0b498bd4f37ef2175916223a2e5ea0324. Cleanup some numeric code. This changes the various comparisons of char >= '0' && char <= '9' and char < '0' || char > '9' to use std::isdigit checks. It also cleans up a handful of hex to digit conversions to call one common method. R=tsepez@chromium.org Review URL: https://codereview.chromium.org/1405253007 . --- core/include/fxcrt/fx_ext.h | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) (limited to 'core/include/fxcrt') diff --git a/core/include/fxcrt/fx_ext.h b/core/include/fxcrt/fx_ext.h index c24955fb7c..4cea13c9fd 100644 --- a/core/include/fxcrt/fx_ext.h +++ b/core/include/fxcrt/fx_ext.h @@ -7,11 +7,9 @@ #ifndef CORE_INCLUDE_FXCRT_FX_EXT_H_ #define CORE_INCLUDE_FXCRT_FX_EXT_H_ -#include "fx_system.h" +#include -#ifdef __cplusplus -extern "C" { -#endif +#include "fx_system.h" FX_FLOAT FXSYS_tan(FX_FLOAT a); FX_FLOAT FXSYS_logb(FX_FLOAT b, FX_FLOAT x); @@ -38,6 +36,19 @@ inline int32_t FXSYS_toupper(int32_t ch) { return ch < 'a' || ch > 'z' ? ch : (ch - 0x20); } +inline int FXSYS_toHexDigit(char c) { + if (!std::isxdigit(c)) + return 0; + char upchar = std::toupper(c); + return upchar > '9' ? upchar - 'A' + 10 : upchar - '0'; +} + +inline int FXSYS_toDecimalDigit(char c) { + if (!std::isdigit(c)) + return 0; + return c - '0'; +} + FX_DWORD FX_HashCode_String_GetA(const FX_CHAR* pStr, int32_t iLength, FX_BOOL bIgnoreCase = FALSE); @@ -45,13 +56,6 @@ FX_DWORD FX_HashCode_String_GetW(const FX_WCHAR* pStr, int32_t iLength, FX_BOOL bIgnoreCase = FALSE); -#ifdef __cplusplus -} -#endif -#ifdef __cplusplus -extern "C" { -#endif - void* FX_Random_MT_Start(FX_DWORD dwSeed); FX_DWORD FX_Random_MT_Generate(void* pContext); @@ -63,9 +67,7 @@ void FX_Random_GenerateBase(FX_DWORD* pBuffer, int32_t iCount); void FX_Random_GenerateMT(FX_DWORD* pBuffer, int32_t iCount); void FX_Random_GenerateCrypto(FX_DWORD* pBuffer, int32_t iCount); -#ifdef __cplusplus -} -#endif + template class CFX_SSortTemplate { public: -- cgit v1.2.3