diff options
Diffstat (limited to 'base/string_util.h')
-rw-r--r-- | base/string_util.h | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/base/string_util.h b/base/string_util.h index cb71553..f40cc8d 100644 --- a/base/string_util.h +++ b/base/string_util.h @@ -595,5 +595,33 @@ bool MatchPattern(const std::string& string, const std::string& pattern); // std::numeric_limits<size_t>::max() / 2 std::string HexEncode(const void* bytes, size_t size); +// Hack to convert any char-like type to its unsigned counterpart. +// For example, it will convert char, signed char and unsigned char to unsigned +// char. +template<typename T> +struct ToUnsigned { + typedef T Unsigned; +}; + +template<> +struct ToUnsigned<char> { + typedef unsigned char Unsigned; +}; +template<> +struct ToUnsigned<signed char> { + typedef unsigned char Unsigned; +}; +template<> +struct ToUnsigned<wchar_t> { +#if defined(WCHAR_T_IS_UTF16) + typedef unsigned short Unsigned; +#elif defined(WCHAR_T_IS_UTF32) + typedef uint32 Unsigned; +#endif +}; +template<> +struct ToUnsigned<short> { + typedef unsigned short Unsigned; +}; #endif // BASE_STRING_UTIL_H_ |