Index: base/string_util.h |
=================================================================== |
--- base/string_util.h (revision 16481) |
+++ base/string_util.h (working copy) |
@@ -595,5 +595,33 @@ |
// 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_ |