3102 json lowercase hex (#4306)

* Made it possible to use lowercase hex numbers, also when encoding JSON (#3102)

Co-authored-by: Thomas Weyn <Thomas.Weyn@cebir.be>

* fix(JSONString): Remove deprecated toJSON functions #4305

* fix(NumericString): conversions inconsistencies #4304

---------

Co-authored-by: Archipel <thomas@weynwebworks.com>
Co-authored-by: Thomas Weyn <Thomas.Weyn@cebir.be>
This commit is contained in:
Aleksandar Fabijanic
2023-11-27 22:43:20 +01:00
committed by GitHub
parent 9141368eca
commit 57bc0bbbb5
13 changed files with 292 additions and 173 deletions

View File

@@ -178,7 +178,7 @@ std::string UTF8::escape(const std::string &s, bool strictJSON)
}
std::string UTF8::escape(const std::string::const_iterator& begin, const std::string::const_iterator& end, bool strictJSON)
std::string UTF8::escape(const std::string::const_iterator& begin, const std::string::const_iterator& end, bool strictJSON, bool lowerCaseHex)
{
static Poco::UInt32 offsetsFromUTF8[6] = {
0x00000000UL, 0x00003080UL, 0x000E2080UL,
@@ -208,7 +208,7 @@ std::string UTF8::escape(const std::string::const_iterator& begin, const std::st
else if (ch == '\r') result += "\\r";
else if (ch == '\b') result += "\\b";
else if (ch == '\f') result += "\\f";
else if (ch == '\v') result += (strictJSON ? "\\u000B" : "\\v");
else if (ch == '\v') result += (strictJSON ? (lowerCaseHex ? "\\u000b" : "\\u000B") : "\\v");
else if (ch == '\a') result += (strictJSON ? "\\u0007" : "\\a");
else if (ch == '\\') result += "\\\\";
else if (ch == '\"') result += "\\\"";
@@ -217,20 +217,20 @@ std::string UTF8::escape(const std::string::const_iterator& begin, const std::st
else if (ch < 32 || ch == 0x7f)
{
result += "\\u";
NumberFormatter::appendHex(result, (unsigned short) ch, 4);
NumberFormatter::appendHex(result, (unsigned short) ch, 4, lowerCaseHex);
}
else if (ch > 0xFFFF)
{
ch -= 0x10000;
result += "\\u";
NumberFormatter::appendHex(result, (unsigned short) (( ch >> 10 ) & 0x03ff ) + 0xd800, 4);
NumberFormatter::appendHex(result, (unsigned short) (( ch >> 10 ) & 0x03ff ) + 0xd800, 4, lowerCaseHex);
result += "\\u";
NumberFormatter::appendHex(result, (unsigned short) (ch & 0x03ff ) + 0xdc00, 4);
NumberFormatter::appendHex(result, (unsigned short) (ch & 0x03ff ) + 0xdc00, 4, lowerCaseHex);
}
else if (ch >= 0x80 && ch <= 0xFFFF)
{
result += "\\u";
NumberFormatter::appendHex(result, (unsigned short) ch, 4);
NumberFormatter::appendHex(result, (unsigned short) ch, 4, lowerCaseHex);
}
else
{