sync json/json_variant with ToobAmp
This commit is contained in:
@@ -308,7 +308,7 @@ namespace pipedal
|
|||||||
iterator end() { return values.end(); }
|
iterator end() { return values.end(); }
|
||||||
const_iterator begin() const { return values.begin(); }
|
const_iterator begin() const { return values.begin(); }
|
||||||
const_iterator end() const { return values.end(); }
|
const_iterator end() const { return values.end(); }
|
||||||
|
|
||||||
iterator erase(iterator it)
|
iterator erase(iterator it)
|
||||||
{
|
{
|
||||||
return values.erase(it);
|
return values.erase(it);
|
||||||
|
|||||||
@@ -22,6 +22,8 @@
|
|||||||
#include <cctype>
|
#include <cctype>
|
||||||
#include "json_variant.hpp"
|
#include "json_variant.hpp"
|
||||||
#include "util.hpp"
|
#include "util.hpp"
|
||||||
|
#include <string_view>
|
||||||
|
|
||||||
using namespace pipedal;
|
using namespace pipedal;
|
||||||
|
|
||||||
|
|
||||||
@@ -123,7 +125,7 @@ void json_writer::write(string_view v,bool enforceValidUtf8Encoding)
|
|||||||
if ((uc >= UTF16_SURROGATE_1_BASE && uc <= UTF16_SURROGATE_1_BASE + UTF16_SURROGATE_MASK) || (uc >= UTF16_SURROGATE_2_BASE && uc <= UTF16_SURROGATE_2_BASE + UTF16_SURROGATE_MASK))
|
if ((uc >= UTF16_SURROGATE_1_BASE && uc <= UTF16_SURROGATE_1_BASE + UTF16_SURROGATE_MASK) || (uc >= UTF16_SURROGATE_2_BASE && uc <= UTF16_SURROGATE_2_BASE + UTF16_SURROGATE_MASK))
|
||||||
{
|
{
|
||||||
// MUST not encode UTF16 surrogates in UTF8.
|
// MUST not encode UTF16 surrogates in UTF8.
|
||||||
// throw_encoding_error();
|
throw_encoding_error();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (uc == '"' || uc == '\\')
|
if (uc == '"' || uc == '\\')
|
||||||
@@ -268,6 +270,29 @@ void json_reader::skip_whitespace()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void utf32_to_utf8_stream(std::ostream &s, uint32_t uc)
|
||||||
|
{
|
||||||
|
if (uc < 0x80u)
|
||||||
|
{
|
||||||
|
s << (char)uc;
|
||||||
|
} else if (uc < 0x800u) {
|
||||||
|
s << (char)(0xC0 + (uc >> 6));
|
||||||
|
s << (char)(0x80 + (uc & 0x3F));
|
||||||
|
|
||||||
|
} else if (uc < 0x10000u) {
|
||||||
|
s << (char)(0xE0 + (uc >> 12));
|
||||||
|
s << (char)(0x80 + ((uc >> 6) & 0x3F));
|
||||||
|
s << (char)(0x80 + (uc & 0x3F));
|
||||||
|
} else if (uc < 0x0110000) {
|
||||||
|
s << (char)(0xF0 + (uc >> 18));
|
||||||
|
s << (char)(0x80 + ((uc >> 12) & 0x3F));
|
||||||
|
s << (char)(0x80 + ((uc >> 6) & 0x3F));
|
||||||
|
s << (char)(0x80 + (uc & 0x3F));
|
||||||
|
} else {
|
||||||
|
throw std::range_error("Illegal UTF-32 character.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::string json_reader::read_string()
|
std::string json_reader::read_string()
|
||||||
{
|
{
|
||||||
// To completely normalize UTF-32 values we must covert to UTF-16, resolve surrogate pairs, and then convert UTF-32 to UTF-8.
|
// To completely normalize UTF-32 values we must covert to UTF-16, resolve surrogate pairs, and then convert UTF-32 to UTF-8.
|
||||||
@@ -344,7 +369,7 @@ std::string json_reader::read_string()
|
|||||||
}
|
}
|
||||||
uc = ((uc & UTF16_SURROGATE_MASK) << 10) + (uc2 & UTF16_SURROGATE_MASK) + 0x10000U;
|
uc = ((uc & UTF16_SURROGATE_MASK) << 10) + (uc2 & UTF16_SURROGATE_MASK) + 0x10000U;
|
||||||
}
|
}
|
||||||
HtmlHelper::utf32_to_utf8_stream(s, uc);
|
utf32_to_utf8_stream(s, uc);
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,6 +50,9 @@ void json_variant::free()
|
|||||||
case ContentType::Array:
|
case ContentType::Array:
|
||||||
memArray().std::shared_ptr<json_array>::~shared_ptr();
|
memArray().std::shared_ptr<json_array>::~shared_ptr();
|
||||||
break;
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
content_type = ContentType::Null;
|
content_type = ContentType::Null;
|
||||||
}
|
}
|
||||||
@@ -467,6 +470,15 @@ json_variant &json_variant::operator=(json_variant &&value)
|
|||||||
case ContentType::Object:
|
case ContentType::Object:
|
||||||
std::swap(this->memObject(), value.memObject());
|
std::swap(this->memObject(), value.memObject());
|
||||||
return *this;
|
return *this;
|
||||||
|
case ContentType::Null:
|
||||||
|
return *this; // nothing to do.
|
||||||
|
case ContentType::Bool:
|
||||||
|
std::swap(this->content.bool_value, value.content.bool_value);
|
||||||
|
return *this;
|
||||||
|
case ContentType::Number:
|
||||||
|
std::swap(this->content.double_value, value.content.double_value);
|
||||||
|
return *this;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
free();
|
free();
|
||||||
|
|||||||
Reference in New Issue
Block a user