summaryrefslogtreecommitdiffstatshomepage
path: root/src/lib/web/json/json_tool.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/web/json/json_tool.h')
-rw-r--r--src/lib/web/json/json_tool.h96
1 files changed, 47 insertions, 49 deletions
diff --git a/src/lib/web/json/json_tool.h b/src/lib/web/json/json_tool.h
index 658031bbba3..9ad8b0cb95c 100644
--- a/src/lib/web/json/json_tool.h
+++ b/src/lib/web/json/json_tool.h
@@ -13,57 +13,56 @@
*/
namespace Json {
-
/// Converts a unicode code-point to UTF-8.
-static inline std::string
+static inline std::string
codePointToUTF8(unsigned int cp)
{
- std::string result;
-
- // based on description from http://en.wikipedia.org/wiki/UTF-8
+ std::string 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)));
- }
+ 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;
+ return result;
}
/// Returns true if ch is a control character (in range [0,32[).
-static inline bool
+static inline bool
isControlCharacter(char ch)
{
- return ch > 0 && ch <= 0x1F;
+ 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().
@@ -72,22 +71,21 @@ 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 )
+static inline void
+uintToString( LargestUInt value,
+ char *&current )
{
- *--current = 0;
- do
- {
- *--current = char(value % 10) + '0';
- value /= 10;
- }
- while ( value != 0 );
+ *--current = 0;
+ do
+ {
+ *--current = char(value % 10) + '0';
+ value /= 10;
+ }
+ while ( value != 0 );
}
} // namespace Json {
-
#endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED