summaryrefslogtreecommitdiffstats
path: root/base/string_util.h
diff options
context:
space:
mode:
authorerikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-20 16:43:49 +0000
committererikkay@google.com <erikkay@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-05-20 16:43:49 +0000
commitd36519b5068d92f4e71b8d6fd51eda2c42e54e38 (patch)
tree6aaf53187b1a36cc1d1f45c8f5ca994d55900650 /base/string_util.h
parentc66cd7d3bfe3b572c7824db8c7d8d5c71cd21afd (diff)
downloadchromium_src-d36519b5068d92f4e71b8d6fd51eda2c42e54e38.zip
chromium_src-d36519b5068d92f4e71b8d6fd51eda2c42e54e38.tar.gz
chromium_src-d36519b5068d92f4e71b8d6fd51eda2c42e54e38.tar.bz2
Add JSON-specific escaping, which has different rules from JS escaping.BUG=http://crbug.com/11431TEST=base_unittests.exe --gtest_filter=StringEscapeTest.Json*
Review URL: http://codereview.chromium.org/113606 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@16485 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/string_util.h')
-rw-r--r--base/string_util.h28
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_