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

@@ -90,6 +90,12 @@ public:
bool getEscapeUnicode() const;
/// Returns the flag for escaping unicode.
void setLowercaseHex(bool lowercaseHex);
/// Sets the flag for using lowercase hex numbers
bool getLowercaseHex() const;
/// Returns the flag for using lowercase hex numbers
ValueVec::const_iterator begin() const;
/// Returns the begin iterator for values.
@@ -206,6 +212,7 @@ private:
// is because Array can be returned stringified from a Dynamic::Var:toString(),
// so it must know whether to escape unicode or not.
bool _escapeUnicode;
bool _lowercaseHex;
};
@@ -224,6 +231,17 @@ inline bool Array::getEscapeUnicode() const
return _escapeUnicode;
}
inline void Array::setLowercaseHex(bool lowercaseHex)
{
_lowercaseHex = lowercaseHex;
}
inline bool Array::getLowercaseHex() const
{
return _lowercaseHex;
}
inline Array::ValueVec::const_iterator Array::begin() const
{

View File

@@ -101,7 +101,13 @@ public:
bool getEscapeUnicode() const;
/// Returns the flag for escaping unicode.
void setLowercaseHex(bool lowercaseHex);
/// Sets the flag for using lowercase hex numbers
bool getLowercaseHex() const;
/// Returns the flag for using lowercase hex numbers
Iterator begin();
/// Returns begin iterator for values.
@@ -255,6 +261,7 @@ private:
{
int options = Poco::JSON_WRAP_STRINGS;
options |= _escapeUnicode ? Poco::JSON_ESCAPE_UNICODE : 0;
options |= _lowercaseHex ? Poco::JSON_LOWERCASE_HEX : 0;
out << '{';
@@ -349,6 +356,7 @@ private:
// because Object can be returned stringified from Dynamic::Var::toString(),
// so it must know whether to escape unicode or not.
bool _escapeUnicode;
bool _lowercaseHex;
mutable StructPtr _pStruct;
mutable OrdStructPtr _pOrdStruct;
mutable bool _modified;
@@ -370,6 +378,17 @@ inline bool Object::getEscapeUnicode() const
return _escapeUnicode;
}
inline void Object::setLowercaseHex(bool lowercaseHex)
{
_lowercaseHex = lowercaseHex;
}
inline bool Object::getLowercaseHex() const
{
return _lowercaseHex;
}
inline Object::Iterator Object::begin()
{

View File

@@ -27,7 +27,8 @@ namespace JSON {
Array::Array(int options):
_modified(false),
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0)
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0),
_lowercaseHex((options & Poco::JSON_LOWERCASE_HEX) != 0)
{
}
@@ -36,7 +37,8 @@ Array::Array(const Array& other) :
_values(other._values),
_pArray(other._pArray),
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
_escapeUnicode(other._escapeUnicode),
_lowercaseHex(other._lowercaseHex)
{
}
@@ -45,7 +47,8 @@ Array::Array(Array&& other) noexcept:
_values(std::move(other._values)),
_pArray(std::move(other._pArray)),
_modified(other._modified),
_escapeUnicode(other._escapeUnicode)
_escapeUnicode(other._escapeUnicode),
_lowercaseHex(other._lowercaseHex)
{
}
@@ -58,6 +61,7 @@ Array& Array::operator = (const Array& other)
_pArray = other._pArray;
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
_lowercaseHex = other._lowercaseHex;
}
return *this;
}
@@ -69,6 +73,7 @@ Array& Array::operator = (Array&& other) noexcept
_pArray = std::move(other._pArray);
_modified = other._modified;
_escapeUnicode = other._escapeUnicode;
_lowercaseHex = other._lowercaseHex;
return *this;
}
@@ -154,6 +159,7 @@ void Array::stringify(std::ostream& out, unsigned int indent, int step) const
{
int options = Poco::JSON_WRAP_STRINGS;
options |= _escapeUnicode ? Poco::JSON_ESCAPE_UNICODE : 0;
options |= _lowercaseHex ? Poco::JSON_LOWERCASE_HEX : 0;
if (step == -1) step = indent;

View File

@@ -27,6 +27,7 @@ namespace JSON {
Object::Object(int options):
_preserveInsOrder((options & Poco::JSON_PRESERVE_KEY_ORDER) != 0),
_escapeUnicode((options & Poco::JSON_ESCAPE_UNICODE) != 0),
_lowercaseHex((options & Poco::JSON_LOWERCASE_HEX) != 0),
_modified(false)
{
}
@@ -35,6 +36,7 @@ Object::Object(int options):
Object::Object(const Object& other) : _values(other._values),
_preserveInsOrder(other._preserveInsOrder),
_escapeUnicode(other._escapeUnicode),
_lowercaseHex(other._lowercaseHex),
_pStruct(!other._modified ? other._pStruct : 0),
_modified(other._modified)
{
@@ -47,6 +49,7 @@ Object::Object(Object&& other) noexcept:
_keys(std::move(other._keys)),
_preserveInsOrder(other._preserveInsOrder),
_escapeUnicode(other._escapeUnicode),
_lowercaseHex(other._lowercaseHex),
_pStruct(std::move(other._pStruct)),
_pOrdStruct(std::move(other._pOrdStruct)),
_modified(other._modified)
@@ -67,6 +70,7 @@ Object &Object::operator = (const Object &other)
_keys = other._keys;
_preserveInsOrder = other._preserveInsOrder;
_escapeUnicode = other._escapeUnicode;
_lowercaseHex = other._lowercaseHex;
_pStruct = !other._modified ? other._pStruct : 0;
_modified = other._modified;
}
@@ -80,6 +84,7 @@ Object& Object::operator = (Object&& other) noexcept
_keys = std::move(other._keys);
_preserveInsOrder = other._preserveInsOrder;
_escapeUnicode = other._escapeUnicode;
_lowercaseHex = other._lowercaseHex;
_pStruct = std::move(other._pStruct);
_pOrdStruct = std::move(other._pOrdStruct);
_modified = other._modified;

View File

@@ -28,6 +28,7 @@ namespace JSON {
void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int indent, int step, int options)
{
bool escapeUnicode = ((options & Poco::JSON_ESCAPE_UNICODE) != 0);
bool lowercaseHex = ((options & Poco::JSON_LOWERCASE_HEX) != 0);
if (step == -1) step = indent;
@@ -35,24 +36,28 @@ void Stringifier::stringify(const Var& any, std::ostream& out, unsigned int inde
{
Object& o = const_cast<Object&>(any.extract<Object>());
o.setEscapeUnicode(escapeUnicode);
o.setLowercaseHex(lowercaseHex);
o.stringify(out, indent == 0 ? 0 : indent, step);
}
else if (any.type() == typeid(Array))
{
Array& a = const_cast<Array&>(any.extract<Array>());
a.setEscapeUnicode(escapeUnicode);
a.setLowercaseHex(lowercaseHex);
a.stringify(out, indent == 0 ? 0 : indent, step);
}
else if (any.type() == typeid(Object::Ptr))
{
Object::Ptr& o = const_cast<Object::Ptr&>(any.extract<Object::Ptr>());
o->setEscapeUnicode(escapeUnicode);
o->setLowercaseHex(lowercaseHex);
o->stringify(out, indent == 0 ? 0 : indent, step);
}
else if (any.type() == typeid(Array::Ptr))
{
Array::Ptr& a = const_cast<Array::Ptr&>(any.extract<Array::Ptr>());
a->setEscapeUnicode(escapeUnicode);
a->setLowercaseHex(lowercaseHex);
a->stringify(out, indent == 0 ? 0 : indent, step);
}
else if (any.isEmpty())