aboutsummaryrefslogtreecommitdiff
path: root/src/lib_json/json_tool.h
diff options
context:
space:
mode:
authorDerek Sollenberger <djsollen@google.com>2016-01-11 14:41:40 -0500
committerDerek Sollenberger <djsollen@google.com>2016-01-11 20:20:14 +0000
commit2eb3b4d7ea1a3cbb0f8775de3b6d92c0a6152f9f (patch)
tree58b7078bd9f0353e4f34119ff3dce5e1b989ab2d /src/lib_json/json_tool.h
parent7daccb3a43871796f8f6c4f70e3b8be79e7e65b2 (diff)
downloadjsoncpp-2eb3b4d7ea1a3cbb0f8775de3b6d92c0a6152f9f.tar.gz
Upgrade jsoncpp to version 1.0.0 to match the copy used by Skia's testing tools.
This mirrors the contents of the upstream repository at... https://github.com/open-source-parsers/jsoncpp/commit/7165f6ac4c482e68475c9e1dac086f9e12fff0d0 Bug: 17997234 Change-Id: I87a8312f9d030e5027f4ca5b1568f8374a856632
Diffstat (limited to 'src/lib_json/json_tool.h')
-rw-r--r--src/lib_json/json_tool.h108
1 files changed, 51 insertions, 57 deletions
diff --git a/src/lib_json/json_tool.h b/src/lib_json/json_tool.h
index 658031b..f9b61c3 100644
--- a/src/lib_json/json_tool.h
+++ b/src/lib_json/json_tool.h
@@ -4,7 +4,7 @@
// See file LICENSE for detail or copy at http://jsoncpp.sourceforge.net/LICENSE
#ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED
-# define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
+#define LIB_JSONCPP_JSON_TOOL_H_INCLUDED
/* This header provides common string manipulation support, such as UTF-8,
* portable conversion from/to string...
@@ -15,77 +15,71 @@
namespace Json {
/// Converts a unicode code-point to UTF-8.
-static inline std::string
-codePointToUTF8(unsigned int cp)
-{
- std::string result;
-
- // based on description from http://en.wikipedia.org/wiki/UTF-8
+static inline std::string codePointToUTF8(unsigned int cp) {
+ std::string result;
- if (cp <= 0x7f)
- {
- result.resize(1);
- result[0] = static_cast<char>(cp);
- }
- else if (cp <= 0x7FF)
- {
- result.resize(2);
- result[1] = static_cast<char>(0x80 | (0x3f & cp));
- result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
- }
- else if (cp <= 0xFFFF)
- {
- result.resize(3);
- result[2] = static_cast<char>(0x80 | (0x3f & cp));
- result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
- result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
- }
- else if (cp <= 0x10FFFF)
- {
- result.resize(4);
- result[3] = static_cast<char>(0x80 | (0x3f & cp));
- result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
- result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
- result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
- }
-
- return result;
-}
+ // based on description from http://en.wikipedia.org/wiki/UTF-8
+ if (cp <= 0x7f) {
+ result.resize(1);
+ result[0] = static_cast<char>(cp);
+ } else if (cp <= 0x7FF) {
+ result.resize(2);
+ result[1] = static_cast<char>(0x80 | (0x3f & cp));
+ result[0] = static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
+ } else if (cp <= 0xFFFF) {
+ result.resize(3);
+ result[2] = static_cast<char>(0x80 | (0x3f & cp));
+ result[1] = 0x80 | static_cast<char>((0x3f & (cp >> 6)));
+ result[0] = 0xE0 | static_cast<char>((0xf & (cp >> 12)));
+ } else if (cp <= 0x10FFFF) {
+ result.resize(4);
+ result[3] = static_cast<char>(0x80 | (0x3f & cp));
+ result[2] = static_cast<char>(0x80 | (0x3f & (cp >> 6)));
+ result[1] = static_cast<char>(0x80 | (0x3f & (cp >> 12)));
+ result[0] = static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
+ }
-/// Returns true if ch is a control character (in range [0,32[).
-static inline bool
-isControlCharacter(char ch)
-{
- return ch > 0 && ch <= 0x1F;
+ return result;
}
+/// Returns true if ch is a control character (in range [0,32[).
+static inline bool isControlCharacter(char ch) { return ch > 0 && ch <= 0x1F; }
-enum {
- /// Constant that specify the size of the buffer that must be passed to uintToString.
- uintToStringBufferSize = 3*sizeof(LargestUInt)+1
+enum {
+ /// Constant that specify the size of the buffer that must be passed to
+ /// uintToString.
+ uintToStringBufferSize = 3 * sizeof(LargestUInt) + 1
};
// Defines a char buffer for use with uintToString().
typedef char UIntToStringBuffer[uintToStringBufferSize];
-
/** Converts an unsigned integer to string.
* @param value Unsigned interger to convert to string
- * @param current Input/Output string buffer.
+ * @param current Input/Output string buffer.
* Must have at least uintToStringBufferSize chars free.
*/
-static inline void
-uintToString( LargestUInt value,
- char *&current )
-{
- *--current = 0;
- do
- {
- *--current = char(value % 10) + '0';
- value /= 10;
- }
- while ( value != 0 );
+static inline void uintToString(LargestUInt value, char*& current) {
+ *--current = 0;
+ do {
+ *--current = char(value % 10) + '0';
+ value /= 10;
+ } while (value != 0);
+}
+
+/** Change ',' to '.' everywhere in buffer.
+ *
+ * We had a sophisticated way, but it did not work in WinCE.
+ * @see https://github.com/open-source-parsers/jsoncpp/pull/9
+ */
+static inline void fixNumericLocale(char* begin, char* end) {
+ while (begin < end) {
+ if (*begin == ',') {
+ *begin = '.';
+ }
+ ++begin;
+ }
}
} // namespace Json {