mirror of
https://github.com/AlexandreRouma/SDRPlusPlus.git
synced 2025-01-12 19:27:11 +01:00
Added preset system for FM IF NR
This commit is contained in:
parent
ad2ddc6ad3
commit
07294034f6
@ -13,6 +13,13 @@ enum DeemphasisMode {
|
||||
_DEEMP_MODE_COUNT
|
||||
};
|
||||
|
||||
enum IFNRPreset {
|
||||
IFNR_PRESET_NOAA_APT,
|
||||
IFNR_PRESET_VOICE,
|
||||
IFNR_PRESET_NARROW_BAND,
|
||||
IFNR_PRESET_BROADCAST
|
||||
};
|
||||
|
||||
namespace demod {
|
||||
class Demodulator {
|
||||
public:
|
||||
|
@ -22,6 +22,13 @@ std::map<DeemphasisMode, double> deempTaus = {
|
||||
{ DEEMP_MODE_75US, 75e-6 }
|
||||
};
|
||||
|
||||
std::map<IFNRPreset, double> ifnrTaps = {
|
||||
{ IFNR_PRESET_NOAA_APT, 9},
|
||||
{ IFNR_PRESET_VOICE, 15 },
|
||||
{ IFNR_PRESET_NARROW_BAND, 31 },
|
||||
{ IFNR_PRESET_BROADCAST, 32 }
|
||||
};
|
||||
|
||||
class RadioModule : public ModuleManager::Instance {
|
||||
public:
|
||||
RadioModule(std::string name) {
|
||||
@ -33,6 +40,10 @@ public:
|
||||
deempModes.define("50us", DEEMP_MODE_50US);
|
||||
deempModes.define("75us", DEEMP_MODE_75US);
|
||||
|
||||
ifnrPresets.define("NOAA APT", IFNR_PRESET_NOAA_APT);
|
||||
ifnrPresets.define("Voice", IFNR_PRESET_VOICE);
|
||||
ifnrPresets.define("Narrow Band", IFNR_PRESET_NARROW_BAND);
|
||||
|
||||
// Initialize the config if it doesn't exist
|
||||
bool created = false;
|
||||
config.acquire();
|
||||
@ -297,6 +308,15 @@ private:
|
||||
if (ImGui::Checkbox(("IF Noise Reduction##_radio_fmifnr_ena_" + _this->name).c_str(), &_this->FMIFNREnabled)) {
|
||||
_this->setFMIFNREnabled(_this->FMIFNREnabled);
|
||||
}
|
||||
if (_this->selectedDemodID == RADIO_DEMOD_NFM) {
|
||||
if (!_this->FMIFNREnabled && _this->enabled) { style::beginDisabled(); }
|
||||
ImGui::SameLine();
|
||||
ImGui::SetNextItemWidth(menuWidth - ImGui::GetCursorPosX());
|
||||
if (ImGui::Combo(("##_radio_fmifnr_ena_" + _this->name).c_str(), &_this->fmIFPresetId, _this->ifnrPresets.txt)) {
|
||||
_this->setIFNRPreset(_this->ifnrPresets[_this->fmIFPresetId]);
|
||||
}
|
||||
if (!_this->FMIFNREnabled && _this->enabled) { style::endDisabled(); }
|
||||
}
|
||||
}
|
||||
|
||||
// Demodulator specific menu
|
||||
@ -347,6 +367,7 @@ private:
|
||||
postProcEnabled = selectedDemod->getPostProcEnabled();
|
||||
FMIFNRAllowed = selectedDemod->getFMIFNRAllowed();
|
||||
FMIFNREnabled = false;
|
||||
fmIFPresetId = ifnrPresets.valueId(IFNR_PRESET_VOICE);
|
||||
nbAllowed = selectedDemod->getNBAllowed();
|
||||
nbEnabled = false;
|
||||
nbLevel = 0.0f;
|
||||
@ -365,7 +386,6 @@ private:
|
||||
squelchEnabled = config.conf[name][selectedDemod->getName()]["squelchEnabled"];
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("deempMode")) {
|
||||
// Upgrade to the text key
|
||||
if (!config.conf[name][selectedDemod->getName()]["deempMode"].is_string()) {
|
||||
config.conf[name][selectedDemod->getName()]["deempMode"] = deempModes.key(deempId);
|
||||
}
|
||||
@ -378,6 +398,12 @@ private:
|
||||
if (config.conf[name][selectedDemod->getName()].contains("FMIFNREnabled")) {
|
||||
FMIFNREnabled = config.conf[name][selectedDemod->getName()]["FMIFNREnabled"];
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("fmifnrPreset")) {
|
||||
std::string presetOpt = config.conf[name][selectedDemod->getName()]["fmifnrPreset"];
|
||||
if (ifnrPresets.keyExists(presetOpt)) {
|
||||
fmIFPresetId = ifnrPresets.keyId(presetOpt);
|
||||
}
|
||||
}
|
||||
if (config.conf[name][selectedDemod->getName()].contains("noiseBlankerEnabled")) {
|
||||
nbEnabled = config.conf[name][selectedDemod->getName()]["noiseBlankerEnabled"];
|
||||
}
|
||||
@ -401,6 +427,7 @@ private:
|
||||
setBandwidth(bandwidth);
|
||||
|
||||
// Configure FM IF Noise Reduction
|
||||
setIFNRPreset((selectedDemodID == RADIO_DEMOD_NFM) ? ifnrPresets[fmIFPresetId] : IFNR_PRESET_BROADCAST);
|
||||
setFMIFNREnabled(FMIFNRAllowed ? FMIFNREnabled : false);
|
||||
|
||||
// Configure notch
|
||||
@ -411,7 +438,6 @@ private:
|
||||
setSquelchEnabled(squelchEnabled);
|
||||
|
||||
// Configure noise blanker
|
||||
fmnr.block.setTapCount((selectedDemod->getIFSampleRate() < 100000.0f) ? 9 : 32);
|
||||
nb.block.setLevel(nbLevel);
|
||||
setNoiseBlankerEnabled(nbEnabled);
|
||||
|
||||
@ -555,6 +581,24 @@ private:
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
void setIFNRPreset(IFNRPreset preset) {
|
||||
// Don't save if in broadcast mode
|
||||
if (preset == IFNR_PRESET_BROADCAST) {
|
||||
if (!selectedDemod) { return; }
|
||||
fmnr.block.setTapCount(ifnrTaps[preset]);
|
||||
return;
|
||||
}
|
||||
|
||||
fmIFPresetId = ifnrPresets.valueId(preset);
|
||||
if (!selectedDemod) { return; }
|
||||
fmnr.block.setTapCount(ifnrTaps[preset]);
|
||||
|
||||
// Save config
|
||||
config.acquire();
|
||||
config.conf[name][selectedDemod->getName()]["fmifnrPreset"] = ifnrPresets.key(fmIFPresetId);
|
||||
config.release(true);
|
||||
}
|
||||
|
||||
static void vfoUserChangedBandwidthHandler(double newBw, void* ctx) {
|
||||
RadioModule* _this = (RadioModule*)ctx;
|
||||
_this->setBandwidth(newBw);
|
||||
@ -655,6 +699,7 @@ private:
|
||||
demod::Demodulator* selectedDemod = NULL;
|
||||
|
||||
OptionList<std::string, DeemphasisMode> deempModes;
|
||||
OptionList<std::string, IFNRPreset> ifnrPresets;
|
||||
|
||||
double audioSampleRate = 48000.0;
|
||||
float minBandwidth;
|
||||
@ -673,6 +718,7 @@ private:
|
||||
|
||||
bool FMIFNRAllowed;
|
||||
bool FMIFNREnabled = false;
|
||||
int fmIFPresetId;
|
||||
|
||||
bool notchEnabled = false;
|
||||
float notchPos = 0;
|
||||
|
@ -96,7 +96,7 @@ public:
|
||||
}
|
||||
return RAPIDJSON_REALLOC(originalPtr, newSize);
|
||||
}
|
||||
static void Free(void *ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); }
|
||||
static void Free(void* ptr) RAPIDJSON_NOEXCEPT { RAPIDJSON_FREE(ptr); }
|
||||
|
||||
bool operator==(const CrtAllocator&) const RAPIDJSON_NOEXCEPT {
|
||||
return true;
|
||||
@ -133,11 +133,11 @@ class MemoryPoolAllocator {
|
||||
struct ChunkHeader {
|
||||
size_t capacity; //!< Capacity of the chunk in bytes (excluding the header itself).
|
||||
size_t size; //!< Current size of allocated memory in bytes.
|
||||
ChunkHeader *next; //!< Next chunk in the linked list.
|
||||
ChunkHeader* next; //!< Next chunk in the linked list.
|
||||
};
|
||||
|
||||
struct SharedData {
|
||||
ChunkHeader *chunkHead; //!< Head of the chunk linked-list. Only the head chunk serves allocation.
|
||||
ChunkHeader* chunkHead; //!< Head of the chunk linked-list. Only the head chunk serves allocation.
|
||||
BaseAllocator* ownBaseAllocator; //!< base allocator created by this object.
|
||||
size_t refcount;
|
||||
bool ownBuffer;
|
||||
@ -146,12 +146,10 @@ class MemoryPoolAllocator {
|
||||
static const size_t SIZEOF_SHARED_DATA = RAPIDJSON_ALIGN(sizeof(SharedData));
|
||||
static const size_t SIZEOF_CHUNK_HEADER = RAPIDJSON_ALIGN(sizeof(ChunkHeader));
|
||||
|
||||
static inline ChunkHeader *GetChunkHead(SharedData *shared)
|
||||
{
|
||||
static inline ChunkHeader* GetChunkHead(SharedData* shared) {
|
||||
return reinterpret_cast<ChunkHeader*>(reinterpret_cast<uint8_t*>(shared) + SIZEOF_SHARED_DATA);
|
||||
}
|
||||
static inline uint8_t *GetChunkBuffer(SharedData *shared)
|
||||
{
|
||||
static inline uint8_t* GetChunkBuffer(SharedData* shared) {
|
||||
return reinterpret_cast<uint8_t*>(shared->chunkHead) + SIZEOF_CHUNK_HEADER;
|
||||
}
|
||||
|
||||
@ -165,12 +163,9 @@ public:
|
||||
/*! \param chunkSize The size of memory chunk. The default is kDefaultChunkSize.
|
||||
\param baseAllocator The allocator for allocating memory chunks.
|
||||
*/
|
||||
explicit
|
||||
MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) :
|
||||
chunk_capacity_(chunkSize),
|
||||
explicit MemoryPoolAllocator(size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : chunk_capacity_(chunkSize),
|
||||
baseAllocator_(baseAllocator ? baseAllocator : RAPIDJSON_NEW(BaseAllocator)()),
|
||||
shared_(static_cast<SharedData*>(baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER) : 0))
|
||||
{
|
||||
shared_(static_cast<SharedData*>(baseAllocator_ ? baseAllocator_->Malloc(SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER) : 0)) {
|
||||
RAPIDJSON_ASSERT(baseAllocator_ != 0);
|
||||
RAPIDJSON_ASSERT(shared_ != 0);
|
||||
if (baseAllocator) {
|
||||
@ -197,11 +192,9 @@ public:
|
||||
\param chunkSize The size of memory chunk. The default is kDefaultChunkSize.
|
||||
\param baseAllocator The allocator for allocating memory chunks.
|
||||
*/
|
||||
MemoryPoolAllocator(void *buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) :
|
||||
chunk_capacity_(chunkSize),
|
||||
MemoryPoolAllocator(void* buffer, size_t size, size_t chunkSize = kDefaultChunkCapacity, BaseAllocator* baseAllocator = 0) : chunk_capacity_(chunkSize),
|
||||
baseAllocator_(baseAllocator),
|
||||
shared_(static_cast<SharedData*>(AlignBuffer(buffer, size)))
|
||||
{
|
||||
shared_(static_cast<SharedData*>(AlignBuffer(buffer, size))) {
|
||||
RAPIDJSON_ASSERT(size >= SIZEOF_SHARED_DATA + SIZEOF_CHUNK_HEADER);
|
||||
shared_->chunkHead = GetChunkHead(shared_);
|
||||
shared_->chunkHead->capacity = size - SIZEOF_SHARED_DATA - SIZEOF_CHUNK_HEADER;
|
||||
@ -212,16 +205,13 @@ public:
|
||||
shared_->refcount = 1;
|
||||
}
|
||||
|
||||
MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT :
|
||||
chunk_capacity_(rhs.chunk_capacity_),
|
||||
MemoryPoolAllocator(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT : chunk_capacity_(rhs.chunk_capacity_),
|
||||
baseAllocator_(rhs.baseAllocator_),
|
||||
shared_(rhs.shared_)
|
||||
{
|
||||
shared_(rhs.shared_) {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(shared_->refcount > 0);
|
||||
++shared_->refcount;
|
||||
}
|
||||
MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
MemoryPoolAllocator& operator=(const MemoryPoolAllocator& rhs) RAPIDJSON_NOEXCEPT {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
|
||||
++rhs.shared_->refcount;
|
||||
this->~MemoryPoolAllocator();
|
||||
@ -232,16 +222,13 @@ public:
|
||||
}
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT :
|
||||
chunk_capacity_(rhs.chunk_capacity_),
|
||||
MemoryPoolAllocator(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT : chunk_capacity_(rhs.chunk_capacity_),
|
||||
baseAllocator_(rhs.baseAllocator_),
|
||||
shared_(rhs.shared_)
|
||||
{
|
||||
shared_(rhs.shared_) {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
|
||||
rhs.shared_ = 0;
|
||||
}
|
||||
MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
MemoryPoolAllocator& operator=(MemoryPoolAllocator&& rhs) RAPIDJSON_NOEXCEPT {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(rhs.shared_->refcount > 0);
|
||||
this->~MemoryPoolAllocator();
|
||||
baseAllocator_ = rhs.baseAllocator_;
|
||||
@ -265,7 +252,7 @@ public:
|
||||
return;
|
||||
}
|
||||
Clear();
|
||||
BaseAllocator *a = shared_->ownBaseAllocator;
|
||||
BaseAllocator* a = shared_->ownBaseAllocator;
|
||||
if (shared_->ownBuffer) {
|
||||
baseAllocator_->Free(shared_);
|
||||
}
|
||||
@ -327,7 +314,7 @@ public:
|
||||
if (!AddChunk(chunk_capacity_ > size ? chunk_capacity_ : size))
|
||||
return NULL;
|
||||
|
||||
void *buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size;
|
||||
void* buffer = GetChunkBuffer(shared_) + shared_->chunkHead->size;
|
||||
shared_->chunkHead->size += size;
|
||||
return buffer;
|
||||
}
|
||||
@ -368,7 +355,7 @@ public:
|
||||
}
|
||||
|
||||
//! Frees a memory block (concept Allocator)
|
||||
static void Free(void *ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing
|
||||
static void Free(void* ptr) RAPIDJSON_NOEXCEPT { (void)ptr; } // Do nothing
|
||||
|
||||
//! Compare (equality) with another MemoryPoolAllocator
|
||||
bool operator==(const MemoryPoolAllocator& rhs) const RAPIDJSON_NOEXCEPT {
|
||||
@ -400,8 +387,7 @@ private:
|
||||
return false;
|
||||
}
|
||||
|
||||
static inline void* AlignBuffer(void* buf, size_t &size)
|
||||
{
|
||||
static inline void* AlignBuffer(void* buf, size_t& size) {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(buf != 0);
|
||||
const uintptr_t mask = sizeof(void*) - 1;
|
||||
const uintptr_t ubuf = reinterpret_cast<uintptr_t>(buf);
|
||||
@ -416,36 +402,29 @@ private:
|
||||
|
||||
size_t chunk_capacity_; //!< The minimum capacity of chunk when they are allocated.
|
||||
BaseAllocator* baseAllocator_; //!< base allocator for allocating memory chunks.
|
||||
SharedData *shared_; //!< The shared data of the allocator
|
||||
SharedData* shared_; //!< The shared data of the allocator
|
||||
};
|
||||
|
||||
namespace internal {
|
||||
template<typename, typename = void>
|
||||
struct IsRefCounted :
|
||||
public FalseType
|
||||
{ };
|
||||
template<typename T>
|
||||
struct IsRefCounted<T, typename internal::EnableIfCond<T::kRefCounted>::Type> :
|
||||
public TrueType
|
||||
{ };
|
||||
template <typename, typename = void>
|
||||
struct IsRefCounted : public FalseType {};
|
||||
template <typename T>
|
||||
struct IsRefCounted<T, typename internal::EnableIfCond<T::kRefCounted>::Type> : public TrueType {};
|
||||
}
|
||||
|
||||
template<typename T, typename A>
|
||||
inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n)
|
||||
{
|
||||
template <typename T, typename A>
|
||||
inline T* Realloc(A& a, T* old_p, size_t old_n, size_t new_n) {
|
||||
RAPIDJSON_NOEXCEPT_ASSERT(old_n <= SIZE_MAX / sizeof(T) && new_n <= SIZE_MAX / sizeof(T));
|
||||
return static_cast<T*>(a.Realloc(old_p, old_n * sizeof(T), new_n * sizeof(T)));
|
||||
}
|
||||
|
||||
template<typename T, typename A>
|
||||
inline T *Malloc(A& a, size_t n = 1)
|
||||
{
|
||||
template <typename T, typename A>
|
||||
inline T* Malloc(A& a, size_t n = 1) {
|
||||
return Realloc<T, A>(a, NULL, 0, n);
|
||||
}
|
||||
|
||||
template<typename T, typename A>
|
||||
inline void Free(A& a, T *p, size_t n = 1)
|
||||
{
|
||||
template <typename T, typename A>
|
||||
inline void Free(A& a, T* p, size_t n = 1) {
|
||||
static_cast<void>(Realloc<T, A>(a, p, n, 0));
|
||||
}
|
||||
|
||||
@ -455,9 +434,7 @@ RAPIDJSON_DIAG_OFF(effc++) // std::allocator can safely be inherited
|
||||
#endif
|
||||
|
||||
template <typename T, typename BaseAllocator = CrtAllocator>
|
||||
class StdAllocator :
|
||||
public std::allocator<T>
|
||||
{
|
||||
class StdAllocator : public std::allocator<T> {
|
||||
typedef std::allocator<T> allocator_type;
|
||||
#if RAPIDJSON_HAS_CXX11
|
||||
typedef std::allocator_traits<allocator_type> traits_type;
|
||||
@ -468,27 +445,19 @@ class StdAllocator :
|
||||
public:
|
||||
typedef BaseAllocator BaseAllocatorType;
|
||||
|
||||
StdAllocator() RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(),
|
||||
baseAllocator_()
|
||||
{ }
|
||||
StdAllocator() RAPIDJSON_NOEXCEPT : allocator_type(),
|
||||
baseAllocator_() {}
|
||||
|
||||
StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_)
|
||||
{ }
|
||||
StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_) {}
|
||||
|
||||
template<typename U>
|
||||
StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_)
|
||||
{ }
|
||||
template <typename U>
|
||||
StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_) {}
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(std::move(rhs)),
|
||||
baseAllocator_(std::move(rhs.baseAllocator_))
|
||||
{ }
|
||||
StdAllocator(StdAllocator&& rhs) RAPIDJSON_NOEXCEPT : allocator_type(std::move(rhs)),
|
||||
baseAllocator_(std::move(rhs.baseAllocator_)) {}
|
||||
#endif
|
||||
#if RAPIDJSON_HAS_CXX11
|
||||
using propagate_on_container_move_assignment = std::true_type;
|
||||
@ -496,15 +465,12 @@ public:
|
||||
#endif
|
||||
|
||||
/* implicit */
|
||||
StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(),
|
||||
baseAllocator_(allocator)
|
||||
{ }
|
||||
StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT : allocator_type(),
|
||||
baseAllocator_(allocator) {}
|
||||
|
||||
~StdAllocator() RAPIDJSON_NOEXCEPT
|
||||
{ }
|
||||
~StdAllocator() RAPIDJSON_NOEXCEPT {}
|
||||
|
||||
template<typename U>
|
||||
template <typename U>
|
||||
struct rebind {
|
||||
typedef StdAllocator<U, BaseAllocator> other;
|
||||
};
|
||||
@ -518,30 +484,25 @@ public:
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11
|
||||
|
||||
typedef typename std::add_lvalue_reference<value_type>::type &reference;
|
||||
typedef typename std::add_lvalue_reference<typename std::add_const<value_type>::type>::type &const_reference;
|
||||
typedef typename std::add_lvalue_reference<value_type>::type& reference;
|
||||
typedef typename std::add_lvalue_reference<typename std::add_const<value_type>::type>::type& const_reference;
|
||||
|
||||
pointer address(reference r) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
pointer address(reference r) const RAPIDJSON_NOEXCEPT {
|
||||
return std::addressof(r);
|
||||
}
|
||||
const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT {
|
||||
return std::addressof(r);
|
||||
}
|
||||
|
||||
size_type max_size() const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
size_type max_size() const RAPIDJSON_NOEXCEPT {
|
||||
return traits_type::max_size(*this);
|
||||
}
|
||||
|
||||
template <typename ...Args>
|
||||
void construct(pointer p, Args&&... args)
|
||||
{
|
||||
template <typename... Args>
|
||||
void construct(pointer p, Args&&... args) {
|
||||
traits_type::construct(*this, p, std::forward<Args>(args)...);
|
||||
}
|
||||
void destroy(pointer p)
|
||||
{
|
||||
void destroy(pointer p) {
|
||||
traits_type::destroy(*this, p);
|
||||
}
|
||||
|
||||
@ -550,48 +511,39 @@ public:
|
||||
typedef typename allocator_type::reference reference;
|
||||
typedef typename allocator_type::const_reference const_reference;
|
||||
|
||||
pointer address(reference r) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
pointer address(reference r) const RAPIDJSON_NOEXCEPT {
|
||||
return allocator_type::address(r);
|
||||
}
|
||||
const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
const_pointer address(const_reference r) const RAPIDJSON_NOEXCEPT {
|
||||
return allocator_type::address(r);
|
||||
}
|
||||
|
||||
size_type max_size() const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
size_type max_size() const RAPIDJSON_NOEXCEPT {
|
||||
return allocator_type::max_size();
|
||||
}
|
||||
|
||||
void construct(pointer p, const_reference r)
|
||||
{
|
||||
void construct(pointer p, const_reference r) {
|
||||
allocator_type::construct(p, r);
|
||||
}
|
||||
void destroy(pointer p)
|
||||
{
|
||||
void destroy(pointer p) {
|
||||
allocator_type::destroy(p);
|
||||
}
|
||||
|
||||
#endif // !RAPIDJSON_HAS_CXX11
|
||||
|
||||
template <typename U>
|
||||
U* allocate(size_type n = 1, const void* = 0)
|
||||
{
|
||||
U* allocate(size_type n = 1, const void* = 0) {
|
||||
return RAPIDJSON_NAMESPACE::Malloc<U>(baseAllocator_, n);
|
||||
}
|
||||
template <typename U>
|
||||
void deallocate(U* p, size_type n = 1)
|
||||
{
|
||||
void deallocate(U* p, size_type n = 1) {
|
||||
RAPIDJSON_NAMESPACE::Free<U>(baseAllocator_, p, n);
|
||||
}
|
||||
|
||||
pointer allocate(size_type n = 1, const void* = 0)
|
||||
{
|
||||
pointer allocate(size_type n = 1, const void* = 0) {
|
||||
return allocate<value_type>(n);
|
||||
}
|
||||
void deallocate(pointer p, size_type n = 1)
|
||||
{
|
||||
void deallocate(pointer p, size_type n = 1) {
|
||||
deallocate<value_type>(p, n);
|
||||
}
|
||||
|
||||
@ -599,30 +551,25 @@ public:
|
||||
using is_always_equal = std::is_empty<BaseAllocator>;
|
||||
#endif
|
||||
|
||||
template<typename U>
|
||||
bool operator==(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
template <typename U>
|
||||
bool operator==(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT {
|
||||
return baseAllocator_ == rhs.baseAllocator_;
|
||||
}
|
||||
template<typename U>
|
||||
bool operator!=(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
template <typename U>
|
||||
bool operator!=(const StdAllocator<U, BaseAllocator>& rhs) const RAPIDJSON_NOEXCEPT {
|
||||
return !operator==(rhs);
|
||||
}
|
||||
|
||||
//! rapidjson Allocator concept
|
||||
static const bool kNeedFree = BaseAllocator::kNeedFree;
|
||||
static const bool kRefCounted = internal::IsRefCounted<BaseAllocator>::Value;
|
||||
void* Malloc(size_t size)
|
||||
{
|
||||
void* Malloc(size_t size) {
|
||||
return baseAllocator_.Malloc(size);
|
||||
}
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
|
||||
{
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
|
||||
return baseAllocator_.Realloc(originalPtr, originalSize, newSize);
|
||||
}
|
||||
static void Free(void *ptr) RAPIDJSON_NOEXCEPT
|
||||
{
|
||||
static void Free(void* ptr) RAPIDJSON_NOEXCEPT {
|
||||
BaseAllocator::Free(ptr);
|
||||
}
|
||||
|
||||
@ -635,40 +582,29 @@ private:
|
||||
|
||||
#if !RAPIDJSON_HAS_CXX17 // std::allocator<void> deprecated in C++17
|
||||
template <typename BaseAllocator>
|
||||
class StdAllocator<void, BaseAllocator> :
|
||||
public std::allocator<void>
|
||||
{
|
||||
class StdAllocator<void, BaseAllocator> : public std::allocator<void> {
|
||||
typedef std::allocator<void> allocator_type;
|
||||
|
||||
public:
|
||||
typedef BaseAllocator BaseAllocatorType;
|
||||
|
||||
StdAllocator() RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(),
|
||||
baseAllocator_()
|
||||
{ }
|
||||
StdAllocator() RAPIDJSON_NOEXCEPT : allocator_type(),
|
||||
baseAllocator_() {}
|
||||
|
||||
StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_)
|
||||
{ }
|
||||
StdAllocator(const StdAllocator& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_) {}
|
||||
|
||||
template<typename U>
|
||||
StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_)
|
||||
{ }
|
||||
template <typename U>
|
||||
StdAllocator(const StdAllocator<U, BaseAllocator>& rhs) RAPIDJSON_NOEXCEPT : allocator_type(rhs),
|
||||
baseAllocator_(rhs.baseAllocator_) {}
|
||||
|
||||
/* implicit */
|
||||
StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT :
|
||||
allocator_type(),
|
||||
baseAllocator_(allocator)
|
||||
{ }
|
||||
StdAllocator(const BaseAllocator& allocator) RAPIDJSON_NOEXCEPT : allocator_type(),
|
||||
baseAllocator_(allocator) {}
|
||||
|
||||
~StdAllocator() RAPIDJSON_NOEXCEPT
|
||||
{ }
|
||||
~StdAllocator() RAPIDJSON_NOEXCEPT {}
|
||||
|
||||
template<typename U>
|
||||
template <typename U>
|
||||
struct rebind {
|
||||
typedef StdAllocator<U, BaseAllocator> other;
|
||||
};
|
||||
|
@ -35,22 +35,22 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
/*!
|
||||
\tparam InputStream Any stream that implements Stream Concept
|
||||
*/
|
||||
template <typename InputStream, typename Encoding = UTF8<> >
|
||||
template <typename InputStream, typename Encoding = UTF8<>>
|
||||
class CursorStreamWrapper : public GenericStreamWrapper<InputStream, Encoding> {
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
CursorStreamWrapper(InputStream& is):
|
||||
GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}
|
||||
CursorStreamWrapper(InputStream& is) : GenericStreamWrapper<InputStream, Encoding>(is), line_(1), col_(0) {}
|
||||
|
||||
// counting line and column number
|
||||
Ch Take() {
|
||||
Ch ch = this->is_.Take();
|
||||
if(ch == '\n') {
|
||||
line_ ++;
|
||||
if (ch == '\n') {
|
||||
line_++;
|
||||
col_ = 0;
|
||||
} else {
|
||||
col_ ++;
|
||||
}
|
||||
else {
|
||||
col_++;
|
||||
}
|
||||
return ch;
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
@ -38,6 +38,7 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
template <typename Encoding, typename InputByteStream>
|
||||
class EncodedInputStream {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
|
||||
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
@ -46,14 +47,24 @@ public:
|
||||
}
|
||||
|
||||
Ch Peek() const { return current_; }
|
||||
Ch Take() { Ch c = current_; current_ = Encoding::Take(is_); return c; }
|
||||
Ch Take() {
|
||||
Ch c = current_;
|
||||
current_ = Encoding::Take(is_);
|
||||
return c;
|
||||
}
|
||||
size_t Tell() const { return is_.Tell(); }
|
||||
|
||||
// Not implemented
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
EncodedInputStream(const EncodedInputStream&);
|
||||
@ -99,6 +110,7 @@ private:
|
||||
template <typename Encoding, typename OutputByteStream>
|
||||
class EncodedOutputStream {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
|
||||
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
@ -111,11 +123,26 @@ public:
|
||||
void Flush() { os_.Flush(); }
|
||||
|
||||
// Not implemented
|
||||
Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
|
||||
Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
|
||||
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch Peek() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
Ch Take() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t Tell() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
EncodedOutputStream(const EncodedOutputStream&);
|
||||
@ -134,6 +161,7 @@ private:
|
||||
template <typename CharType, typename InputByteStream>
|
||||
class AutoUTFInputStream {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename InputByteStream::Ch) == 1);
|
||||
|
||||
public:
|
||||
typedef CharType Ch;
|
||||
|
||||
@ -154,14 +182,24 @@ public:
|
||||
bool HasBOM() const { return hasBOM_; }
|
||||
|
||||
Ch Peek() const { return current_; }
|
||||
Ch Take() { Ch c = current_; current_ = takeFunc_(*is_); return c; }
|
||||
Ch Take() {
|
||||
Ch c = current_;
|
||||
current_ = takeFunc_(*is_);
|
||||
return c;
|
||||
}
|
||||
size_t Tell() const { return is_->Tell(); }
|
||||
|
||||
// Not implemented
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
AutoUTFInputStream(const AutoUTFInputStream&);
|
||||
@ -176,17 +214,47 @@ private:
|
||||
// FF FE UTF-16LE
|
||||
// EF BB BF UTF-8
|
||||
|
||||
const unsigned char* c = reinterpret_cast<const unsigned char *>(is_->Peek4());
|
||||
const unsigned char* c = reinterpret_cast<const unsigned char*>(is_->Peek4());
|
||||
if (!c)
|
||||
return;
|
||||
|
||||
unsigned bom = static_cast<unsigned>(c[0] | (c[1] << 8) | (c[2] << 16) | (c[3] << 24));
|
||||
hasBOM_ = false;
|
||||
if (bom == 0xFFFE0000) { type_ = kUTF32BE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
|
||||
else if (bom == 0x0000FEFF) { type_ = kUTF32LE; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); is_->Take(); }
|
||||
else if ((bom & 0xFFFF) == 0xFFFE) { type_ = kUTF16BE; hasBOM_ = true; is_->Take(); is_->Take(); }
|
||||
else if ((bom & 0xFFFF) == 0xFEFF) { type_ = kUTF16LE; hasBOM_ = true; is_->Take(); is_->Take(); }
|
||||
else if ((bom & 0xFFFFFF) == 0xBFBBEF) { type_ = kUTF8; hasBOM_ = true; is_->Take(); is_->Take(); is_->Take(); }
|
||||
if (bom == 0xFFFE0000) {
|
||||
type_ = kUTF32BE;
|
||||
hasBOM_ = true;
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
}
|
||||
else if (bom == 0x0000FEFF) {
|
||||
type_ = kUTF32LE;
|
||||
hasBOM_ = true;
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
}
|
||||
else if ((bom & 0xFFFF) == 0xFFFE) {
|
||||
type_ = kUTF16BE;
|
||||
hasBOM_ = true;
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
}
|
||||
else if ((bom & 0xFFFF) == 0xFEFF) {
|
||||
type_ = kUTF16LE;
|
||||
hasBOM_ = true;
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
}
|
||||
else if ((bom & 0xFFFFFF) == 0xBFBBEF) {
|
||||
type_ = kUTF8;
|
||||
hasBOM_ = true;
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
is_->Take();
|
||||
}
|
||||
|
||||
// RFC 4627: Section 3
|
||||
// "Since the first two characters of a JSON text will always be ASCII
|
||||
@ -202,12 +270,23 @@ private:
|
||||
if (!hasBOM_) {
|
||||
int pattern = (c[0] ? 1 : 0) | (c[1] ? 2 : 0) | (c[2] ? 4 : 0) | (c[3] ? 8 : 0);
|
||||
switch (pattern) {
|
||||
case 0x08: type_ = kUTF32BE; break;
|
||||
case 0x0A: type_ = kUTF16BE; break;
|
||||
case 0x01: type_ = kUTF32LE; break;
|
||||
case 0x05: type_ = kUTF16LE; break;
|
||||
case 0x0F: type_ = kUTF8; break;
|
||||
default: break; // Use type defined by user.
|
||||
case 0x08:
|
||||
type_ = kUTF32BE;
|
||||
break;
|
||||
case 0x0A:
|
||||
type_ = kUTF16BE;
|
||||
break;
|
||||
case 0x01:
|
||||
type_ = kUTF32LE;
|
||||
break;
|
||||
case 0x05:
|
||||
type_ = kUTF16LE;
|
||||
break;
|
||||
case 0x0F:
|
||||
type_ = kUTF8;
|
||||
break;
|
||||
default:
|
||||
break; // Use type defined by user.
|
||||
}
|
||||
}
|
||||
|
||||
@ -232,6 +311,7 @@ private:
|
||||
template <typename CharType, typename OutputByteStream>
|
||||
class AutoUTFOutputStream {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputByteStream::Ch) == 1);
|
||||
|
||||
public:
|
||||
typedef CharType Ch;
|
||||
|
||||
@ -261,11 +341,26 @@ public:
|
||||
void Flush() { os_->Flush(); }
|
||||
|
||||
// Not implemented
|
||||
Ch Peek() const { RAPIDJSON_ASSERT(false); return 0;}
|
||||
Ch Take() { RAPIDJSON_ASSERT(false); return 0;}
|
||||
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch Peek() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
Ch Take() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t Tell() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
AutoUTFOutputStream(const AutoUTFOutputStream&);
|
||||
|
@ -92,13 +92,13 @@ concept Encoding {
|
||||
\tparam CharType Code unit for storing 8-bit UTF-8 data. Default is char.
|
||||
\note implements Encoding concept
|
||||
*/
|
||||
template<typename CharType = char>
|
||||
template <typename CharType = char>
|
||||
struct UTF8 {
|
||||
typedef CharType Ch;
|
||||
|
||||
enum { supportUnicode = 1 };
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void Encode(OutputStream& os, unsigned codepoint) {
|
||||
if (codepoint <= 0x7F)
|
||||
os.Put(static_cast<Ch>(codepoint & 0xFF));
|
||||
@ -120,7 +120,7 @@ struct UTF8 {
|
||||
}
|
||||
}
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
|
||||
if (codepoint <= 0x7F)
|
||||
PutUnsafe(os, static_cast<Ch>(codepoint & 0xFF));
|
||||
@ -144,9 +144,13 @@ struct UTF8 {
|
||||
|
||||
template <typename InputStream>
|
||||
static bool Decode(InputStream& is, unsigned* codepoint) {
|
||||
#define RAPIDJSON_COPY() c = is.Take(); *codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
|
||||
#define RAPIDJSON_COPY() \
|
||||
c = is.Take(); \
|
||||
*codepoint = (*codepoint << 6) | (static_cast<unsigned char>(c) & 0x3Fu)
|
||||
#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
|
||||
#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70)
|
||||
#define RAPIDJSON_TAIL() \
|
||||
RAPIDJSON_COPY(); \
|
||||
RAPIDJSON_TRANS(0x70)
|
||||
typename InputStream::Ch c = is.Take();
|
||||
if (!(c & 0x80)) {
|
||||
*codepoint = static_cast<unsigned char>(c);
|
||||
@ -156,19 +160,48 @@ struct UTF8 {
|
||||
unsigned char type = GetRange(static_cast<unsigned char>(c));
|
||||
if (type >= 32) {
|
||||
*codepoint = 0;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
*codepoint = (0xFFu >> type) & static_cast<unsigned char>(c);
|
||||
}
|
||||
bool result = true;
|
||||
switch (type) {
|
||||
case 2: RAPIDJSON_TAIL(); return result;
|
||||
case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result;
|
||||
case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result;
|
||||
case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
default: return false;
|
||||
case 2:
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 3:
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 4:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x50);
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 5:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x10);
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 6:
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 10:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x20);
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 11:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x60);
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#undef RAPIDJSON_COPY
|
||||
#undef RAPIDJSON_TRANS
|
||||
@ -179,7 +212,9 @@ struct UTF8 {
|
||||
static bool Validate(InputStream& is, OutputStream& os) {
|
||||
#define RAPIDJSON_COPY() os.Put(c = is.Take())
|
||||
#define RAPIDJSON_TRANS(mask) result &= ((GetRange(static_cast<unsigned char>(c)) & mask) != 0)
|
||||
#define RAPIDJSON_TAIL() RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x70)
|
||||
#define RAPIDJSON_TAIL() \
|
||||
RAPIDJSON_COPY(); \
|
||||
RAPIDJSON_TRANS(0x70)
|
||||
Ch c;
|
||||
RAPIDJSON_COPY();
|
||||
if (!(c & 0x80))
|
||||
@ -187,14 +222,42 @@ struct UTF8 {
|
||||
|
||||
bool result = true;
|
||||
switch (GetRange(static_cast<unsigned char>(c))) {
|
||||
case 2: RAPIDJSON_TAIL(); return result;
|
||||
case 3: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 4: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x50); RAPIDJSON_TAIL(); return result;
|
||||
case 5: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x10); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 6: RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
case 10: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x20); RAPIDJSON_TAIL(); return result;
|
||||
case 11: RAPIDJSON_COPY(); RAPIDJSON_TRANS(0x60); RAPIDJSON_TAIL(); RAPIDJSON_TAIL(); return result;
|
||||
default: return false;
|
||||
case 2:
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 3:
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 4:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x50);
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 5:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x10);
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 6:
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 10:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x20);
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
case 11:
|
||||
RAPIDJSON_COPY();
|
||||
RAPIDJSON_TRANS(0x60);
|
||||
RAPIDJSON_TAIL();
|
||||
RAPIDJSON_TAIL();
|
||||
return result;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
#undef RAPIDJSON_COPY
|
||||
#undef RAPIDJSON_TRANS
|
||||
@ -205,16 +268,262 @@ struct UTF8 {
|
||||
// Referring to DFA of http://bjoern.hoehrmann.de/utf-8/decoder/dfa/
|
||||
// With new mapping 1 -> 0x10, 7 -> 0x20, 9 -> 0x40, such that AND operation can test multiple types.
|
||||
static const unsigned char type[] = {
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
|
||||
0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,0x10,
|
||||
0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,0x20,
|
||||
8,8,2,2,2,2,2,2,2,2,2,2,2,2,2,2, 2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,2,
|
||||
10,3,3,3,3,3,3,3,3,3,3,3,3,4,3,3, 11,6,6,6,5,8,8,8,8,8,8,8,8,8,8,8,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x10,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x40,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
0x20,
|
||||
8,
|
||||
8,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
2,
|
||||
10,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
3,
|
||||
4,
|
||||
3,
|
||||
3,
|
||||
11,
|
||||
6,
|
||||
6,
|
||||
6,
|
||||
5,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
8,
|
||||
};
|
||||
return type[c];
|
||||
}
|
||||
@ -265,14 +574,14 @@ struct UTF8 {
|
||||
\note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness.
|
||||
For streaming, use UTF16LE and UTF16BE, which handle endianness.
|
||||
*/
|
||||
template<typename CharType = wchar_t>
|
||||
template <typename CharType = wchar_t>
|
||||
struct UTF16 {
|
||||
typedef CharType Ch;
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 2);
|
||||
|
||||
enum { supportUnicode = 1 };
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void Encode(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
|
||||
if (codepoint <= 0xFFFF) {
|
||||
@ -288,7 +597,7 @@ struct UTF16 {
|
||||
}
|
||||
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 2);
|
||||
if (codepoint <= 0xFFFF) {
|
||||
@ -338,7 +647,7 @@ struct UTF16 {
|
||||
};
|
||||
|
||||
//! UTF-16 little endian encoding.
|
||||
template<typename CharType = wchar_t>
|
||||
template <typename CharType = wchar_t>
|
||||
struct UTF16LE : UTF16<CharType> {
|
||||
template <typename InputByteStream>
|
||||
static CharType TakeBOM(InputByteStream& is) {
|
||||
@ -371,7 +680,7 @@ struct UTF16LE : UTF16<CharType> {
|
||||
};
|
||||
|
||||
//! UTF-16 big endian encoding.
|
||||
template<typename CharType = wchar_t>
|
||||
template <typename CharType = wchar_t>
|
||||
struct UTF16BE : UTF16<CharType> {
|
||||
template <typename InputByteStream>
|
||||
static CharType TakeBOM(InputByteStream& is) {
|
||||
@ -414,21 +723,21 @@ struct UTF16BE : UTF16<CharType> {
|
||||
\note For in-memory access, no need to concern endianness. The code units and code points are represented by CPU's endianness.
|
||||
For streaming, use UTF32LE and UTF32BE, which handle endianness.
|
||||
*/
|
||||
template<typename CharType = unsigned>
|
||||
template <typename CharType = unsigned>
|
||||
struct UTF32 {
|
||||
typedef CharType Ch;
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(Ch) >= 4);
|
||||
|
||||
enum { supportUnicode = 1 };
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void Encode(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4);
|
||||
RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
|
||||
os.Put(codepoint);
|
||||
}
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(typename OutputStream::Ch) >= 4);
|
||||
RAPIDJSON_ASSERT(codepoint <= 0x10FFFF);
|
||||
@ -453,7 +762,7 @@ struct UTF32 {
|
||||
};
|
||||
|
||||
//! UTF-32 little endian enocoding.
|
||||
template<typename CharType = unsigned>
|
||||
template <typename CharType = unsigned>
|
||||
struct UTF32LE : UTF32<CharType> {
|
||||
template <typename InputByteStream>
|
||||
static CharType TakeBOM(InputByteStream& is) {
|
||||
@ -492,7 +801,7 @@ struct UTF32LE : UTF32<CharType> {
|
||||
};
|
||||
|
||||
//! UTF-32 big endian encoding.
|
||||
template<typename CharType = unsigned>
|
||||
template <typename CharType = unsigned>
|
||||
struct UTF32BE : UTF32<CharType> {
|
||||
template <typename InputByteStream>
|
||||
static CharType TakeBOM(InputByteStream& is) {
|
||||
@ -538,19 +847,19 @@ struct UTF32BE : UTF32<CharType> {
|
||||
\tparam CharType Code unit for storing 7-bit ASCII data. Default is char.
|
||||
\note implements Encoding concept
|
||||
*/
|
||||
template<typename CharType = char>
|
||||
template <typename CharType = char>
|
||||
struct ASCII {
|
||||
typedef CharType Ch;
|
||||
|
||||
enum { supportUnicode = 0 };
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void Encode(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_ASSERT(codepoint <= 0x7F);
|
||||
os.Put(static_cast<Ch>(codepoint & 0xFF));
|
||||
}
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
|
||||
RAPIDJSON_ASSERT(codepoint <= 0x7F);
|
||||
PutUnsafe(os, static_cast<Ch>(codepoint & 0xFF));
|
||||
@ -611,7 +920,7 @@ enum UTFType {
|
||||
//! Dynamically select encoding according to stream's runtime-specified UTF encoding type.
|
||||
/*! \note This class can be used with AutoUTFInputtStream and AutoUTFOutputStream, which provides GetType().
|
||||
*/
|
||||
template<typename CharType>
|
||||
template <typename CharType>
|
||||
struct AutoUTF {
|
||||
typedef CharType Ch;
|
||||
|
||||
@ -619,14 +928,14 @@ struct AutoUTF {
|
||||
|
||||
#define RAPIDJSON_ENCODINGS_FUNC(x) UTF8<Ch>::x, UTF16LE<Ch>::x, UTF16BE<Ch>::x, UTF32LE<Ch>::x, UTF32BE<Ch>::x
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE void Encode(OutputStream& os, unsigned codepoint) {
|
||||
typedef void (*EncodeFunc)(OutputStream&, unsigned);
|
||||
static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(Encode) };
|
||||
(*f[os.GetType()])(os, codepoint);
|
||||
}
|
||||
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE void EncodeUnsafe(OutputStream& os, unsigned codepoint) {
|
||||
typedef void (*EncodeFunc)(OutputStream&, unsigned);
|
||||
static const EncodeFunc f[] = { RAPIDJSON_ENCODINGS_FUNC(EncodeUnsafe) };
|
||||
@ -654,10 +963,10 @@ struct AutoUTF {
|
||||
// Transcoder
|
||||
|
||||
//! Encoding conversion.
|
||||
template<typename SourceEncoding, typename TargetEncoding>
|
||||
template <typename SourceEncoding, typename TargetEncoding>
|
||||
struct Transcoder {
|
||||
//! Take one Unicode codepoint from source encoding, convert it to target encoding and put it to the output stream.
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) {
|
||||
unsigned codepoint;
|
||||
if (!SourceEncoding::Decode(is, &codepoint))
|
||||
@ -666,7 +975,7 @@ struct Transcoder {
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) {
|
||||
unsigned codepoint;
|
||||
if (!SourceEncoding::Decode(is, &codepoint))
|
||||
@ -676,32 +985,32 @@ struct Transcoder {
|
||||
}
|
||||
|
||||
//! Validate one Unicode codepoint from an encoded stream.
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
|
||||
return Transcode(is, os); // Since source/target encoding is different, must transcode.
|
||||
}
|
||||
};
|
||||
|
||||
// Forward declaration.
|
||||
template<typename Stream>
|
||||
template <typename Stream>
|
||||
inline void PutUnsafe(Stream& stream, typename Stream::Ch c);
|
||||
|
||||
//! Specialization of Transcoder with same source and target encoding.
|
||||
template<typename Encoding>
|
||||
template <typename Encoding>
|
||||
struct Transcoder<Encoding, Encoding> {
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool Transcode(InputStream& is, OutputStream& os) {
|
||||
os.Put(is.Take()); // Just copy one code unit. This semantic is different from primary template class.
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool TranscodeUnsafe(InputStream& is, OutputStream& os) {
|
||||
PutUnsafe(os, is.Take()); // Just copy one code unit. This semantic is different from primary template class.
|
||||
return true;
|
||||
}
|
||||
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE bool Validate(InputStream& is, OutputStream& os) {
|
||||
return Encoding::Validate(is, os); // source/target encoding are the same
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
RAPIDJSON_DIAG_OFF(covered-switch-default)
|
||||
RAPIDJSON_DIAG_OFF(switch - enum)
|
||||
RAPIDJSON_DIAG_OFF(covered - switch - default)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -35,33 +35,52 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
*/
|
||||
inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErrorCode) {
|
||||
switch (parseErrorCode) {
|
||||
case kParseErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
|
||||
case kParseErrorNone:
|
||||
return RAPIDJSON_ERROR_STRING("No error.");
|
||||
|
||||
case kParseErrorDocumentEmpty: return RAPIDJSON_ERROR_STRING("The document is empty.");
|
||||
case kParseErrorDocumentRootNotSingular: return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
|
||||
case kParseErrorDocumentEmpty:
|
||||
return RAPIDJSON_ERROR_STRING("The document is empty.");
|
||||
case kParseErrorDocumentRootNotSingular:
|
||||
return RAPIDJSON_ERROR_STRING("The document root must not be followed by other values.");
|
||||
|
||||
case kParseErrorValueInvalid: return RAPIDJSON_ERROR_STRING("Invalid value.");
|
||||
case kParseErrorValueInvalid:
|
||||
return RAPIDJSON_ERROR_STRING("Invalid value.");
|
||||
|
||||
case kParseErrorObjectMissName: return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
|
||||
case kParseErrorObjectMissColon: return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
|
||||
case kParseErrorObjectMissCommaOrCurlyBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
|
||||
case kParseErrorObjectMissName:
|
||||
return RAPIDJSON_ERROR_STRING("Missing a name for object member.");
|
||||
case kParseErrorObjectMissColon:
|
||||
return RAPIDJSON_ERROR_STRING("Missing a colon after a name of object member.");
|
||||
case kParseErrorObjectMissCommaOrCurlyBracket:
|
||||
return RAPIDJSON_ERROR_STRING("Missing a comma or '}' after an object member.");
|
||||
|
||||
case kParseErrorArrayMissCommaOrSquareBracket: return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
|
||||
case kParseErrorArrayMissCommaOrSquareBracket:
|
||||
return RAPIDJSON_ERROR_STRING("Missing a comma or ']' after an array element.");
|
||||
|
||||
case kParseErrorStringUnicodeEscapeInvalidHex: return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
|
||||
case kParseErrorStringUnicodeSurrogateInvalid: return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
|
||||
case kParseErrorStringEscapeInvalid: return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
|
||||
case kParseErrorStringMissQuotationMark: return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
|
||||
case kParseErrorStringInvalidEncoding: return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
|
||||
case kParseErrorStringUnicodeEscapeInvalidHex:
|
||||
return RAPIDJSON_ERROR_STRING("Incorrect hex digit after \\u escape in string.");
|
||||
case kParseErrorStringUnicodeSurrogateInvalid:
|
||||
return RAPIDJSON_ERROR_STRING("The surrogate pair in string is invalid.");
|
||||
case kParseErrorStringEscapeInvalid:
|
||||
return RAPIDJSON_ERROR_STRING("Invalid escape character in string.");
|
||||
case kParseErrorStringMissQuotationMark:
|
||||
return RAPIDJSON_ERROR_STRING("Missing a closing quotation mark in string.");
|
||||
case kParseErrorStringInvalidEncoding:
|
||||
return RAPIDJSON_ERROR_STRING("Invalid encoding in string.");
|
||||
|
||||
case kParseErrorNumberTooBig: return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
|
||||
case kParseErrorNumberMissFraction: return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
|
||||
case kParseErrorNumberMissExponent: return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
|
||||
case kParseErrorNumberTooBig:
|
||||
return RAPIDJSON_ERROR_STRING("Number too big to be stored in double.");
|
||||
case kParseErrorNumberMissFraction:
|
||||
return RAPIDJSON_ERROR_STRING("Miss fraction part in number.");
|
||||
case kParseErrorNumberMissExponent:
|
||||
return RAPIDJSON_ERROR_STRING("Miss exponent in number.");
|
||||
|
||||
case kParseErrorTermination: return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
|
||||
case kParseErrorUnspecificSyntaxError: return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
|
||||
case kParseErrorTermination:
|
||||
return RAPIDJSON_ERROR_STRING("Terminate parsing due to Handler error.");
|
||||
case kParseErrorUnspecificSyntaxError:
|
||||
return RAPIDJSON_ERROR_STRING("Unspecific syntax error.");
|
||||
|
||||
default: return RAPIDJSON_ERROR_STRING("Unknown error.");
|
||||
default:
|
||||
return RAPIDJSON_ERROR_STRING("Unknown error.");
|
||||
}
|
||||
}
|
||||
|
||||
@ -75,41 +94,69 @@ inline const RAPIDJSON_ERROR_CHARTYPE* GetParseError_En(ParseErrorCode parseErro
|
||||
*/
|
||||
inline const RAPIDJSON_ERROR_CHARTYPE* GetValidateError_En(ValidateErrorCode validateErrorCode) {
|
||||
switch (validateErrorCode) {
|
||||
case kValidateErrors: return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred");
|
||||
case kValidateErrorNone: return RAPIDJSON_ERROR_STRING("No error.");
|
||||
case kValidateErrors:
|
||||
return RAPIDJSON_ERROR_STRING("One or more validation errors have occurred");
|
||||
case kValidateErrorNone:
|
||||
return RAPIDJSON_ERROR_STRING("No error.");
|
||||
|
||||
case kValidateErrorMultipleOf: return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'.");
|
||||
case kValidateErrorMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'.");
|
||||
case kValidateErrorExclusiveMaximum: return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'.");
|
||||
case kValidateErrorMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'.");
|
||||
case kValidateErrorExclusiveMinimum: return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'.");
|
||||
case kValidateErrorMultipleOf:
|
||||
return RAPIDJSON_ERROR_STRING("Number '%actual' is not a multiple of the 'multipleOf' value '%expected'.");
|
||||
case kValidateErrorMaximum:
|
||||
return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than the 'maximum' value '%expected'.");
|
||||
case kValidateErrorExclusiveMaximum:
|
||||
return RAPIDJSON_ERROR_STRING("Number '%actual' is greater than or equal to the 'exclusiveMaximum' value '%expected'.");
|
||||
case kValidateErrorMinimum:
|
||||
return RAPIDJSON_ERROR_STRING("Number '%actual' is less than the 'minimum' value '%expected'.");
|
||||
case kValidateErrorExclusiveMinimum:
|
||||
return RAPIDJSON_ERROR_STRING("Number '%actual' is less than or equal to the 'exclusiveMinimum' value '%expected'.");
|
||||
|
||||
case kValidateErrorMaxLength: return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'.");
|
||||
case kValidateErrorMinLength: return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'.");
|
||||
case kValidateErrorPattern: return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression.");
|
||||
case kValidateErrorMaxLength:
|
||||
return RAPIDJSON_ERROR_STRING("String '%actual' is longer than the 'maxLength' value '%expected'.");
|
||||
case kValidateErrorMinLength:
|
||||
return RAPIDJSON_ERROR_STRING("String '%actual' is shorter than the 'minLength' value '%expected'.");
|
||||
case kValidateErrorPattern:
|
||||
return RAPIDJSON_ERROR_STRING("String '%actual' does not match the 'pattern' regular expression.");
|
||||
|
||||
case kValidateErrorMaxItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'.");
|
||||
case kValidateErrorMinItems: return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'.");
|
||||
case kValidateErrorUniqueItems: return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true.");
|
||||
case kValidateErrorAdditionalItems: return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema.");
|
||||
case kValidateErrorMaxItems:
|
||||
return RAPIDJSON_ERROR_STRING("Array of length '%actual' is longer than the 'maxItems' value '%expected'.");
|
||||
case kValidateErrorMinItems:
|
||||
return RAPIDJSON_ERROR_STRING("Array of length '%actual' is shorter than the 'minItems' value '%expected'.");
|
||||
case kValidateErrorUniqueItems:
|
||||
return RAPIDJSON_ERROR_STRING("Array has duplicate items at indices '%duplicates' but 'uniqueItems' is true.");
|
||||
case kValidateErrorAdditionalItems:
|
||||
return RAPIDJSON_ERROR_STRING("Array has an additional item at index '%disallowed' that is not allowed by the schema.");
|
||||
|
||||
case kValidateErrorMaxProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'.");
|
||||
case kValidateErrorMinProperties: return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'.");
|
||||
case kValidateErrorRequired: return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'.");
|
||||
case kValidateErrorAdditionalProperties: return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema.");
|
||||
case kValidateErrorPatternProperties: return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema.");
|
||||
case kValidateErrorDependencies: return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors.");
|
||||
case kValidateErrorMaxProperties:
|
||||
return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is more than 'maxProperties' value '%expected'.");
|
||||
case kValidateErrorMinProperties:
|
||||
return RAPIDJSON_ERROR_STRING("Object has '%actual' members which is less than 'minProperties' value '%expected'.");
|
||||
case kValidateErrorRequired:
|
||||
return RAPIDJSON_ERROR_STRING("Object is missing the following members required by the schema: '%missing'.");
|
||||
case kValidateErrorAdditionalProperties:
|
||||
return RAPIDJSON_ERROR_STRING("Object has an additional member '%disallowed' that is not allowed by the schema.");
|
||||
case kValidateErrorPatternProperties:
|
||||
return RAPIDJSON_ERROR_STRING("Object has 'patternProperties' that are not allowed by the schema.");
|
||||
case kValidateErrorDependencies:
|
||||
return RAPIDJSON_ERROR_STRING("Object has missing property or schema dependencies, refer to following errors.");
|
||||
|
||||
case kValidateErrorEnum: return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values.");
|
||||
case kValidateErrorType: return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'.");
|
||||
case kValidateErrorEnum:
|
||||
return RAPIDJSON_ERROR_STRING("Property has a value that is not one of its allowed enumerated values.");
|
||||
case kValidateErrorType:
|
||||
return RAPIDJSON_ERROR_STRING("Property has a type '%actual' that is not in the following list: '%expected'.");
|
||||
|
||||
case kValidateErrorOneOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors.");
|
||||
case kValidateErrorOneOfMatch: return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf'.");
|
||||
case kValidateErrorAllOf: return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors.");
|
||||
case kValidateErrorAnyOf: return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors.");
|
||||
case kValidateErrorNot: return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'.");
|
||||
case kValidateErrorOneOf:
|
||||
return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'oneOf', refer to following errors.");
|
||||
case kValidateErrorOneOfMatch:
|
||||
return RAPIDJSON_ERROR_STRING("Property matched more than one of the sub-schemas specified by 'oneOf'.");
|
||||
case kValidateErrorAllOf:
|
||||
return RAPIDJSON_ERROR_STRING("Property did not match all of the sub-schemas specified by 'allOf', refer to following errors.");
|
||||
case kValidateErrorAnyOf:
|
||||
return RAPIDJSON_ERROR_STRING("Property did not match any of the sub-schemas specified by 'anyOf', refer to following errors.");
|
||||
case kValidateErrorNot:
|
||||
return RAPIDJSON_ERROR_STRING("Property matched the sub-schema specified by 'not'.");
|
||||
|
||||
default: return RAPIDJSON_ERROR_STRING("Unknown error.");
|
||||
default:
|
||||
return RAPIDJSON_ERROR_STRING("Unknown error.");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -106,6 +106,7 @@ enum ParseErrorCode {
|
||||
struct ParseResult {
|
||||
//!! Unspecified boolean type
|
||||
typedef bool (ParseResult::*BooleanType)() const;
|
||||
|
||||
public:
|
||||
//! Default constructor, no error.
|
||||
ParseResult() : code_(kParseErrorNone), offset_(0) {}
|
||||
@ -124,16 +125,19 @@ public:
|
||||
|
||||
bool operator==(const ParseResult& that) const { return code_ == that.code_; }
|
||||
bool operator==(ParseErrorCode code) const { return code_ == code; }
|
||||
friend bool operator==(ParseErrorCode code, const ParseResult & err) { return code == err.code_; }
|
||||
friend bool operator==(ParseErrorCode code, const ParseResult& err) { return code == err.code_; }
|
||||
|
||||
bool operator!=(const ParseResult& that) const { return !(*this == that); }
|
||||
bool operator!=(ParseErrorCode code) const { return !(*this == code); }
|
||||
friend bool operator!=(ParseErrorCode code, const ParseResult & err) { return err != code; }
|
||||
friend bool operator!=(ParseErrorCode code, const ParseResult& err) { return err != code; }
|
||||
|
||||
//! Reset error code.
|
||||
void Clear() { Set(kParseErrorNone); }
|
||||
//! Update error code and offset.
|
||||
void Set(ParseErrorCode code, size_t offset = 0) { code_ = code; offset_ = offset; }
|
||||
void Set(ParseErrorCode code, size_t offset = 0) {
|
||||
code_ = code;
|
||||
offset_ = offset;
|
||||
}
|
||||
|
||||
private:
|
||||
ParseErrorCode code_;
|
||||
|
@ -21,8 +21,8 @@
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_OFF(unreachable-code)
|
||||
RAPIDJSON_DIAG_OFF(missing-noreturn)
|
||||
RAPIDJSON_DIAG_OFF(unreachable - code)
|
||||
RAPIDJSON_DIAG_OFF(missing - noreturn)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -48,14 +48,24 @@ public:
|
||||
}
|
||||
|
||||
Ch Peek() const { return *current_; }
|
||||
Ch Take() { Ch c = *current_; Read(); return c; }
|
||||
Ch Take() {
|
||||
Ch c = *current_;
|
||||
Read();
|
||||
return c;
|
||||
}
|
||||
size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
|
||||
|
||||
// Not implemented
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// For encoding detection only.
|
||||
const Ch* Peek4() const {
|
||||
@ -81,10 +91,10 @@ private:
|
||||
}
|
||||
|
||||
std::FILE* fp_;
|
||||
Ch *buffer_;
|
||||
Ch* buffer_;
|
||||
size_t bufferSize_;
|
||||
Ch *bufferLast_;
|
||||
Ch *current_;
|
||||
Ch* bufferLast_;
|
||||
Ch* current_;
|
||||
size_t readCount_;
|
||||
size_t count_; //!< Number of characters read
|
||||
bool eof_;
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(unreachable-code)
|
||||
RAPIDJSON_DIAG_OFF(unreachable - code)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -72,11 +72,26 @@ public:
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char Take() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char Peek() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
char Take() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t Tell() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
char* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(char*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
// Prohibit copy constructor & assignment operator.
|
||||
@ -84,13 +99,13 @@ private:
|
||||
FileWriteStream& operator=(const FileWriteStream&);
|
||||
|
||||
std::FILE* fp_;
|
||||
char *buffer_;
|
||||
char *bufferEnd_;
|
||||
char *current_;
|
||||
char* buffer_;
|
||||
char* bufferEnd_;
|
||||
char* current_;
|
||||
};
|
||||
|
||||
//! Implement specialized version of PutN() with memset() for better performance.
|
||||
template<>
|
||||
template <>
|
||||
inline void PutN(FileWriteStream& stream, char c, size_t n) {
|
||||
stream.PutN(c, n);
|
||||
}
|
||||
|
@ -21,17 +21,26 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
|
||||
// encodings.h
|
||||
|
||||
template<typename CharType> struct UTF8;
|
||||
template<typename CharType> struct UTF16;
|
||||
template<typename CharType> struct UTF16BE;
|
||||
template<typename CharType> struct UTF16LE;
|
||||
template<typename CharType> struct UTF32;
|
||||
template<typename CharType> struct UTF32BE;
|
||||
template<typename CharType> struct UTF32LE;
|
||||
template<typename CharType> struct ASCII;
|
||||
template<typename CharType> struct AutoUTF;
|
||||
template <typename CharType>
|
||||
struct UTF8;
|
||||
template <typename CharType>
|
||||
struct UTF16;
|
||||
template <typename CharType>
|
||||
struct UTF16BE;
|
||||
template <typename CharType>
|
||||
struct UTF16LE;
|
||||
template <typename CharType>
|
||||
struct UTF32;
|
||||
template <typename CharType>
|
||||
struct UTF32BE;
|
||||
template <typename CharType>
|
||||
struct UTF32LE;
|
||||
template <typename CharType>
|
||||
struct ASCII;
|
||||
template <typename CharType>
|
||||
struct AutoUTF;
|
||||
|
||||
template<typename SourceEncoding, typename TargetEncoding>
|
||||
template <typename SourceEncoding, typename TargetEncoding>
|
||||
struct Transcoder;
|
||||
|
||||
// allocators.h
|
||||
@ -46,12 +55,12 @@ class MemoryPoolAllocator;
|
||||
template <typename Encoding>
|
||||
struct GenericStringStream;
|
||||
|
||||
typedef GenericStringStream<UTF8<char> > StringStream;
|
||||
typedef GenericStringStream<UTF8<char>> StringStream;
|
||||
|
||||
template <typename Encoding>
|
||||
struct GenericInsituStringStream;
|
||||
|
||||
typedef GenericInsituStringStream<UTF8<char> > InsituStringStream;
|
||||
typedef GenericInsituStringStream<UTF8<char>> InsituStringStream;
|
||||
|
||||
// stringbuffer.h
|
||||
|
||||
@ -81,7 +90,7 @@ struct MemoryStream;
|
||||
|
||||
// reader.h
|
||||
|
||||
template<typename Encoding, typename Derived>
|
||||
template <typename Encoding, typename Derived>
|
||||
struct BaseReaderHandler;
|
||||
|
||||
template <typename SourceEncoding, typename TargetEncoding, typename StackAllocator>
|
||||
@ -91,12 +100,12 @@ typedef GenericReader<UTF8<char>, UTF8<char>, CrtAllocator> Reader;
|
||||
|
||||
// writer.h
|
||||
|
||||
template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
|
||||
template <typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
|
||||
class Writer;
|
||||
|
||||
// prettywriter.h
|
||||
|
||||
template<typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
|
||||
template <typename OutputStream, typename SourceEncoding, typename TargetEncoding, typename StackAllocator, unsigned writeFlags>
|
||||
class PrettyWriter;
|
||||
|
||||
// document.h
|
||||
@ -107,13 +116,13 @@ class GenericMember;
|
||||
template <bool Const, typename Encoding, typename Allocator>
|
||||
class GenericMemberIterator;
|
||||
|
||||
template<typename CharType>
|
||||
template <typename CharType>
|
||||
struct GenericStringRef;
|
||||
|
||||
template <typename Encoding, typename Allocator>
|
||||
class GenericValue;
|
||||
|
||||
typedef GenericValue<UTF8<char>, MemoryPoolAllocator<CrtAllocator> > Value;
|
||||
typedef GenericValue<UTF8<char>, MemoryPoolAllocator<CrtAllocator>> Value;
|
||||
|
||||
template <typename Encoding, typename Allocator, typename StackAllocator>
|
||||
class GenericDocument;
|
||||
|
@ -25,8 +25,8 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
class BigInteger {
|
||||
public:
|
||||
class BigInteger {
|
||||
public:
|
||||
typedef uint64_t Type;
|
||||
|
||||
BigInteger(const BigInteger& rhs) : count_(rhs.count_) {
|
||||
@ -52,8 +52,7 @@ public:
|
||||
AppendDecimal64(decimals + i, decimals + i + length);
|
||||
}
|
||||
|
||||
BigInteger& operator=(const BigInteger &rhs)
|
||||
{
|
||||
BigInteger& operator=(const BigInteger& rhs) {
|
||||
if (this != &rhs) {
|
||||
count_ = rhs.count_;
|
||||
std::memcpy(digits_, rhs.digits_, count_ * sizeof(Type));
|
||||
@ -188,8 +187,16 @@ public:
|
||||
RAPIDJSON_ASSERT(cmp != 0);
|
||||
const BigInteger *a, *b; // Makes a > b
|
||||
bool ret;
|
||||
if (cmp < 0) { a = &rhs; b = this; ret = true; }
|
||||
else { a = this; b = &rhs; ret = false; }
|
||||
if (cmp < 0) {
|
||||
a = &rhs;
|
||||
b = this;
|
||||
ret = true;
|
||||
}
|
||||
else {
|
||||
a = this;
|
||||
b = &rhs;
|
||||
ret = false;
|
||||
}
|
||||
|
||||
Type borrow = 0;
|
||||
for (size_t i = 0; i < a->count_; i++) {
|
||||
@ -217,10 +224,13 @@ public:
|
||||
}
|
||||
|
||||
size_t GetCount() const { return count_; }
|
||||
Type GetDigit(size_t index) const { RAPIDJSON_ASSERT(index < count_); return digits_[index]; }
|
||||
Type GetDigit(size_t index) const {
|
||||
RAPIDJSON_ASSERT(index < count_);
|
||||
return digits_[index];
|
||||
}
|
||||
bool IsZero() const { return count_ == 1 && digits_[0] == 0; }
|
||||
|
||||
private:
|
||||
private:
|
||||
void AppendDecimal64(const char* begin, const char* end) {
|
||||
uint64_t u = ParseUint64(begin, end);
|
||||
if (IsZero())
|
||||
@ -282,7 +292,7 @@ private:
|
||||
|
||||
Type digits_[kCapacity];
|
||||
size_t count_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -29,7 +29,7 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
inline uint32_t clzll(uint64_t x) {
|
||||
inline uint32_t clzll(uint64_t x) {
|
||||
// Passing 0 to __builtin_clzll is UB in GCC and results in an
|
||||
// infinite loop in the software implementation.
|
||||
RAPIDJSON_ASSERT(x != 0);
|
||||
@ -61,7 +61,7 @@ inline uint32_t clzll(uint64_t x) {
|
||||
|
||||
return r;
|
||||
#endif // _MSC_VER
|
||||
}
|
||||
}
|
||||
|
||||
#define RAPIDJSON_CLZLL RAPIDJSON_NAMESPACE::internal::clzll
|
||||
|
||||
|
@ -32,16 +32,16 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
#ifdef __GNUC__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(effc++)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(effc++)
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
#endif
|
||||
|
||||
struct DiyFp {
|
||||
struct DiyFp {
|
||||
DiyFp() : f(), e() {}
|
||||
|
||||
DiyFp(uint64_t fp, int exp) : f(fp), e(exp) {}
|
||||
@ -128,7 +128,7 @@ struct DiyFp {
|
||||
union {
|
||||
double d;
|
||||
uint64_t u64;
|
||||
}u;
|
||||
} u;
|
||||
RAPIDJSON_ASSERT(f <= kDpHiddenBit + kDpSignificandMask);
|
||||
if (e < kDpDenormalExponent) {
|
||||
// Underflow.
|
||||
@ -138,8 +138,7 @@ struct DiyFp {
|
||||
// Overflow.
|
||||
return std::numeric_limits<double>::infinity();
|
||||
}
|
||||
const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 :
|
||||
static_cast<uint64_t>(e + kDpExponentBias);
|
||||
const uint64_t be = (e == kDpDenormalExponent && (f & kDpHiddenBit) == 0) ? 0 : static_cast<uint64_t>(e + kDpExponentBias);
|
||||
u.u64 = (f & kDpSignificandMask) | (be << kDpSignificandSize);
|
||||
return u.d;
|
||||
}
|
||||
@ -156,9 +155,9 @@ struct DiyFp {
|
||||
|
||||
uint64_t f;
|
||||
int e;
|
||||
};
|
||||
};
|
||||
|
||||
inline DiyFp GetCachedPowerByIndex(size_t index) {
|
||||
inline DiyFp GetCachedPowerByIndex(size_t index) {
|
||||
// 10^-348, 10^-340, ..., 10^340
|
||||
static const uint64_t kCachedPowers_F[] = {
|
||||
RAPIDJSON_UINT64_C2(0xfa8fd5a0, 0x081c0288), RAPIDJSON_UINT64_C2(0xbaaee17f, 0xa23ebf76),
|
||||
@ -219,9 +218,9 @@ inline DiyFp GetCachedPowerByIndex(size_t index) {
|
||||
};
|
||||
RAPIDJSON_ASSERT(index < 87);
|
||||
return DiyFp(kCachedPowers_F[index], kCachedPowers_E[index]);
|
||||
}
|
||||
}
|
||||
|
||||
inline DiyFp GetCachedPower(int e, int* K) {
|
||||
inline DiyFp GetCachedPower(int e, int* K) {
|
||||
|
||||
//int k = static_cast<int>(ceil((-61 - e) * 0.30102999566398114)) + 374;
|
||||
double dk = (-61 - e) * 0.30102999566398114 + 347; // dk must be positive, so can do ceiling in positive
|
||||
@ -233,22 +232,22 @@ inline DiyFp GetCachedPower(int e, int* K) {
|
||||
*K = -(-348 + static_cast<int>(index << 3)); // decimal exponent no need lookup table
|
||||
|
||||
return GetCachedPowerByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
inline DiyFp GetCachedPower10(int exp, int *outExp) {
|
||||
inline DiyFp GetCachedPower10(int exp, int* outExp) {
|
||||
RAPIDJSON_ASSERT(exp >= -348);
|
||||
unsigned index = static_cast<unsigned>(exp + 348) / 8u;
|
||||
*outExp = -348 + static_cast<int>(index) * 8;
|
||||
return GetCachedPowerByIndex(index);
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
RAPIDJSON_DIAG_POP
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_POP
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_POP
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
#endif
|
||||
|
||||
} // namespace internal
|
||||
|
@ -27,21 +27,21 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
#ifdef __GNUC__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(effc++)
|
||||
RAPIDJSON_DIAG_OFF(array-bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(effc++)
|
||||
RAPIDJSON_DIAG_OFF(array - bounds) // some gcc versions generate wrong warnings https://gcc.gnu.org/bugzilla/show_bug.cgi?id=59124
|
||||
#endif
|
||||
|
||||
inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
|
||||
inline void GrisuRound(char* buffer, int len, uint64_t delta, uint64_t rest, uint64_t ten_kappa, uint64_t wp_w) {
|
||||
while (rest < wp_w && delta - rest >= ten_kappa &&
|
||||
(rest + ten_kappa < wp_w || /// closer
|
||||
wp_w - rest > rest + ten_kappa - wp_w)) {
|
||||
buffer[len - 1]--;
|
||||
rest += ten_kappa;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline int CountDecimalDigit32(uint32_t n) {
|
||||
inline int CountDecimalDigit32(uint32_t n) {
|
||||
// Simple pure C++ implementation was faster than __builtin_clz version in this situation.
|
||||
if (n < 10) return 1;
|
||||
if (n < 100) return 2;
|
||||
@ -55,9 +55,9 @@ inline int CountDecimalDigit32(uint32_t n) {
|
||||
//if (n < 1000000000) return 9;
|
||||
//return 10;
|
||||
return 9;
|
||||
}
|
||||
}
|
||||
|
||||
inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
|
||||
inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buffer, int* len, int* K) {
|
||||
static const uint32_t kPow10[] = { 1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000 };
|
||||
const DiyFp one(uint64_t(1) << -Mp.e, Mp.e);
|
||||
const DiyFp wp_w = Mp - W;
|
||||
@ -69,15 +69,42 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff
|
||||
while (kappa > 0) {
|
||||
uint32_t d = 0;
|
||||
switch (kappa) {
|
||||
case 9: d = p1 / 100000000; p1 %= 100000000; break;
|
||||
case 8: d = p1 / 10000000; p1 %= 10000000; break;
|
||||
case 7: d = p1 / 1000000; p1 %= 1000000; break;
|
||||
case 6: d = p1 / 100000; p1 %= 100000; break;
|
||||
case 5: d = p1 / 10000; p1 %= 10000; break;
|
||||
case 4: d = p1 / 1000; p1 %= 1000; break;
|
||||
case 3: d = p1 / 100; p1 %= 100; break;
|
||||
case 2: d = p1 / 10; p1 %= 10; break;
|
||||
case 1: d = p1; p1 = 0; break;
|
||||
case 9:
|
||||
d = p1 / 100000000;
|
||||
p1 %= 100000000;
|
||||
break;
|
||||
case 8:
|
||||
d = p1 / 10000000;
|
||||
p1 %= 10000000;
|
||||
break;
|
||||
case 7:
|
||||
d = p1 / 1000000;
|
||||
p1 %= 1000000;
|
||||
break;
|
||||
case 6:
|
||||
d = p1 / 100000;
|
||||
p1 %= 100000;
|
||||
break;
|
||||
case 5:
|
||||
d = p1 / 10000;
|
||||
p1 %= 10000;
|
||||
break;
|
||||
case 4:
|
||||
d = p1 / 1000;
|
||||
p1 %= 1000;
|
||||
break;
|
||||
case 3:
|
||||
d = p1 / 100;
|
||||
p1 %= 100;
|
||||
break;
|
||||
case 2:
|
||||
d = p1 / 10;
|
||||
p1 %= 10;
|
||||
break;
|
||||
case 1:
|
||||
d = p1;
|
||||
p1 = 0;
|
||||
break;
|
||||
default:;
|
||||
}
|
||||
if (d || *len)
|
||||
@ -107,9 +134,9 @@ inline void DigitGen(const DiyFp& W, const DiyFp& Mp, uint64_t delta, char* buff
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline void Grisu2(double value, char* buffer, int* length, int* K) {
|
||||
inline void Grisu2(double value, char* buffer, int* length, int* K) {
|
||||
const DiyFp v(value);
|
||||
DiyFp w_m, w_p;
|
||||
v.NormalizedBoundaries(&w_m, &w_p);
|
||||
@ -121,9 +148,9 @@ inline void Grisu2(double value, char* buffer, int* length, int* K) {
|
||||
Wm.f++;
|
||||
Wp.f--;
|
||||
DigitGen(W, Wp, Wp.f - Wm.f, buffer, length, K);
|
||||
}
|
||||
}
|
||||
|
||||
inline char* WriteExponent(int K, char* buffer) {
|
||||
inline char* WriteExponent(int K, char* buffer) {
|
||||
if (K < 0) {
|
||||
*buffer++ = '-';
|
||||
K = -K;
|
||||
@ -145,9 +172,9 @@ inline char* WriteExponent(int K, char* buffer) {
|
||||
*buffer++ = static_cast<char>('0' + static_cast<char>(K));
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
|
||||
inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
|
||||
const int kk = length + k; // 10^(kk-1) <= v < 10^kk
|
||||
|
||||
if (0 <= k && kk <= 21) {
|
||||
@ -211,9 +238,9 @@ inline char* Prettify(char* buffer, int length, int k, int maxDecimalPlaces) {
|
||||
buffer[length + 1] = 'e';
|
||||
return WriteExponent(kk - 1, &buffer[0 + length + 2]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) {
|
||||
inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) {
|
||||
RAPIDJSON_ASSERT(maxDecimalPlaces >= 1);
|
||||
Double d(value);
|
||||
if (d.IsZero()) {
|
||||
@ -233,10 +260,10 @@ inline char* dtoa(double value, char* buffer, int maxDecimalPlaces = 324) {
|
||||
Grisu2(value, buffer, &length, &K);
|
||||
return Prettify(buffer, length, K, maxDecimalPlaces);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef __GNUC__
|
||||
RAPIDJSON_DIAG_POP
|
||||
RAPIDJSON_DIAG_POP
|
||||
#endif
|
||||
|
||||
} // namespace internal
|
||||
|
@ -20,8 +20,8 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
class Double {
|
||||
public:
|
||||
class Double {
|
||||
public:
|
||||
Double() {}
|
||||
Double(double d) : d_(d) {}
|
||||
Double(uint64_t u) : u_(u) {}
|
||||
@ -57,7 +57,7 @@ public:
|
||||
return order + 1074;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
static const int kSignificandSize = 52;
|
||||
static const int kExponentBias = 0x3FF;
|
||||
static const int kDenormalExponent = 1 - kExponentBias;
|
||||
@ -70,7 +70,7 @@ private:
|
||||
double d_;
|
||||
uint64_t u_;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -20,23 +20,23 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
inline const char* GetDigitsLut() {
|
||||
inline const char* GetDigitsLut() {
|
||||
static const char cDigitsLut[200] = {
|
||||
'0','0','0','1','0','2','0','3','0','4','0','5','0','6','0','7','0','8','0','9',
|
||||
'1','0','1','1','1','2','1','3','1','4','1','5','1','6','1','7','1','8','1','9',
|
||||
'2','0','2','1','2','2','2','3','2','4','2','5','2','6','2','7','2','8','2','9',
|
||||
'3','0','3','1','3','2','3','3','3','4','3','5','3','6','3','7','3','8','3','9',
|
||||
'4','0','4','1','4','2','4','3','4','4','4','5','4','6','4','7','4','8','4','9',
|
||||
'5','0','5','1','5','2','5','3','5','4','5','5','5','6','5','7','5','8','5','9',
|
||||
'6','0','6','1','6','2','6','3','6','4','6','5','6','6','6','7','6','8','6','9',
|
||||
'7','0','7','1','7','2','7','3','7','4','7','5','7','6','7','7','7','8','7','9',
|
||||
'8','0','8','1','8','2','8','3','8','4','8','5','8','6','8','7','8','8','8','9',
|
||||
'9','0','9','1','9','2','9','3','9','4','9','5','9','6','9','7','9','8','9','9'
|
||||
'0', '0', '0', '1', '0', '2', '0', '3', '0', '4', '0', '5', '0', '6', '0', '7', '0', '8', '0', '9',
|
||||
'1', '0', '1', '1', '1', '2', '1', '3', '1', '4', '1', '5', '1', '6', '1', '7', '1', '8', '1', '9',
|
||||
'2', '0', '2', '1', '2', '2', '2', '3', '2', '4', '2', '5', '2', '6', '2', '7', '2', '8', '2', '9',
|
||||
'3', '0', '3', '1', '3', '2', '3', '3', '3', '4', '3', '5', '3', '6', '3', '7', '3', '8', '3', '9',
|
||||
'4', '0', '4', '1', '4', '2', '4', '3', '4', '4', '4', '5', '4', '6', '4', '7', '4', '8', '4', '9',
|
||||
'5', '0', '5', '1', '5', '2', '5', '3', '5', '4', '5', '5', '5', '6', '5', '7', '5', '8', '5', '9',
|
||||
'6', '0', '6', '1', '6', '2', '6', '3', '6', '4', '6', '5', '6', '6', '6', '7', '6', '8', '6', '9',
|
||||
'7', '0', '7', '1', '7', '2', '7', '3', '7', '4', '7', '5', '7', '6', '7', '7', '7', '8', '7', '9',
|
||||
'8', '0', '8', '1', '8', '2', '8', '3', '8', '4', '8', '5', '8', '6', '8', '7', '8', '8', '8', '9',
|
||||
'9', '0', '9', '1', '9', '2', '9', '3', '9', '4', '9', '5', '9', '6', '9', '7', '9', '8', '9', '9'
|
||||
};
|
||||
return cDigitsLut;
|
||||
}
|
||||
}
|
||||
|
||||
inline char* u32toa(uint32_t value, char* buffer) {
|
||||
inline char* u32toa(uint32_t value, char* buffer) {
|
||||
RAPIDJSON_ASSERT(buffer != 0);
|
||||
|
||||
const char* cDigitsLut = GetDigitsLut();
|
||||
@ -110,9 +110,9 @@ inline char* u32toa(uint32_t value, char* buffer) {
|
||||
*buffer++ = cDigitsLut[d4 + 1];
|
||||
}
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
inline char* i32toa(int32_t value, char* buffer) {
|
||||
inline char* i32toa(int32_t value, char* buffer) {
|
||||
RAPIDJSON_ASSERT(buffer != 0);
|
||||
uint32_t u = static_cast<uint32_t>(value);
|
||||
if (value < 0) {
|
||||
@ -121,9 +121,9 @@ inline char* i32toa(int32_t value, char* buffer) {
|
||||
}
|
||||
|
||||
return u32toa(u, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
inline char* u64toa(uint64_t value, char* buffer) {
|
||||
inline char* u64toa(uint64_t value, char* buffer) {
|
||||
RAPIDJSON_ASSERT(buffer != 0);
|
||||
const char* cDigitsLut = GetDigitsLut();
|
||||
const uint64_t kTen8 = 100000000;
|
||||
@ -289,9 +289,9 @@ inline char* u64toa(uint64_t value, char* buffer) {
|
||||
}
|
||||
|
||||
return buffer;
|
||||
}
|
||||
}
|
||||
|
||||
inline char* i64toa(int64_t value, char* buffer) {
|
||||
inline char* i64toa(int64_t value, char* buffer) {
|
||||
RAPIDJSON_ASSERT(buffer != 0);
|
||||
uint64_t u = static_cast<uint64_t>(value);
|
||||
if (value < 0) {
|
||||
@ -300,7 +300,7 @@ inline char* i64toa(int64_t value, char* buffer) {
|
||||
}
|
||||
|
||||
return u64toa(u, buffer);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -35,81 +35,113 @@ RAPIDJSON_DIAG_OFF(6334)
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
|
||||
template <typename T> struct Void { typedef void Type; };
|
||||
// Helper to wrap/convert arbitrary types to void, useful for arbitrary type matching
|
||||
template <typename T>
|
||||
struct Void { typedef void Type; };
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// BoolType, TrueType, FalseType
|
||||
//
|
||||
template <bool Cond> struct BoolType {
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// BoolType, TrueType, FalseType
|
||||
//
|
||||
template <bool Cond>
|
||||
struct BoolType {
|
||||
static const bool Value = Cond;
|
||||
typedef BoolType Type;
|
||||
};
|
||||
typedef BoolType<true> TrueType;
|
||||
typedef BoolType<false> FalseType;
|
||||
};
|
||||
typedef BoolType<true> TrueType;
|
||||
typedef BoolType<false> FalseType;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
|
||||
//
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SelectIf, BoolExpr, NotExpr, AndExpr, OrExpr
|
||||
//
|
||||
|
||||
template <bool C> struct SelectIfImpl { template <typename T1, typename T2> struct Apply { typedef T1 Type; }; };
|
||||
template <> struct SelectIfImpl<false> { template <typename T1, typename T2> struct Apply { typedef T2 Type; }; };
|
||||
template <bool C, typename T1, typename T2> struct SelectIfCond : SelectIfImpl<C>::template Apply<T1,T2> {};
|
||||
template <typename C, typename T1, typename T2> struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
|
||||
template <bool C>
|
||||
struct SelectIfImpl {
|
||||
template <typename T1, typename T2>
|
||||
struct Apply { typedef T1 Type; };
|
||||
};
|
||||
template <>
|
||||
struct SelectIfImpl<false> {
|
||||
template <typename T1, typename T2>
|
||||
struct Apply { typedef T2 Type; };
|
||||
};
|
||||
template <bool C, typename T1, typename T2>
|
||||
struct SelectIfCond : SelectIfImpl<C>::template Apply<T1, T2> {};
|
||||
template <typename C, typename T1, typename T2>
|
||||
struct SelectIf : SelectIfCond<C::Value, T1, T2> {};
|
||||
|
||||
template <bool Cond1, bool Cond2> struct AndExprCond : FalseType {};
|
||||
template <> struct AndExprCond<true, true> : TrueType {};
|
||||
template <bool Cond1, bool Cond2> struct OrExprCond : TrueType {};
|
||||
template <> struct OrExprCond<false, false> : FalseType {};
|
||||
template <bool Cond1, bool Cond2>
|
||||
struct AndExprCond : FalseType {};
|
||||
template <>
|
||||
struct AndExprCond<true, true> : TrueType {};
|
||||
template <bool Cond1, bool Cond2>
|
||||
struct OrExprCond : TrueType {};
|
||||
template <>
|
||||
struct OrExprCond<false, false> : FalseType {};
|
||||
|
||||
template <typename C> struct BoolExpr : SelectIf<C,TrueType,FalseType>::Type {};
|
||||
template <typename C> struct NotExpr : SelectIf<C,FalseType,TrueType>::Type {};
|
||||
template <typename C1, typename C2> struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
|
||||
template <typename C1, typename C2> struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
|
||||
template <typename C>
|
||||
struct BoolExpr : SelectIf<C, TrueType, FalseType>::Type {};
|
||||
template <typename C>
|
||||
struct NotExpr : SelectIf<C, FalseType, TrueType>::Type {};
|
||||
template <typename C1, typename C2>
|
||||
struct AndExpr : AndExprCond<C1::Value, C2::Value>::Type {};
|
||||
template <typename C1, typename C2>
|
||||
struct OrExpr : OrExprCond<C1::Value, C2::Value>::Type {};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddConst, MaybeAddConst, RemoveConst
|
||||
template <typename T> struct AddConst { typedef const T Type; };
|
||||
template <bool Constify, typename T> struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
|
||||
template <typename T> struct RemoveConst { typedef T Type; };
|
||||
template <typename T> struct RemoveConst<const T> { typedef T Type; };
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// AddConst, MaybeAddConst, RemoveConst
|
||||
template <typename T>
|
||||
struct AddConst { typedef const T Type; };
|
||||
template <bool Constify, typename T>
|
||||
struct MaybeAddConst : SelectIfCond<Constify, const T, T> {};
|
||||
template <typename T>
|
||||
struct RemoveConst { typedef T Type; };
|
||||
template <typename T>
|
||||
struct RemoveConst<const T> { typedef T Type; };
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IsSame, IsConst, IsMoreConst, IsPointer
|
||||
//
|
||||
template <typename T, typename U> struct IsSame : FalseType {};
|
||||
template <typename T> struct IsSame<T, T> : TrueType {};
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IsSame, IsConst, IsMoreConst, IsPointer
|
||||
//
|
||||
template <typename T, typename U>
|
||||
struct IsSame : FalseType {};
|
||||
template <typename T>
|
||||
struct IsSame<T, T> : TrueType {};
|
||||
|
||||
template <typename T> struct IsConst : FalseType {};
|
||||
template <typename T> struct IsConst<const T> : TrueType {};
|
||||
template <typename T>
|
||||
struct IsConst : FalseType {};
|
||||
template <typename T>
|
||||
struct IsConst<const T> : TrueType {};
|
||||
|
||||
template <typename CT, typename T>
|
||||
struct IsMoreConst
|
||||
template <typename CT, typename T>
|
||||
struct IsMoreConst
|
||||
: AndExpr<IsSame<typename RemoveConst<CT>::Type, typename RemoveConst<T>::Type>,
|
||||
BoolType<IsConst<CT>::Value >= IsConst<T>::Value> >::Type {};
|
||||
BoolType<IsConst<CT>::Value >= IsConst<T>::Value>>::Type {};
|
||||
|
||||
template <typename T> struct IsPointer : FalseType {};
|
||||
template <typename T> struct IsPointer<T*> : TrueType {};
|
||||
template <typename T>
|
||||
struct IsPointer : FalseType {};
|
||||
template <typename T>
|
||||
struct IsPointer<T*> : TrueType {};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IsBaseOf
|
||||
//
|
||||
#if RAPIDJSON_HAS_CXX11_TYPETRAITS
|
||||
|
||||
template <typename B, typename D> struct IsBaseOf
|
||||
: BoolType< ::std::is_base_of<B,D>::value> {};
|
||||
template <typename B, typename D>
|
||||
struct IsBaseOf
|
||||
: BoolType<::std::is_base_of<B, D>::value> {};
|
||||
|
||||
#else // simplified version adopted from Boost
|
||||
|
||||
template<typename B, typename D> struct IsBaseOfImpl {
|
||||
template <typename B, typename D>
|
||||
struct IsBaseOfImpl {
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(B) != 0);
|
||||
RAPIDJSON_STATIC_ASSERT(sizeof(D) != 0);
|
||||
|
||||
typedef char (&Yes)[1];
|
||||
typedef char (&No) [2];
|
||||
typedef char (&No)[2];
|
||||
|
||||
template <typename T>
|
||||
static Yes Check(const D*, T);
|
||||
@ -121,54 +153,58 @@ template<typename B, typename D> struct IsBaseOfImpl {
|
||||
};
|
||||
|
||||
enum { Value = (sizeof(Check(Host(), 0)) == sizeof(Yes)) };
|
||||
};
|
||||
};
|
||||
|
||||
template <typename B, typename D> struct IsBaseOf
|
||||
: OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D> > >::Type {};
|
||||
template <typename B, typename D>
|
||||
struct IsBaseOf
|
||||
: OrExpr<IsSame<B, D>, BoolExpr<IsBaseOfImpl<B, D>>>::Type {};
|
||||
|
||||
#endif // RAPIDJSON_HAS_CXX11_TYPETRAITS
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EnableIf / DisableIf
|
||||
//
|
||||
template <bool Condition, typename T = void> struct EnableIfCond { typedef T Type; };
|
||||
template <typename T> struct EnableIfCond<false, T> { /* empty */ };
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
// EnableIf / DisableIf
|
||||
//
|
||||
template <bool Condition, typename T = void>
|
||||
struct EnableIfCond { typedef T Type; };
|
||||
template <typename T>
|
||||
struct EnableIfCond<false, T> { /* empty */
|
||||
};
|
||||
|
||||
template <bool Condition, typename T = void> struct DisableIfCond { typedef T Type; };
|
||||
template <typename T> struct DisableIfCond<true, T> { /* empty */ };
|
||||
template <bool Condition, typename T = void>
|
||||
struct DisableIfCond { typedef T Type; };
|
||||
template <typename T>
|
||||
struct DisableIfCond<true, T> { /* empty */
|
||||
};
|
||||
|
||||
template <typename Condition, typename T = void>
|
||||
struct EnableIf : EnableIfCond<Condition::Value, T> {};
|
||||
template <typename Condition, typename T = void>
|
||||
struct EnableIf : EnableIfCond<Condition::Value, T> {};
|
||||
|
||||
template <typename Condition, typename T = void>
|
||||
struct DisableIf : DisableIfCond<Condition::Value, T> {};
|
||||
template <typename Condition, typename T = void>
|
||||
struct DisableIf : DisableIfCond<Condition::Value, T> {};
|
||||
|
||||
// SFINAE helpers
|
||||
struct SfinaeTag {};
|
||||
template <typename T> struct RemoveSfinaeTag;
|
||||
template <typename T> struct RemoveSfinaeTag<SfinaeTag&(*)(T)> { typedef T Type; };
|
||||
// SFINAE helpers
|
||||
struct SfinaeTag {};
|
||||
template <typename T>
|
||||
struct RemoveSfinaeTag;
|
||||
template <typename T>
|
||||
struct RemoveSfinaeTag<SfinaeTag& (*)(T)> { typedef T Type; };
|
||||
|
||||
#define RAPIDJSON_REMOVEFPTR_(type) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag \
|
||||
< ::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*) type>::Type
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::RemoveSfinaeTag<::RAPIDJSON_NAMESPACE::internal::SfinaeTag&(*)type>::Type
|
||||
|
||||
#define RAPIDJSON_ENABLEIF(cond) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
|
||||
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf<RAPIDJSON_REMOVEFPTR_(cond)>::Type* = NULL
|
||||
|
||||
#define RAPIDJSON_DISABLEIF(cond) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
|
||||
<RAPIDJSON_REMOVEFPTR_(cond)>::Type * = NULL
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf<RAPIDJSON_REMOVEFPTR_(cond)>::Type* = NULL
|
||||
|
||||
#define RAPIDJSON_ENABLEIF_RETURN(cond,returntype) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf \
|
||||
<RAPIDJSON_REMOVEFPTR_(cond), \
|
||||
#define RAPIDJSON_ENABLEIF_RETURN(cond, returntype) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::EnableIf<RAPIDJSON_REMOVEFPTR_(cond), \
|
||||
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
|
||||
|
||||
#define RAPIDJSON_DISABLEIF_RETURN(cond,returntype) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf \
|
||||
<RAPIDJSON_REMOVEFPTR_(cond), \
|
||||
#define RAPIDJSON_DISABLEIF_RETURN(cond, returntype) \
|
||||
typename ::RAPIDJSON_NAMESPACE::internal::DisableIf<RAPIDJSON_REMOVEFPTR_(cond), \
|
||||
RAPIDJSON_REMOVEFPTR_(returntype)>::Type
|
||||
|
||||
} // namespace internal
|
||||
|
@ -20,12 +20,12 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
//! Computes integer powers of 10 in double (10.0^n).
|
||||
/*! This function uses lookup table for fast and accurate results.
|
||||
//! Computes integer powers of 10 in double (10.0^n).
|
||||
/*! This function uses lookup table for fast and accurate results.
|
||||
\param n non-negative exponent. Must <= 308.
|
||||
\return 10.0^n
|
||||
*/
|
||||
inline double Pow10(int n) {
|
||||
inline double Pow10(int n) {
|
||||
static const double e[] = { // 1e-0...1e308: 309 * 8 bytes = 2472 bytes
|
||||
1e+0,
|
||||
1e+1, 1e+2, 1e+3, 1e+4, 1e+5, 1e+6, 1e+7, 1e+8, 1e+9, 1e+10, 1e+11, 1e+12, 1e+13, 1e+14, 1e+15, 1e+16, 1e+17, 1e+18, 1e+19, 1e+20,
|
||||
@ -33,21 +33,21 @@ inline double Pow10(int n) {
|
||||
1e+41, 1e+42, 1e+43, 1e+44, 1e+45, 1e+46, 1e+47, 1e+48, 1e+49, 1e+50, 1e+51, 1e+52, 1e+53, 1e+54, 1e+55, 1e+56, 1e+57, 1e+58, 1e+59, 1e+60,
|
||||
1e+61, 1e+62, 1e+63, 1e+64, 1e+65, 1e+66, 1e+67, 1e+68, 1e+69, 1e+70, 1e+71, 1e+72, 1e+73, 1e+74, 1e+75, 1e+76, 1e+77, 1e+78, 1e+79, 1e+80,
|
||||
1e+81, 1e+82, 1e+83, 1e+84, 1e+85, 1e+86, 1e+87, 1e+88, 1e+89, 1e+90, 1e+91, 1e+92, 1e+93, 1e+94, 1e+95, 1e+96, 1e+97, 1e+98, 1e+99, 1e+100,
|
||||
1e+101,1e+102,1e+103,1e+104,1e+105,1e+106,1e+107,1e+108,1e+109,1e+110,1e+111,1e+112,1e+113,1e+114,1e+115,1e+116,1e+117,1e+118,1e+119,1e+120,
|
||||
1e+121,1e+122,1e+123,1e+124,1e+125,1e+126,1e+127,1e+128,1e+129,1e+130,1e+131,1e+132,1e+133,1e+134,1e+135,1e+136,1e+137,1e+138,1e+139,1e+140,
|
||||
1e+141,1e+142,1e+143,1e+144,1e+145,1e+146,1e+147,1e+148,1e+149,1e+150,1e+151,1e+152,1e+153,1e+154,1e+155,1e+156,1e+157,1e+158,1e+159,1e+160,
|
||||
1e+161,1e+162,1e+163,1e+164,1e+165,1e+166,1e+167,1e+168,1e+169,1e+170,1e+171,1e+172,1e+173,1e+174,1e+175,1e+176,1e+177,1e+178,1e+179,1e+180,
|
||||
1e+181,1e+182,1e+183,1e+184,1e+185,1e+186,1e+187,1e+188,1e+189,1e+190,1e+191,1e+192,1e+193,1e+194,1e+195,1e+196,1e+197,1e+198,1e+199,1e+200,
|
||||
1e+201,1e+202,1e+203,1e+204,1e+205,1e+206,1e+207,1e+208,1e+209,1e+210,1e+211,1e+212,1e+213,1e+214,1e+215,1e+216,1e+217,1e+218,1e+219,1e+220,
|
||||
1e+221,1e+222,1e+223,1e+224,1e+225,1e+226,1e+227,1e+228,1e+229,1e+230,1e+231,1e+232,1e+233,1e+234,1e+235,1e+236,1e+237,1e+238,1e+239,1e+240,
|
||||
1e+241,1e+242,1e+243,1e+244,1e+245,1e+246,1e+247,1e+248,1e+249,1e+250,1e+251,1e+252,1e+253,1e+254,1e+255,1e+256,1e+257,1e+258,1e+259,1e+260,
|
||||
1e+261,1e+262,1e+263,1e+264,1e+265,1e+266,1e+267,1e+268,1e+269,1e+270,1e+271,1e+272,1e+273,1e+274,1e+275,1e+276,1e+277,1e+278,1e+279,1e+280,
|
||||
1e+281,1e+282,1e+283,1e+284,1e+285,1e+286,1e+287,1e+288,1e+289,1e+290,1e+291,1e+292,1e+293,1e+294,1e+295,1e+296,1e+297,1e+298,1e+299,1e+300,
|
||||
1e+301,1e+302,1e+303,1e+304,1e+305,1e+306,1e+307,1e+308
|
||||
1e+101, 1e+102, 1e+103, 1e+104, 1e+105, 1e+106, 1e+107, 1e+108, 1e+109, 1e+110, 1e+111, 1e+112, 1e+113, 1e+114, 1e+115, 1e+116, 1e+117, 1e+118, 1e+119, 1e+120,
|
||||
1e+121, 1e+122, 1e+123, 1e+124, 1e+125, 1e+126, 1e+127, 1e+128, 1e+129, 1e+130, 1e+131, 1e+132, 1e+133, 1e+134, 1e+135, 1e+136, 1e+137, 1e+138, 1e+139, 1e+140,
|
||||
1e+141, 1e+142, 1e+143, 1e+144, 1e+145, 1e+146, 1e+147, 1e+148, 1e+149, 1e+150, 1e+151, 1e+152, 1e+153, 1e+154, 1e+155, 1e+156, 1e+157, 1e+158, 1e+159, 1e+160,
|
||||
1e+161, 1e+162, 1e+163, 1e+164, 1e+165, 1e+166, 1e+167, 1e+168, 1e+169, 1e+170, 1e+171, 1e+172, 1e+173, 1e+174, 1e+175, 1e+176, 1e+177, 1e+178, 1e+179, 1e+180,
|
||||
1e+181, 1e+182, 1e+183, 1e+184, 1e+185, 1e+186, 1e+187, 1e+188, 1e+189, 1e+190, 1e+191, 1e+192, 1e+193, 1e+194, 1e+195, 1e+196, 1e+197, 1e+198, 1e+199, 1e+200,
|
||||
1e+201, 1e+202, 1e+203, 1e+204, 1e+205, 1e+206, 1e+207, 1e+208, 1e+209, 1e+210, 1e+211, 1e+212, 1e+213, 1e+214, 1e+215, 1e+216, 1e+217, 1e+218, 1e+219, 1e+220,
|
||||
1e+221, 1e+222, 1e+223, 1e+224, 1e+225, 1e+226, 1e+227, 1e+228, 1e+229, 1e+230, 1e+231, 1e+232, 1e+233, 1e+234, 1e+235, 1e+236, 1e+237, 1e+238, 1e+239, 1e+240,
|
||||
1e+241, 1e+242, 1e+243, 1e+244, 1e+245, 1e+246, 1e+247, 1e+248, 1e+249, 1e+250, 1e+251, 1e+252, 1e+253, 1e+254, 1e+255, 1e+256, 1e+257, 1e+258, 1e+259, 1e+260,
|
||||
1e+261, 1e+262, 1e+263, 1e+264, 1e+265, 1e+266, 1e+267, 1e+268, 1e+269, 1e+270, 1e+271, 1e+272, 1e+273, 1e+274, 1e+275, 1e+276, 1e+277, 1e+278, 1e+279, 1e+280,
|
||||
1e+281, 1e+282, 1e+283, 1e+284, 1e+285, 1e+286, 1e+287, 1e+288, 1e+289, 1e+290, 1e+291, 1e+292, 1e+293, 1e+294, 1e+295, 1e+296, 1e+297, 1e+298, 1e+299, 1e+300,
|
||||
1e+301, 1e+302, 1e+303, 1e+304, 1e+305, 1e+306, 1e+307, 1e+308
|
||||
};
|
||||
RAPIDJSON_ASSERT(n >= 0 && n <= 308);
|
||||
return e[n];
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -22,7 +22,7 @@
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
RAPIDJSON_DIAG_OFF(switch - enum)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
|
||||
@ -40,12 +40,12 @@ RAPIDJSON_DIAG_OFF(effc++)
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// DecodedStream
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// DecodedStream
|
||||
|
||||
template <typename SourceStream, typename Encoding>
|
||||
class DecodedStream {
|
||||
public:
|
||||
template <typename SourceStream, typename Encoding>
|
||||
class DecodedStream {
|
||||
public:
|
||||
DecodedStream(SourceStream& ss) : ss_(ss), codepoint_() { Decode(); }
|
||||
unsigned Peek() { return codepoint_; }
|
||||
unsigned Take() {
|
||||
@ -55,7 +55,7 @@ public:
|
||||
return c;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
void Decode() {
|
||||
if (!Encoding::Decode(ss_, &codepoint_))
|
||||
codepoint_ = 0;
|
||||
@ -63,19 +63,19 @@ private:
|
||||
|
||||
SourceStream& ss_;
|
||||
unsigned codepoint_;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GenericRegex
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// GenericRegex
|
||||
|
||||
static const SizeType kRegexInvalidState = ~SizeType(0); //!< Represents an invalid index in GenericRegex::State::out, out1
|
||||
static const SizeType kRegexInvalidRange = ~SizeType(0);
|
||||
static const SizeType kRegexInvalidState = ~SizeType(0); //!< Represents an invalid index in GenericRegex::State::out, out1
|
||||
static const SizeType kRegexInvalidRange = ~SizeType(0);
|
||||
|
||||
template <typename Encoding, typename Allocator>
|
||||
class GenericRegexSearch;
|
||||
template <typename Encoding, typename Allocator>
|
||||
class GenericRegexSearch;
|
||||
|
||||
//! Regular expression engine with subset of ECMAscript grammar.
|
||||
/*!
|
||||
//! Regular expression engine with subset of ECMAscript grammar.
|
||||
/*!
|
||||
Supported regular expression syntax:
|
||||
- \c ab Concatenation
|
||||
- \c a|b Alternation
|
||||
@ -106,25 +106,23 @@ class GenericRegexSearch;
|
||||
Cox, Russ. "Regular Expression Matching Can Be Simple And Fast (but is slow in Java, Perl, PHP, Python, Ruby,...).",
|
||||
https://swtch.com/~rsc/regexp/regexp1.html
|
||||
*/
|
||||
template <typename Encoding, typename Allocator = CrtAllocator>
|
||||
class GenericRegex {
|
||||
public:
|
||||
template <typename Encoding, typename Allocator = CrtAllocator>
|
||||
class GenericRegex {
|
||||
public:
|
||||
typedef Encoding EncodingType;
|
||||
typedef typename Encoding::Ch Ch;
|
||||
template <typename, typename> friend class GenericRegexSearch;
|
||||
template <typename, typename>
|
||||
friend class GenericRegexSearch;
|
||||
|
||||
GenericRegex(const Ch* source, Allocator* allocator = 0) :
|
||||
ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_),
|
||||
GenericRegex(const Ch* source, Allocator* allocator = 0) : ownAllocator_(allocator ? 0 : RAPIDJSON_NEW(Allocator)()), allocator_(allocator ? allocator : ownAllocator_),
|
||||
states_(allocator_, 256), ranges_(allocator_, 256), root_(kRegexInvalidState), stateCount_(), rangeCount_(),
|
||||
anchorBegin_(), anchorEnd_()
|
||||
{
|
||||
anchorBegin_(), anchorEnd_() {
|
||||
GenericStringStream<Encoding> ss(source);
|
||||
DecodedStream<GenericStringStream<Encoding>, Encoding> ds(ss);
|
||||
Parse(ds);
|
||||
}
|
||||
|
||||
~GenericRegex()
|
||||
{
|
||||
~GenericRegex() {
|
||||
RAPIDJSON_DELETE(ownAllocator_);
|
||||
}
|
||||
|
||||
@ -132,7 +130,7 @@ public:
|
||||
return root_ != kRegexInvalidState;
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
enum Operator {
|
||||
kZeroOrOne,
|
||||
kZeroOrMore,
|
||||
@ -244,8 +242,7 @@ private:
|
||||
return;
|
||||
break;
|
||||
|
||||
case '{':
|
||||
{
|
||||
case '{': {
|
||||
unsigned n, m;
|
||||
if (!ParseUnsigned(ds, &n))
|
||||
return;
|
||||
@ -263,16 +260,14 @@ private:
|
||||
if (!EvalQuantifier(operandStack, n, m) || ds.Peek() != '}')
|
||||
return;
|
||||
ds.Take();
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
|
||||
case '.':
|
||||
PushOperand(operandStack, kAnyCharacterClass);
|
||||
ImplicitConcatenation(atomCountStack, operatorStack);
|
||||
break;
|
||||
|
||||
case '[':
|
||||
{
|
||||
case '[': {
|
||||
SizeType range;
|
||||
if (!ParseRange(ds, &range))
|
||||
return;
|
||||
@ -307,7 +302,7 @@ private:
|
||||
|
||||
#if RAPIDJSON_REGEX_VERBOSE
|
||||
printf("root: %d\n", root_);
|
||||
for (SizeType i = 0; i < stateCount_ ; i++) {
|
||||
for (SizeType i = 0; i < stateCount_; i++) {
|
||||
State& s = GetState(i);
|
||||
printf("[%2d] out: %2d out1: %2d c: '%c'\n", i, s.out, s.out1, (char)s.codepoint);
|
||||
}
|
||||
@ -529,8 +524,7 @@ private:
|
||||
// fall through to step 0 for other characters
|
||||
RAPIDJSON_DELIBERATE_FALLTHROUGH;
|
||||
|
||||
case 0:
|
||||
{
|
||||
case 0: {
|
||||
SizeType r = NewRange(codepoint);
|
||||
if (current != kRegexInvalidRange)
|
||||
GetRange(current).next = r;
|
||||
@ -576,12 +570,23 @@ private:
|
||||
case '{':
|
||||
case '}':
|
||||
case '\\':
|
||||
*escapedCodepoint = codepoint; return true;
|
||||
case 'f': *escapedCodepoint = 0x000C; return true;
|
||||
case 'n': *escapedCodepoint = 0x000A; return true;
|
||||
case 'r': *escapedCodepoint = 0x000D; return true;
|
||||
case 't': *escapedCodepoint = 0x0009; return true;
|
||||
case 'v': *escapedCodepoint = 0x000B; return true;
|
||||
*escapedCodepoint = codepoint;
|
||||
return true;
|
||||
case 'f':
|
||||
*escapedCodepoint = 0x000C;
|
||||
return true;
|
||||
case 'n':
|
||||
*escapedCodepoint = 0x000A;
|
||||
return true;
|
||||
case 'r':
|
||||
*escapedCodepoint = 0x000D;
|
||||
return true;
|
||||
case 't':
|
||||
*escapedCodepoint = 0x0009;
|
||||
return true;
|
||||
case 'v':
|
||||
*escapedCodepoint = 0x000B;
|
||||
return true;
|
||||
default:
|
||||
return false; // Unsupported escape character
|
||||
}
|
||||
@ -600,18 +605,16 @@ private:
|
||||
// For SearchWithAnchoring()
|
||||
bool anchorBegin_;
|
||||
bool anchorEnd_;
|
||||
};
|
||||
};
|
||||
|
||||
template <typename RegexType, typename Allocator = CrtAllocator>
|
||||
class GenericRegexSearch {
|
||||
public:
|
||||
template <typename RegexType, typename Allocator = CrtAllocator>
|
||||
class GenericRegexSearch {
|
||||
public:
|
||||
typedef typename RegexType::EncodingType Encoding;
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
GenericRegexSearch(const RegexType& regex, Allocator* allocator = 0) :
|
||||
regex_(regex), allocator_(allocator), ownAllocator_(0),
|
||||
state0_(allocator, 0), state1_(allocator, 0), stateSet_()
|
||||
{
|
||||
GenericRegexSearch(const RegexType& regex, Allocator* allocator = 0) : regex_(regex), allocator_(allocator), ownAllocator_(0),
|
||||
state0_(allocator, 0), state1_(allocator, 0), stateSet_() {
|
||||
RAPIDJSON_ASSERT(regex_.IsValid());
|
||||
if (!allocator_)
|
||||
ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
|
||||
@ -645,7 +648,7 @@ public:
|
||||
return Search(is);
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
typedef typename RegexType::State State;
|
||||
typedef typename RegexType::Range Range;
|
||||
|
||||
@ -654,7 +657,7 @@ private:
|
||||
DecodedStream<InputStream, Encoding> ds(is);
|
||||
|
||||
state0_.Clear();
|
||||
Stack<Allocator> *current = &state0_, *next = &state1_;
|
||||
Stack<Allocator>*current = &state0_, *next = &state1_;
|
||||
const size_t stateSetSize = GetStateSetSize();
|
||||
std::memset(stateSet_, 0, stateSetSize);
|
||||
|
||||
@ -668,8 +671,7 @@ private:
|
||||
const State& sr = regex_.GetState(*s);
|
||||
if (sr.codepoint == codepoint ||
|
||||
sr.codepoint == RegexType::kAnyCharacterClass ||
|
||||
(sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint)))
|
||||
{
|
||||
(sr.codepoint == RegexType::kRangeCharacterClass && MatchRange(sr.rangeStart, codepoint))) {
|
||||
matched = AddState(*next, sr.out) || matched;
|
||||
if (!anchorEnd && matched)
|
||||
return true;
|
||||
@ -720,10 +722,10 @@ private:
|
||||
Stack<Allocator> state0_;
|
||||
Stack<Allocator> state1_;
|
||||
uint32_t* stateSet_;
|
||||
};
|
||||
};
|
||||
|
||||
typedef GenericRegex<UTF8<> > Regex;
|
||||
typedef GenericRegexSearch<Regex> RegexSearch;
|
||||
typedef GenericRegex<UTF8<>> Regex;
|
||||
typedef GenericRegexSearch<Regex> RegexSearch;
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -21,21 +21,21 @@
|
||||
|
||||
#if defined(__clang__)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Stack
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Stack
|
||||
|
||||
//! A type-unsafe stack for storing different types of data.
|
||||
/*! \tparam Allocator Allocator for allocating stack memory.
|
||||
//! A type-unsafe stack for storing different types of data.
|
||||
/*! \tparam Allocator Allocator for allocating stack memory.
|
||||
*/
|
||||
template <typename Allocator>
|
||||
class Stack {
|
||||
public:
|
||||
template <typename Allocator>
|
||||
class Stack {
|
||||
public:
|
||||
// Optimization note: Do not allocate memory for stack_ in constructor.
|
||||
// Do it lazily when first Push() -> Expand() -> Resize().
|
||||
Stack(Allocator* allocator, size_t stackCapacity) : allocator_(allocator), ownAllocator_(0), stack_(0), stackTop_(0), stackEnd_(0), initialCapacity_(stackCapacity) {
|
||||
@ -48,8 +48,7 @@ public:
|
||||
stack_(rhs.stack_),
|
||||
stackTop_(rhs.stackTop_),
|
||||
stackEnd_(rhs.stackEnd_),
|
||||
initialCapacity_(rhs.initialCapacity_)
|
||||
{
|
||||
initialCapacity_(rhs.initialCapacity_) {
|
||||
rhs.allocator_ = 0;
|
||||
rhs.ownAllocator_ = 0;
|
||||
rhs.stack_ = 0;
|
||||
@ -65,8 +64,7 @@ public:
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
Stack& operator=(Stack&& rhs) {
|
||||
if (&rhs != this)
|
||||
{
|
||||
if (&rhs != this) {
|
||||
Destroy();
|
||||
|
||||
allocator_ = rhs.allocator_;
|
||||
@ -112,20 +110,20 @@ public:
|
||||
|
||||
// Optimization note: try to minimize the size of this function for force inline.
|
||||
// Expansion is run very infrequently, so it is moved to another (probably non-inline) function.
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
RAPIDJSON_FORCEINLINE void Reserve(size_t count = 1) {
|
||||
// Expand the stack if needed
|
||||
if (RAPIDJSON_UNLIKELY(static_cast<std::ptrdiff_t>(sizeof(T) * count) > (stackEnd_ - stackTop_)))
|
||||
Expand<T>(count);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
RAPIDJSON_FORCEINLINE T* Push(size_t count = 1) {
|
||||
Reserve<T>(count);
|
||||
return PushUnsafe<T>(count);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
RAPIDJSON_FORCEINLINE T* PushUnsafe(size_t count = 1) {
|
||||
RAPIDJSON_ASSERT(stackTop_);
|
||||
RAPIDJSON_ASSERT(static_cast<std::ptrdiff_t>(sizeof(T) * count) <= (stackEnd_ - stackTop_));
|
||||
@ -134,35 +132,35 @@ public:
|
||||
return ret;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T* Pop(size_t count) {
|
||||
RAPIDJSON_ASSERT(GetSize() >= count * sizeof(T));
|
||||
stackTop_ -= count * sizeof(T);
|
||||
return reinterpret_cast<T*>(stackTop_);
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T* Top() {
|
||||
RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
|
||||
return reinterpret_cast<T*>(stackTop_ - sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
const T* Top() const {
|
||||
RAPIDJSON_ASSERT(GetSize() >= sizeof(T));
|
||||
return reinterpret_cast<T*>(stackTop_ - sizeof(T));
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T* End() { return reinterpret_cast<T*>(stackTop_); }
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
const T* End() const { return reinterpret_cast<T*>(stackTop_); }
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
T* Bottom() { return reinterpret_cast<T*>(stack_); }
|
||||
|
||||
template<typename T>
|
||||
template <typename T>
|
||||
const T* Bottom() const { return reinterpret_cast<T*>(stack_); }
|
||||
|
||||
bool HasAllocator() const {
|
||||
@ -178,8 +176,8 @@ public:
|
||||
size_t GetSize() const { return static_cast<size_t>(stackTop_ - stack_); }
|
||||
size_t GetCapacity() const { return static_cast<size_t>(stackEnd_ - stack_); }
|
||||
|
||||
private:
|
||||
template<typename T>
|
||||
private:
|
||||
template <typename T>
|
||||
void Expand(size_t count) {
|
||||
// Only expand the capacity if the current stack exists. Otherwise just create a stack with initial capacity.
|
||||
size_t newCapacity;
|
||||
@ -187,7 +185,8 @@ private:
|
||||
if (!allocator_)
|
||||
ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
|
||||
newCapacity = initialCapacity_;
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
newCapacity = GetCapacity();
|
||||
newCapacity += (newCapacity + 1) / 2;
|
||||
}
|
||||
@ -216,11 +215,11 @@ private:
|
||||
|
||||
Allocator* allocator_;
|
||||
Allocator* ownAllocator_;
|
||||
char *stack_;
|
||||
char *stackTop_;
|
||||
char *stackEnd_;
|
||||
char* stack_;
|
||||
char* stackTop_;
|
||||
char* stackEnd_;
|
||||
size_t initialCapacity_;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -21,33 +21,33 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
//! Custom strlen() which works on different character types.
|
||||
/*! \tparam Ch Character type (e.g. char, wchar_t, short)
|
||||
//! Custom strlen() which works on different character types.
|
||||
/*! \tparam Ch Character type (e.g. char, wchar_t, short)
|
||||
\param s Null-terminated input string.
|
||||
\return Number of characters in the string.
|
||||
\note This has the same semantics as strlen(), the return value is not number of Unicode codepoints.
|
||||
*/
|
||||
template <typename Ch>
|
||||
inline SizeType StrLen(const Ch* s) {
|
||||
template <typename Ch>
|
||||
inline SizeType StrLen(const Ch* s) {
|
||||
RAPIDJSON_ASSERT(s != 0);
|
||||
const Ch* p = s;
|
||||
while (*p) ++p;
|
||||
return SizeType(p - s);
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline SizeType StrLen(const char* s) {
|
||||
template <>
|
||||
inline SizeType StrLen(const char* s) {
|
||||
return SizeType(std::strlen(s));
|
||||
}
|
||||
}
|
||||
|
||||
template <>
|
||||
inline SizeType StrLen(const wchar_t* s) {
|
||||
template <>
|
||||
inline SizeType StrLen(const wchar_t* s) {
|
||||
return SizeType(std::wcslen(s));
|
||||
}
|
||||
}
|
||||
|
||||
//! Returns number of code points in a encoded string.
|
||||
template<typename Encoding>
|
||||
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
|
||||
//! Returns number of code points in a encoded string.
|
||||
template <typename Encoding>
|
||||
bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeType* outCount) {
|
||||
RAPIDJSON_ASSERT(s != 0);
|
||||
RAPIDJSON_ASSERT(outCount != 0);
|
||||
GenericStringStream<Encoding> is(s);
|
||||
@ -61,7 +61,7 @@ bool CountStringCodePoint(const typename Encoding::Ch* s, SizeType length, SizeT
|
||||
}
|
||||
*outCount = count;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -25,16 +25,16 @@
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
inline double FastPath(double significand, int exp) {
|
||||
inline double FastPath(double significand, int exp) {
|
||||
if (exp < -308)
|
||||
return 0.0;
|
||||
else if (exp >= 0)
|
||||
return significand * internal::Pow10(exp);
|
||||
else
|
||||
return significand / internal::Pow10(-exp);
|
||||
}
|
||||
}
|
||||
|
||||
inline double StrtodNormalPrecision(double d, int p) {
|
||||
inline double StrtodNormalPrecision(double d, int p) {
|
||||
if (p < -308) {
|
||||
// Prevent expSum < -308, making Pow10(p) = 0
|
||||
d = FastPath(d, -308);
|
||||
@ -43,17 +43,17 @@ inline double StrtodNormalPrecision(double d, int p) {
|
||||
else
|
||||
d = FastPath(d, p);
|
||||
return d;
|
||||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline T Min3(T a, T b, T c) {
|
||||
template <typename T>
|
||||
inline T Min3(T a, T b, T c) {
|
||||
T m = a;
|
||||
if (m > b) m = b;
|
||||
if (m > c) m = c;
|
||||
return m;
|
||||
}
|
||||
}
|
||||
|
||||
inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
|
||||
inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
|
||||
const Double db(b);
|
||||
const uint64_t bInt = db.IntegerSignificand();
|
||||
const int bExp = db.IntegerExponent();
|
||||
@ -108,9 +108,9 @@ inline int CheckWithinHalfULP(double b, const BigInteger& d, int dExp) {
|
||||
dS.Difference(bS, &delta);
|
||||
|
||||
return delta.Compare(hS);
|
||||
}
|
||||
}
|
||||
|
||||
inline bool StrtodFast(double d, int p, double* result) {
|
||||
inline bool StrtodFast(double d, int p, double* result) {
|
||||
// Use fast path for string-to-double conversion if possible
|
||||
// see http://www.exploringbinary.com/fast-path-decimal-to-floating-point-conversion/
|
||||
if (p > 22 && p < 22 + 16) {
|
||||
@ -125,10 +125,10 @@ inline bool StrtodFast(double d, int p, double* result) {
|
||||
}
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Compute an approximation and see if it is within 1/2 ULP
|
||||
inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) {
|
||||
// Compute an approximation and see if it is within 1/2 ULP
|
||||
inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result) {
|
||||
uint64_t significand = 0;
|
||||
int i = 0; // 2^64 - 1 = 18446744073709551615, 1844674407370955161 = 0x1999999999999999
|
||||
for (; i < dLen; i++) {
|
||||
@ -203,9 +203,9 @@ inline bool StrtodDiyFp(const char* decimals, int dLen, int dExp, double* result
|
||||
*result = rounded.ToDouble();
|
||||
|
||||
return halfWay - static_cast<unsigned>(error) >= precisionBits || precisionBits >= halfWay + static_cast<unsigned>(error);
|
||||
}
|
||||
}
|
||||
|
||||
inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) {
|
||||
inline double StrtodBigInteger(double approx, const char* decimals, int dLen, int dExp) {
|
||||
RAPIDJSON_ASSERT(dLen >= 0);
|
||||
const BigInteger dInt(decimals, static_cast<unsigned>(dLen));
|
||||
Double a(approx);
|
||||
@ -221,9 +221,9 @@ inline double StrtodBigInteger(double approx, const char* decimals, int dLen, in
|
||||
}
|
||||
else // adjustment
|
||||
return a.NextPositiveDouble();
|
||||
}
|
||||
}
|
||||
|
||||
inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
|
||||
inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t length, size_t decimalPosition, int exp) {
|
||||
RAPIDJSON_ASSERT(d >= 0.0);
|
||||
RAPIDJSON_ASSERT(length >= 1);
|
||||
|
||||
@ -282,7 +282,7 @@ inline double StrtodFullPrecision(double d, int p, const char* decimals, size_t
|
||||
|
||||
// Use approximation from StrtodDiyFp and make adjustment with BigInteger comparison
|
||||
return StrtodBigInteger(result, decimals, dLen, dExp);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -19,22 +19,22 @@
|
||||
|
||||
#if defined(__clang__)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
namespace internal {
|
||||
|
||||
//! Custom swap() to avoid dependency on C++ <algorithm> header
|
||||
/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
|
||||
//! Custom swap() to avoid dependency on C++ <algorithm> header
|
||||
/*! \tparam T Type of the arguments to swap, should be instantiated with primitive C++ types only.
|
||||
\note This has the same semantics as std::swap().
|
||||
*/
|
||||
template <typename T>
|
||||
inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
|
||||
template <typename T>
|
||||
inline void Swap(T& a, T& b) RAPIDJSON_NOEXCEPT {
|
||||
T tmp = a;
|
||||
a = b;
|
||||
b = tmp;
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
@ -54,7 +54,7 @@ public:
|
||||
/*!
|
||||
\param stream stream opened for read.
|
||||
*/
|
||||
BasicIStreamWrapper(StreamType &stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
|
||||
BasicIStreamWrapper(StreamType& stream) : stream_(stream), buffer_(peekBuffer_), bufferSize_(4), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
|
||||
Read();
|
||||
}
|
||||
|
||||
@ -64,20 +64,30 @@ public:
|
||||
\param buffer user-supplied buffer.
|
||||
\param bufferSize size of buffer in bytes. Must >=4 bytes.
|
||||
*/
|
||||
BasicIStreamWrapper(StreamType &stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
|
||||
BasicIStreamWrapper(StreamType& stream, char* buffer, size_t bufferSize) : stream_(stream), buffer_(buffer), bufferSize_(bufferSize), bufferLast_(0), current_(buffer_), readCount_(0), count_(0), eof_(false) {
|
||||
RAPIDJSON_ASSERT(bufferSize >= 4);
|
||||
Read();
|
||||
}
|
||||
|
||||
Ch Peek() const { return *current_; }
|
||||
Ch Take() { Ch c = *current_; Read(); return c; }
|
||||
Ch Take() {
|
||||
Ch c = *current_;
|
||||
Read();
|
||||
return c;
|
||||
}
|
||||
size_t Tell() const { return count_ + static_cast<size_t>(current_ - buffer_); }
|
||||
|
||||
// Not implemented
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// For encoding detection only.
|
||||
const Ch* Peek4() const {
|
||||
@ -106,11 +116,11 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
StreamType &stream_;
|
||||
StreamType& stream_;
|
||||
Ch peekBuffer_[4], *buffer_;
|
||||
size_t bufferSize_;
|
||||
Ch *bufferLast_;
|
||||
Ch *current_;
|
||||
Ch* bufferLast_;
|
||||
Ch* current_;
|
||||
size_t readCount_;
|
||||
size_t count_; //!< Number of characters read
|
||||
bool eof_;
|
||||
|
@ -60,7 +60,7 @@ struct GenericMemoryBuffer {
|
||||
typedef GenericMemoryBuffer<> MemoryBuffer;
|
||||
|
||||
//! Implement specialized version of PutN() with memset() for better performance.
|
||||
template<>
|
||||
template <>
|
||||
inline void PutN(MemoryBuffer& memoryBuffer, char c, size_t n) {
|
||||
std::memset(memoryBuffer.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
}
|
||||
|
@ -19,8 +19,8 @@
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(unreachable-code)
|
||||
RAPIDJSON_DIAG_OFF(missing-noreturn)
|
||||
RAPIDJSON_DIAG_OFF(unreachable - code)
|
||||
RAPIDJSON_DIAG_OFF(missing - noreturn)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -40,16 +40,22 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
struct MemoryStream {
|
||||
typedef char Ch; // byte
|
||||
|
||||
MemoryStream(const Ch *src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {}
|
||||
MemoryStream(const Ch* src, size_t size) : src_(src), begin_(src), end_(src + size), size_(size) {}
|
||||
|
||||
Ch Peek() const { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_; }
|
||||
Ch Take() { return RAPIDJSON_UNLIKELY(src_ == end_) ? '\0' : *src_++; }
|
||||
size_t Tell() const { return static_cast<size_t>(src_ - begin_); }
|
||||
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
// For encoding detection only.
|
||||
const Ch* Peek4() const {
|
||||
|
@ -194,11 +194,11 @@ typedef struct {
|
||||
#define SCNiMAX "I64i"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define SCNdPTR "I64d"
|
||||
# define SCNiPTR "I64i"
|
||||
#define SCNdPTR "I64d"
|
||||
#define SCNiPTR "I64i"
|
||||
#else // _WIN64 ][
|
||||
# define SCNdPTR "ld"
|
||||
# define SCNiPTR "li"
|
||||
#define SCNdPTR "ld"
|
||||
#define SCNiPTR "li"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// The fscanf macros for unsigned integers are:
|
||||
@ -260,15 +260,15 @@ typedef struct {
|
||||
#define SCNXMAX "I64X"
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define SCNoPTR "I64o"
|
||||
# define SCNuPTR "I64u"
|
||||
# define SCNxPTR "I64x"
|
||||
# define SCNXPTR "I64X"
|
||||
#define SCNoPTR "I64o"
|
||||
#define SCNuPTR "I64u"
|
||||
#define SCNxPTR "I64x"
|
||||
#define SCNXPTR "I64X"
|
||||
#else // _WIN64 ][
|
||||
# define SCNoPTR "lo"
|
||||
# define SCNuPTR "lu"
|
||||
# define SCNxPTR "lx"
|
||||
# define SCNXPTR "lX"
|
||||
#define SCNoPTR "lo"
|
||||
#define SCNuPTR "lu"
|
||||
#define SCNxPTR "lx"
|
||||
#define SCNXPTR "lX"
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#endif // __STDC_FORMAT_MACROS ]
|
||||
@ -287,8 +287,7 @@ static
|
||||
#else // STATIC_IMAXDIV ][
|
||||
_inline
|
||||
#endif // STATIC_IMAXDIV ]
|
||||
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom)
|
||||
{
|
||||
imaxdiv_t __cdecl imaxdiv(intmax_t numer, intmax_t denom) {
|
||||
imaxdiv_t result;
|
||||
|
||||
result.quot = numer / denom;
|
||||
|
@ -76,10 +76,10 @@
|
||||
// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
|
||||
// Check out Issue 9 for the details.
|
||||
#ifndef INTMAX_C // [
|
||||
# define INTMAX_C INT64_C
|
||||
#define INTMAX_C INT64_C
|
||||
#endif // INTMAX_C ]
|
||||
#ifndef UINTMAX_C // [
|
||||
# define UINTMAX_C UINT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
#endif // UINTMAX_C ]
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
@ -95,18 +95,18 @@
|
||||
#if defined(__cplusplus) && !defined(_M_ARM)
|
||||
extern "C" {
|
||||
#endif
|
||||
# include <wchar.h>
|
||||
#include <wchar.h>
|
||||
#if defined(__cplusplus) && !defined(_M_ARM)
|
||||
}
|
||||
#endif
|
||||
|
||||
// Define _W64 macros to mark types changing their size, like intptr_t.
|
||||
#ifndef _W64
|
||||
# if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
# define _W64 __w64
|
||||
# else
|
||||
# define _W64
|
||||
# endif
|
||||
#if !defined(__midl) && (defined(_X86_) || defined(_M_IX86)) && _MSC_VER >= 1300
|
||||
#define _W64 __w64
|
||||
#else
|
||||
#define _W64
|
||||
#endif
|
||||
#endif
|
||||
|
||||
|
||||
@ -118,19 +118,19 @@ extern "C" {
|
||||
// realize that, e.g. char has the same size as __int8
|
||||
// so we give up on __intX for them.
|
||||
#if (_MSC_VER < 1300)
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
typedef signed char int8_t;
|
||||
typedef signed short int16_t;
|
||||
typedef signed int int32_t;
|
||||
typedef unsigned char uint8_t;
|
||||
typedef unsigned short uint16_t;
|
||||
typedef unsigned int uint32_t;
|
||||
#else
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
typedef signed __int8 int8_t;
|
||||
typedef signed __int16 int16_t;
|
||||
typedef signed __int32 int32_t;
|
||||
typedef unsigned __int8 uint8_t;
|
||||
typedef unsigned __int16 uint16_t;
|
||||
typedef unsigned __int32 uint32_t;
|
||||
#endif
|
||||
typedef signed __int64 int64_t;
|
||||
typedef unsigned __int64 uint64_t;
|
||||
@ -158,11 +158,11 @@ typedef uint64_t uint_fast64_t;
|
||||
|
||||
// 7.18.1.4 Integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
typedef signed __int64 intptr_t;
|
||||
typedef unsigned __int64 uintptr_t;
|
||||
#else // _WIN64 ][
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
typedef _W64 signed int intptr_t;
|
||||
typedef _W64 unsigned int uintptr_t;
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.1.5 Greatest-width integer types
|
||||
@ -218,13 +218,13 @@ typedef uint64_t uintmax_t;
|
||||
|
||||
// 7.18.2.4 Limits of integer types capable of holding object pointers
|
||||
#ifdef _WIN64 // [
|
||||
# define INTPTR_MIN INT64_MIN
|
||||
# define INTPTR_MAX INT64_MAX
|
||||
# define UINTPTR_MAX UINT64_MAX
|
||||
#define INTPTR_MIN INT64_MIN
|
||||
#define INTPTR_MAX INT64_MAX
|
||||
#define UINTPTR_MAX UINT64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define INTPTR_MIN INT32_MIN
|
||||
# define INTPTR_MAX INT32_MAX
|
||||
# define UINTPTR_MAX UINT32_MAX
|
||||
#define INTPTR_MIN INT32_MIN
|
||||
#define INTPTR_MAX INT32_MAX
|
||||
#define UINTPTR_MAX UINT32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
// 7.18.2.5 Limits of greatest-width integer types
|
||||
@ -235,30 +235,30 @@ typedef uint64_t uintmax_t;
|
||||
// 7.18.3 Limits of other integer types
|
||||
|
||||
#ifdef _WIN64 // [
|
||||
# define PTRDIFF_MIN _I64_MIN
|
||||
# define PTRDIFF_MAX _I64_MAX
|
||||
#define PTRDIFF_MIN _I64_MIN
|
||||
#define PTRDIFF_MAX _I64_MAX
|
||||
#else // _WIN64 ][
|
||||
# define PTRDIFF_MIN _I32_MIN
|
||||
# define PTRDIFF_MAX _I32_MAX
|
||||
#define PTRDIFF_MIN _I32_MIN
|
||||
#define PTRDIFF_MAX _I32_MAX
|
||||
#endif // _WIN64 ]
|
||||
|
||||
#define SIG_ATOMIC_MIN INT_MIN
|
||||
#define SIG_ATOMIC_MAX INT_MAX
|
||||
|
||||
#ifndef SIZE_MAX // [
|
||||
# ifdef _WIN64 // [
|
||||
# define SIZE_MAX _UI64_MAX
|
||||
# else // _WIN64 ][
|
||||
# define SIZE_MAX _UI32_MAX
|
||||
# endif // _WIN64 ]
|
||||
#ifdef _WIN64 // [
|
||||
#define SIZE_MAX _UI64_MAX
|
||||
#else // _WIN64 ][
|
||||
#define SIZE_MAX _UI32_MAX
|
||||
#endif // _WIN64 ]
|
||||
#endif // SIZE_MAX ]
|
||||
|
||||
// WCHAR_MIN and WCHAR_MAX are also defined in <wchar.h>
|
||||
#ifndef WCHAR_MIN // [
|
||||
# define WCHAR_MIN 0
|
||||
#define WCHAR_MIN 0
|
||||
#endif // WCHAR_MIN ]
|
||||
#ifndef WCHAR_MAX // [
|
||||
# define WCHAR_MAX _UI16_MAX
|
||||
#define WCHAR_MAX _UI16_MAX
|
||||
#endif // WCHAR_MAX ]
|
||||
|
||||
#define WINT_MIN 0
|
||||
@ -287,10 +287,10 @@ typedef uint64_t uintmax_t;
|
||||
// These #ifndef's are needed to prevent collisions with <boost/cstdint.hpp>.
|
||||
// Check out Issue 9 for the details.
|
||||
#ifndef INTMAX_C // [
|
||||
# define INTMAX_C INT64_C
|
||||
#define INTMAX_C INT64_C
|
||||
#endif // INTMAX_C ]
|
||||
#ifndef UINTMAX_C // [
|
||||
# define UINTMAX_C UINT64_C
|
||||
#define UINTMAX_C UINT64_C
|
||||
#endif // UINTMAX_C ]
|
||||
|
||||
#endif // __STDC_CONSTANT_MACROS ]
|
||||
|
@ -56,11 +56,26 @@ public:
|
||||
}
|
||||
|
||||
// Not implemented
|
||||
char Peek() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char Take() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t Tell() const { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(char*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
char Peek() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
char Take() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t Tell() const {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
char* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
size_t PutEnd(char*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
BasicOStreamWrapper(const BasicOStreamWrapper&);
|
||||
|
@ -20,7 +20,7 @@
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
RAPIDJSON_DIAG_OFF(switch - enum)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
|
||||
@ -244,7 +244,7 @@ public:
|
||||
GenericPointer Append(const Token& token, Allocator* allocator = 0) const {
|
||||
GenericPointer r;
|
||||
r.allocator_ = allocator;
|
||||
Ch *p = r.CopyFromRaw(*this, 1, token.length + 1);
|
||||
Ch* p = r.CopyFromRaw(*this, 1, token.length + 1);
|
||||
std::memcpy(p, token.name, (token.length + 1) * sizeof(Ch));
|
||||
r.tokens_[tokenCount_].name = p;
|
||||
r.tokens_[tokenCount_].length = token.length;
|
||||
@ -271,7 +271,7 @@ public:
|
||||
\return A new Pointer with appended token.
|
||||
*/
|
||||
template <typename T>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch> >), (GenericPointer))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr<internal::IsSame<typename internal::RemoveConst<T>::Type, Ch>>), (GenericPointer))
|
||||
Append(T* name, Allocator* allocator = 0) const {
|
||||
return Append(name, internal::StrLen(name), allocator);
|
||||
}
|
||||
@ -371,8 +371,7 @@ public:
|
||||
for (size_t i = 0; i < tokenCount_; i++) {
|
||||
if (tokens_[i].index != rhs.tokens_[i].index ||
|
||||
tokens_[i].length != rhs.tokens_[i].length ||
|
||||
(tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch)* tokens_[i].length) != 0))
|
||||
{
|
||||
(tokens_[i].length != 0 && std::memcmp(tokens_[i].name, rhs.tokens_[i].name, sizeof(Ch) * tokens_[i].length) != 0)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@ -423,7 +422,7 @@ public:
|
||||
\tparam OutputStream Type of output stream.
|
||||
\param os The output stream.
|
||||
*/
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
bool Stringify(OutputStream& os) const {
|
||||
return Stringify<false, OutputStream>(os);
|
||||
}
|
||||
@ -433,7 +432,7 @@ public:
|
||||
\tparam OutputStream Type of output stream.
|
||||
\param os The output stream.
|
||||
*/
|
||||
template<typename OutputStream>
|
||||
template <typename OutputStream>
|
||||
bool StringifyUriFragment(OutputStream& os) const {
|
||||
return Stringify<true, OutputStream>(os);
|
||||
}
|
||||
@ -462,7 +461,7 @@ public:
|
||||
RAPIDJSON_ASSERT(IsValid());
|
||||
ValueType* v = &root;
|
||||
bool exist = true;
|
||||
for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
for (const Token* t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
if (v->IsArray() && t->name[0] == '-' && t->length == 1) {
|
||||
v->PushBack(ValueType().Move(), allocator);
|
||||
v = &((*v)[v->Size() - 1]);
|
||||
@ -540,10 +539,9 @@ public:
|
||||
ValueType* Get(ValueType& root, size_t* unresolvedTokenIndex = 0) const {
|
||||
RAPIDJSON_ASSERT(IsValid());
|
||||
ValueType* v = &root;
|
||||
for (const Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
for (const Token* t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
switch (v->GetType()) {
|
||||
case kObjectType:
|
||||
{
|
||||
case kObjectType: {
|
||||
typename ValueType::MemberIterator m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
|
||||
if (m == v->MemberEnd())
|
||||
break;
|
||||
@ -618,7 +616,7 @@ public:
|
||||
\tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
|
||||
*/
|
||||
template <typename T>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>), (ValueType&))
|
||||
GetWithDefault(ValueType& root, T defaultValue, typename ValueType::AllocatorType& allocator) const {
|
||||
return GetWithDefault(root, ValueType(defaultValue).Move(), allocator);
|
||||
}
|
||||
@ -648,7 +646,7 @@ public:
|
||||
\tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
|
||||
*/
|
||||
template <typename T, typename stackAllocator>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>), (ValueType&))
|
||||
GetWithDefault(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T defaultValue) const {
|
||||
return GetWithDefault(document, defaultValue, document.GetAllocator());
|
||||
}
|
||||
@ -694,7 +692,7 @@ public:
|
||||
\tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
|
||||
*/
|
||||
template <typename T>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>), (ValueType&))
|
||||
Set(ValueType& root, T value, typename ValueType::AllocatorType& allocator) const {
|
||||
return Create(root, allocator) = ValueType(value).Move();
|
||||
}
|
||||
@ -730,7 +728,7 @@ public:
|
||||
\tparam T Either \ref Type, \c int, \c unsigned, \c int64_t, \c uint64_t, \c bool
|
||||
*/
|
||||
template <typename T, typename stackAllocator>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T> >), (ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T>, internal::IsGenericValue<T>>), (ValueType&))
|
||||
Set(GenericDocument<EncodingType, typename ValueType::AllocatorType, stackAllocator>& document, T value) const {
|
||||
return Create(document) = value;
|
||||
}
|
||||
@ -776,16 +774,14 @@ public:
|
||||
|
||||
ValueType* v = &root;
|
||||
const Token* last = tokens_ + (tokenCount_ - 1);
|
||||
for (const Token *t = tokens_; t != last; ++t) {
|
||||
for (const Token* t = tokens_; t != last; ++t) {
|
||||
switch (v->GetType()) {
|
||||
case kObjectType:
|
||||
{
|
||||
case kObjectType: {
|
||||
typename ValueType::MemberIterator m = v->FindMember(GenericValue<EncodingType>(GenericStringRef<Ch>(t->name, t->length)));
|
||||
if (m == v->MemberEnd())
|
||||
return false;
|
||||
v = &m->value;
|
||||
}
|
||||
break;
|
||||
} break;
|
||||
case kArrayType:
|
||||
if (t->index == kPointerInvalidIndex || t->index >= v->Size())
|
||||
return false;
|
||||
@ -822,12 +818,12 @@ private:
|
||||
ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
|
||||
|
||||
size_t nameBufferSize = rhs.tokenCount_; // null terminators for tokens
|
||||
for (Token *t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t)
|
||||
for (Token* t = rhs.tokens_; t != rhs.tokens_ + rhs.tokenCount_; ++t)
|
||||
nameBufferSize += t->length;
|
||||
|
||||
tokenCount_ = rhs.tokenCount_ + extraToken;
|
||||
tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + (nameBufferSize + extraNameBufferSize) * sizeof(Ch)));
|
||||
nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
|
||||
tokens_ = static_cast<Token*>(allocator_->Malloc(tokenCount_ * sizeof(Token) + (nameBufferSize + extraNameBufferSize) * sizeof(Ch)));
|
||||
nameBuffer_ = reinterpret_cast<Ch*>(tokens_ + tokenCount_);
|
||||
if (rhs.tokenCount_ > 0) {
|
||||
std::memcpy(tokens_, rhs.tokens_, rhs.tokenCount_ * sizeof(Token));
|
||||
}
|
||||
@ -837,7 +833,7 @@ private:
|
||||
|
||||
// Adjust pointers to name buffer
|
||||
std::ptrdiff_t diff = nameBuffer_ - rhs.nameBuffer_;
|
||||
for (Token *t = tokens_; t != tokens_ + rhs.tokenCount_; ++t)
|
||||
for (Token* t = tokens_; t != tokens_ + rhs.tokenCount_; ++t)
|
||||
t->name += diff;
|
||||
|
||||
return nameBuffer_ + nameBufferSize;
|
||||
@ -849,7 +845,7 @@ private:
|
||||
\param c The character (code unit) to be tested.
|
||||
*/
|
||||
bool NeedPercentEncode(Ch c) const {
|
||||
return !((c >= '0' && c <= '9') || (c >= 'A' && c <='Z') || (c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '_' || c =='~');
|
||||
return !((c >= '0' && c <= '9') || (c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z') || c == '-' || c == '.' || c == '_' || c == '~');
|
||||
}
|
||||
|
||||
//! Parse a JSON String or its URI fragment representation into tokens.
|
||||
@ -875,8 +871,8 @@ private:
|
||||
if (*s == '/')
|
||||
tokenCount_++;
|
||||
|
||||
Token* token = tokens_ = static_cast<Token *>(allocator_->Malloc(tokenCount_ * sizeof(Token) + length * sizeof(Ch)));
|
||||
Ch* name = nameBuffer_ = reinterpret_cast<Ch *>(tokens_ + tokenCount_);
|
||||
Token* token = tokens_ = static_cast<Token*>(allocator_->Malloc(tokenCount_ * sizeof(Token) + length * sizeof(Ch)));
|
||||
Ch* name = nameBuffer_ = reinterpret_cast<Ch*>(tokens_ + tokenCount_);
|
||||
size_t i = 0;
|
||||
|
||||
// Detect if it is a URI fragment
|
||||
@ -933,8 +929,10 @@ private:
|
||||
if (c == '~') {
|
||||
if (i < length) {
|
||||
c = source[i];
|
||||
if (c == '0') c = '~';
|
||||
else if (c == '1') c = '/';
|
||||
if (c == '0')
|
||||
c = '~';
|
||||
else if (c == '1')
|
||||
c = '/';
|
||||
else {
|
||||
parseErrorCode_ = kPointerParseErrorInvalidEscape;
|
||||
goto error;
|
||||
@ -998,14 +996,14 @@ private:
|
||||
\tparam OutputStream type of output stream.
|
||||
\param os The output stream.
|
||||
*/
|
||||
template<bool uriFragment, typename OutputStream>
|
||||
template <bool uriFragment, typename OutputStream>
|
||||
bool Stringify(OutputStream& os) const {
|
||||
RAPIDJSON_ASSERT(IsValid());
|
||||
|
||||
if (uriFragment)
|
||||
os.Put('#');
|
||||
|
||||
for (Token *t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
for (Token* t = tokens_; t != tokens_ + tokenCount_; ++t) {
|
||||
os.Put('/');
|
||||
for (size_t j = 0; j < t->length; j++) {
|
||||
Ch c = t->name[j];
|
||||
@ -1021,7 +1019,7 @@ private:
|
||||
// Transcode to UTF8 sequence
|
||||
GenericStringStream<typename ValueType::EncodingType> source(&t->name[j]);
|
||||
PercentEncodeStream<OutputStream> target(os);
|
||||
if (!Transcoder<EncodingType, UTF8<> >().Validate(source, target))
|
||||
if (!Transcoder<EncodingType, UTF8<>>().Validate(source, target))
|
||||
return false;
|
||||
j += source.Tell() - 1;
|
||||
}
|
||||
@ -1059,9 +1057,12 @@ private:
|
||||
for (int j = 0; j < 2; j++) {
|
||||
c = static_cast<Ch>(c << 4);
|
||||
Ch h = *src_;
|
||||
if (h >= '0' && h <= '9') c = static_cast<Ch>(c + h - '0');
|
||||
else if (h >= 'A' && h <= 'F') c = static_cast<Ch>(c + h - 'A' + 10);
|
||||
else if (h >= 'a' && h <= 'f') c = static_cast<Ch>(c + h - 'a' + 10);
|
||||
if (h >= '0' && h <= '9')
|
||||
c = static_cast<Ch>(c + h - '0');
|
||||
else if (h >= 'A' && h <= 'F')
|
||||
c = static_cast<Ch>(c + h - 'A' + 10);
|
||||
else if (h >= 'a' && h <= 'f')
|
||||
c = static_cast<Ch>(c + h - 'a' + 10);
|
||||
else {
|
||||
valid_ = false;
|
||||
return 0;
|
||||
@ -1093,6 +1094,7 @@ private:
|
||||
os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u >> 4]));
|
||||
os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[u & 15]));
|
||||
}
|
||||
|
||||
private:
|
||||
OutputStream& os_;
|
||||
};
|
||||
@ -1120,7 +1122,7 @@ typename T::ValueType& CreateValueByPointer(T& root, const GenericPointer<typena
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& CreateValueByPointer(T& root, const CharType(&source)[N], typename T::AllocatorType& a) {
|
||||
typename T::ValueType& CreateValueByPointer(T& root, const CharType (&source)[N], typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Create(root, a);
|
||||
}
|
||||
|
||||
@ -1132,7 +1134,7 @@ typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, c
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const CharType(&source)[N]) {
|
||||
typename DocumentType::ValueType& CreateValueByPointer(DocumentType& document, const CharType (&source)[N]) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Create(document);
|
||||
}
|
||||
|
||||
@ -1154,7 +1156,7 @@ typename T::ValueType* GetValueByPointer(T& root, const CharType (&source)[N], s
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
const typename T::ValueType* GetValueByPointer(const T& root, const CharType(&source)[N], size_t* unresolvedTokenIndex = 0) {
|
||||
const typename T::ValueType* GetValueByPointer(const T& root, const CharType (&source)[N], size_t* unresolvedTokenIndex = 0) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Get(root, unresolvedTokenIndex);
|
||||
}
|
||||
|
||||
@ -1178,31 +1180,31 @@ typename T::ValueType& GetValueByPointerWithDefault(T& root, const GenericPointe
|
||||
#endif
|
||||
|
||||
template <typename T, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename T::ValueType&))
|
||||
GetValueByPointerWithDefault(T& root, const GenericPointer<typename T::ValueType>& pointer, T2 defaultValue, typename T::AllocatorType& a) {
|
||||
return pointer.GetWithDefault(root, defaultValue, a);
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::ValueType& defaultValue, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType (&source)[N], const typename T::ValueType& defaultValue, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const typename T::Ch* defaultValue, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType (&source)[N], const typename T::Ch* defaultValue, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
|
||||
}
|
||||
|
||||
#if RAPIDJSON_HAS_STDSTRING
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType(&source)[N], const std::basic_string<typename T::Ch>& defaultValue, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& GetValueByPointerWithDefault(T& root, const CharType (&source)[N], const std::basic_string<typename T::Ch>& defaultValue, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, typename CharType, size_t N, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
|
||||
GetValueByPointerWithDefault(T& root, const CharType(&source)[N], T2 defaultValue, typename T::AllocatorType& a) {
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename T::ValueType&))
|
||||
GetValueByPointerWithDefault(T& root, const CharType (&source)[N], T2 defaultValue, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).GetWithDefault(root, defaultValue, a);
|
||||
}
|
||||
|
||||
@ -1226,31 +1228,31 @@ typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& doc
|
||||
#endif
|
||||
|
||||
template <typename DocumentType, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename DocumentType::ValueType&))
|
||||
GetValueByPointerWithDefault(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, T2 defaultValue) {
|
||||
return pointer.GetWithDefault(document, defaultValue);
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& defaultValue) {
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType (&source)[N], const typename DocumentType::ValueType& defaultValue) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* defaultValue) {
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType (&source)[N], const typename DocumentType::Ch* defaultValue) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
|
||||
}
|
||||
|
||||
#if RAPIDJSON_HAS_STDSTRING
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], const std::basic_string<typename DocumentType::Ch>& defaultValue) {
|
||||
typename DocumentType::ValueType& GetValueByPointerWithDefault(DocumentType& document, const CharType (&source)[N], const std::basic_string<typename DocumentType::Ch>& defaultValue) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
|
||||
GetValueByPointerWithDefault(DocumentType& document, const CharType(&source)[N], T2 defaultValue) {
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename DocumentType::ValueType&))
|
||||
GetValueByPointerWithDefault(DocumentType& document, const CharType (&source)[N], T2 defaultValue) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).GetWithDefault(document, defaultValue);
|
||||
}
|
||||
|
||||
@ -1279,36 +1281,36 @@ typename T::ValueType& SetValueByPointer(T& root, const GenericPointer<typename
|
||||
#endif
|
||||
|
||||
template <typename T, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename T::ValueType&))
|
||||
SetValueByPointer(T& root, const GenericPointer<typename T::ValueType>& pointer, T2 value, typename T::AllocatorType& a) {
|
||||
return pointer.Set(root, value, a);
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType (&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType (&source)[N], const typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType (&source)[N], const typename T::Ch* value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
|
||||
}
|
||||
|
||||
#if RAPIDJSON_HAS_STDSTRING
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType(&source)[N], const std::basic_string<typename T::Ch>& value, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& SetValueByPointer(T& root, const CharType (&source)[N], const std::basic_string<typename T::Ch>& value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename T, typename CharType, size_t N, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename T::ValueType&))
|
||||
SetValueByPointer(T& root, const CharType(&source)[N], T2 value, typename T::AllocatorType& a) {
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename T::ValueType&))
|
||||
SetValueByPointer(T& root, const CharType (&source)[N], T2 value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Set(root, value, a);
|
||||
}
|
||||
|
||||
@ -1337,36 +1339,36 @@ typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, cons
|
||||
#endif
|
||||
|
||||
template <typename DocumentType, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename DocumentType::ValueType&))
|
||||
SetValueByPointer(DocumentType& document, const GenericPointer<typename DocumentType::ValueType>& pointer, T2 value) {
|
||||
return pointer.Set(document, value);
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) {
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType (&source)[N], typename DocumentType::ValueType& value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::ValueType& value) {
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType (&source)[N], const typename DocumentType::ValueType& value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const typename DocumentType::Ch* value) {
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType (&source)[N], const typename DocumentType::Ch* value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
|
||||
}
|
||||
|
||||
#if RAPIDJSON_HAS_STDSTRING
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType(&source)[N], const std::basic_string<typename DocumentType::Ch>& value) {
|
||||
typename DocumentType::ValueType& SetValueByPointer(DocumentType& document, const CharType (&source)[N], const std::basic_string<typename DocumentType::Ch>& value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N, typename T2>
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2> >), (typename DocumentType::ValueType&))
|
||||
SetValueByPointer(DocumentType& document, const CharType(&source)[N], T2 value) {
|
||||
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr<internal::IsPointer<T2>, internal::IsGenericValue<T2>>), (typename DocumentType::ValueType&))
|
||||
SetValueByPointer(DocumentType& document, const CharType (&source)[N], T2 value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Set(document, value);
|
||||
}
|
||||
|
||||
@ -1378,7 +1380,7 @@ typename T::ValueType& SwapValueByPointer(T& root, const GenericPointer<typename
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
typename T::ValueType& SwapValueByPointer(T& root, const CharType(&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
typename T::ValueType& SwapValueByPointer(T& root, const CharType (&source)[N], typename T::ValueType& value, typename T::AllocatorType& a) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Swap(root, value, a);
|
||||
}
|
||||
|
||||
@ -1388,7 +1390,7 @@ typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, con
|
||||
}
|
||||
|
||||
template <typename DocumentType, typename CharType, size_t N>
|
||||
typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const CharType(&source)[N], typename DocumentType::ValueType& value) {
|
||||
typename DocumentType::ValueType& SwapValueByPointer(DocumentType& document, const CharType (&source)[N], typename DocumentType::ValueType& value) {
|
||||
return GenericPointer<typename DocumentType::ValueType>(source, N - 1).Swap(document, value);
|
||||
}
|
||||
|
||||
@ -1400,7 +1402,7 @@ bool EraseValueByPointer(T& root, const GenericPointer<typename T::ValueType>& p
|
||||
}
|
||||
|
||||
template <typename T, typename CharType, size_t N>
|
||||
bool EraseValueByPointer(T& root, const CharType(&source)[N]) {
|
||||
bool EraseValueByPointer(T& root, const CharType (&source)[N]) {
|
||||
return GenericPointer<typename T::ValueType>(source, N - 1).Erase(root);
|
||||
}
|
||||
|
||||
|
@ -24,7 +24,7 @@ RAPIDJSON_DIAG_OFF(effc++)
|
||||
|
||||
#if defined(__clang__)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -44,7 +44,7 @@ enum PrettyFormatOptions {
|
||||
\tparam TargetEncoding Encoding of output stream.
|
||||
\tparam StackAllocator Type of allocator for allocating memory of stack.
|
||||
*/
|
||||
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
|
||||
template <typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
|
||||
class PrettyWriter : public Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> {
|
||||
public:
|
||||
typedef Writer<OutputStream, SourceEncoding, TargetEncoding, StackAllocator, writeFlags> Base;
|
||||
@ -55,16 +55,13 @@ public:
|
||||
\param allocator User supplied allocator. If it is null, it will create a private one.
|
||||
\param levelDepth Initial capacity of stack.
|
||||
*/
|
||||
explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
|
||||
Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
|
||||
explicit PrettyWriter(OutputStream& os, StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : Base(os, allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
|
||||
|
||||
|
||||
explicit PrettyWriter(StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) :
|
||||
Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
|
||||
explicit PrettyWriter(StackAllocator* allocator = 0, size_t levelDepth = Base::kDefaultLevelDepth) : Base(allocator, levelDepth), indentChar_(' '), indentCharCount_(4), formatOptions_(kFormatDefault) {}
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
PrettyWriter(PrettyWriter&& rhs) :
|
||||
Base(std::forward<PrettyWriter>(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {}
|
||||
PrettyWriter(PrettyWriter&& rhs) : Base(std::forward<PrettyWriter>(rhs)), indentChar_(rhs.indentChar_), indentCharCount_(rhs.indentCharCount_), formatOptions_(rhs.formatOptions_) {}
|
||||
#endif
|
||||
|
||||
//! Set custom indentation.
|
||||
@ -92,13 +89,34 @@ public:
|
||||
*/
|
||||
//@{
|
||||
|
||||
bool Null() { PrettyPrefix(kNullType); return Base::EndValue(Base::WriteNull()); }
|
||||
bool Bool(bool b) { PrettyPrefix(b ? kTrueType : kFalseType); return Base::EndValue(Base::WriteBool(b)); }
|
||||
bool Int(int i) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt(i)); }
|
||||
bool Uint(unsigned u) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint(u)); }
|
||||
bool Int64(int64_t i64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteInt64(i64)); }
|
||||
bool Uint64(uint64_t u64) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteUint64(u64)); }
|
||||
bool Double(double d) { PrettyPrefix(kNumberType); return Base::EndValue(Base::WriteDouble(d)); }
|
||||
bool Null() {
|
||||
PrettyPrefix(kNullType);
|
||||
return Base::EndValue(Base::WriteNull());
|
||||
}
|
||||
bool Bool(bool b) {
|
||||
PrettyPrefix(b ? kTrueType : kFalseType);
|
||||
return Base::EndValue(Base::WriteBool(b));
|
||||
}
|
||||
bool Int(int i) {
|
||||
PrettyPrefix(kNumberType);
|
||||
return Base::EndValue(Base::WriteInt(i));
|
||||
}
|
||||
bool Uint(unsigned u) {
|
||||
PrettyPrefix(kNumberType);
|
||||
return Base::EndValue(Base::WriteUint(u));
|
||||
}
|
||||
bool Int64(int64_t i64) {
|
||||
PrettyPrefix(kNumberType);
|
||||
return Base::EndValue(Base::WriteInt64(i64));
|
||||
}
|
||||
bool Uint64(uint64_t u64) {
|
||||
PrettyPrefix(kNumberType);
|
||||
return Base::EndValue(Base::WriteUint64(u64));
|
||||
}
|
||||
bool Double(double d) {
|
||||
PrettyPrefix(kNumberType);
|
||||
return Base::EndValue(Base::WriteDouble(d));
|
||||
}
|
||||
|
||||
bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
|
||||
RAPIDJSON_ASSERT(str != 0);
|
||||
|
@ -244,41 +244,41 @@
|
||||
*/
|
||||
#ifndef RAPIDJSON_ENDIAN
|
||||
// Detect with GCC 4.6's macro
|
||||
# ifdef __BYTE_ORDER__
|
||||
# if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
# elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
# else
|
||||
# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
# endif // __BYTE_ORDER__
|
||||
#ifdef __BYTE_ORDER__
|
||||
#if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
#elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
#else
|
||||
#error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
#endif // __BYTE_ORDER__
|
||||
// Detect with GLIBC's endian.h
|
||||
# elif defined(__GLIBC__)
|
||||
# include <endian.h>
|
||||
# if (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
# elif (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
# else
|
||||
# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
# endif // __GLIBC__
|
||||
#elif defined(__GLIBC__)
|
||||
#include <endian.h>
|
||||
#if (__BYTE_ORDER == __LITTLE_ENDIAN)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
#elif (__BYTE_ORDER == __BIG_ENDIAN)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
#else
|
||||
#error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
#endif // __GLIBC__
|
||||
// Detect with _LITTLE_ENDIAN and _BIG_ENDIAN macro
|
||||
# elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
# elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
#elif defined(_LITTLE_ENDIAN) && !defined(_BIG_ENDIAN)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
#elif defined(_BIG_ENDIAN) && !defined(_LITTLE_ENDIAN)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
// Detect with architecture macros
|
||||
# elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
# elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__)
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
# elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
||||
# define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
# elif defined(RAPIDJSON_DOXYGEN_RUNNING)
|
||||
# define RAPIDJSON_ENDIAN
|
||||
# else
|
||||
# error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
# endif
|
||||
#elif defined(__sparc) || defined(__sparc__) || defined(_POWER) || defined(__powerpc__) || defined(__ppc__) || defined(__hpux) || defined(__hppa) || defined(_MIPSEB) || defined(_POWER) || defined(__s390__)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_BIGENDIAN
|
||||
#elif defined(__i386__) || defined(__alpha__) || defined(__ia64) || defined(__ia64__) || defined(_M_IX86) || defined(_M_IA64) || defined(_M_ALPHA) || defined(__amd64) || defined(__amd64__) || defined(_M_AMD64) || defined(__x86_64) || defined(__x86_64__) || defined(_M_X64) || defined(__bfin__)
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
#elif defined(_MSC_VER) && (defined(_M_ARM) || defined(_M_ARM64))
|
||||
#define RAPIDJSON_ENDIAN RAPIDJSON_LITTLEENDIAN
|
||||
#elif defined(RAPIDJSON_DOXYGEN_RUNNING)
|
||||
#define RAPIDJSON_ENDIAN
|
||||
#else
|
||||
#error Unknown machine endianness detected. User needs to define RAPIDJSON_ENDIAN.
|
||||
#endif
|
||||
#endif // RAPIDJSON_ENDIAN
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
@ -343,8 +343,8 @@
|
||||
#if RAPIDJSON_64BIT != 1
|
||||
#error RAPIDJSON_48BITPOINTER_OPTIMIZATION can only be set to 1 when RAPIDJSON_64BIT=1
|
||||
#endif
|
||||
#define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast<type *>((reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast<uintptr_t>(reinterpret_cast<const void*>(x))))
|
||||
#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type *>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
|
||||
#define RAPIDJSON_SETPOINTER(type, p, x) (p = reinterpret_cast<type*>((reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0xFFFF0000, 0x00000000))) | reinterpret_cast<uintptr_t>(reinterpret_cast<const void*>(x))))
|
||||
#define RAPIDJSON_GETPOINTER(type, p) (reinterpret_cast<type*>(reinterpret_cast<uintptr_t>(p) & static_cast<uintptr_t>(RAPIDJSON_UINT64_C2(0x0000FFFF, 0xFFFFFFFF))))
|
||||
#else
|
||||
#define RAPIDJSON_SETPOINTER(type, p, x) (p = (x))
|
||||
#define RAPIDJSON_GETPOINTER(type, p) (p)
|
||||
@ -379,8 +379,7 @@
|
||||
If any of these symbols is defined, RapidJSON defines the macro
|
||||
\c RAPIDJSON_SIMD to indicate the availability of the optimized code.
|
||||
*/
|
||||
#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) \
|
||||
|| defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
|
||||
#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42) || defined(RAPIDJSON_NEON) || defined(RAPIDJSON_DOXYGEN_RUNNING)
|
||||
#define RAPIDJSON_SIMD
|
||||
#endif
|
||||
|
||||
@ -442,7 +441,7 @@ RAPIDJSON_NAMESPACE_END
|
||||
|
||||
// Prefer C++11 static_assert, if available
|
||||
#ifndef RAPIDJSON_STATIC_ASSERT
|
||||
#if RAPIDJSON_CPLUSPLUS >= 201103L || ( defined(_MSC_VER) && _MSC_VER >= 1800 )
|
||||
#if RAPIDJSON_CPLUSPLUS >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800)
|
||||
#define RAPIDJSON_STATIC_ASSERT(x) \
|
||||
static_assert(x, RAPIDJSON_STRINGIFY(x))
|
||||
#endif // C++11
|
||||
@ -454,9 +453,14 @@ RAPIDJSON_NAMESPACE_END
|
||||
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
|
||||
#endif
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
template <bool x> struct STATIC_ASSERTION_FAILURE;
|
||||
template <> struct STATIC_ASSERTION_FAILURE<true> { enum { value = 1 }; };
|
||||
template <size_t x> struct StaticAssertTest {};
|
||||
template <bool x>
|
||||
struct STATIC_ASSERTION_FAILURE;
|
||||
template <>
|
||||
struct STATIC_ASSERTION_FAILURE<true> {
|
||||
enum { value = 1 };
|
||||
};
|
||||
template <size_t x>
|
||||
struct StaticAssertTest {};
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#if defined(__GNUC__) || defined(__clang__)
|
||||
@ -475,7 +479,7 @@ RAPIDJSON_NAMESPACE_END
|
||||
*/
|
||||
#define RAPIDJSON_STATIC_ASSERT(x) \
|
||||
typedef ::RAPIDJSON_NAMESPACE::StaticAssertTest< \
|
||||
sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x) >)> \
|
||||
sizeof(::RAPIDJSON_NAMESPACE::STATIC_ASSERTION_FAILURE<bool(x)>)> \
|
||||
RAPIDJSON_JOIN(StaticAssertTypedef, __LINE__) RAPIDJSON_STATIC_ASSERT_UNUSED_ATTRIBUTE
|
||||
#endif // RAPIDJSON_STATIC_ASSERT
|
||||
|
||||
@ -515,10 +519,11 @@ RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#define RAPIDJSON_MULTILINEMACRO_BEGIN do {
|
||||
#define RAPIDJSON_MULTILINEMACRO_END \
|
||||
} while((void)0, 0)
|
||||
} \
|
||||
while ((void)0, 0)
|
||||
|
||||
// adopted from Boost
|
||||
#define RAPIDJSON_VERSION_CODE(x,y,z) \
|
||||
#define RAPIDJSON_VERSION_CODE(x, y, z) \
|
||||
(((x)*100000) + ((y)*100) + (z))
|
||||
|
||||
#if defined(__has_builtin)
|
||||
@ -532,18 +537,18 @@ RAPIDJSON_NAMESPACE_END
|
||||
|
||||
#if defined(__GNUC__)
|
||||
#define RAPIDJSON_GNUC \
|
||||
RAPIDJSON_VERSION_CODE(__GNUC__,__GNUC_MINOR__,__GNUC_PATCHLEVEL__)
|
||||
RAPIDJSON_VERSION_CODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__)
|
||||
#endif
|
||||
|
||||
#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,2,0))
|
||||
#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 2, 0))
|
||||
|
||||
#define RAPIDJSON_PRAGMA(x) _Pragma(RAPIDJSON_STRINGIFY(x))
|
||||
#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(GCC diagnostic x)
|
||||
#define RAPIDJSON_DIAG_OFF(x) \
|
||||
RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W,x)))
|
||||
RAPIDJSON_DIAG_PRAGMA(ignored RAPIDJSON_STRINGIFY(RAPIDJSON_JOIN(-W, x)))
|
||||
|
||||
// push/pop support in Clang and GCC>=4.6
|
||||
#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0))
|
||||
#if defined(__clang__) || (defined(RAPIDJSON_GNUC) && RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0))
|
||||
#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
|
||||
#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
|
||||
#else // GCC >= 4.2, < 4.6
|
||||
@ -557,7 +562,8 @@ RAPIDJSON_NAMESPACE_END
|
||||
#define RAPIDJSON_PRAGMA(x) __pragma(x)
|
||||
#define RAPIDJSON_DIAG_PRAGMA(x) RAPIDJSON_PRAGMA(warning(x))
|
||||
|
||||
#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable: x)
|
||||
#define RAPIDJSON_DIAG_OFF(x) RAPIDJSON_DIAG_PRAGMA(disable \
|
||||
: x)
|
||||
#define RAPIDJSON_DIAG_PUSH RAPIDJSON_DIAG_PRAGMA(push)
|
||||
#define RAPIDJSON_DIAG_POP RAPIDJSON_DIAG_PRAGMA(pop)
|
||||
|
||||
@ -586,7 +592,7 @@ RAPIDJSON_NAMESPACE_END
|
||||
#else
|
||||
#define RAPIDJSON_HAS_CXX11_RVALUE_REFS 0
|
||||
#endif
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,3,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 3, 0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
(defined(_MSC_VER) && _MSC_VER >= 1600) || \
|
||||
(defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
|
||||
@ -605,7 +611,7 @@ RAPIDJSON_NAMESPACE_END
|
||||
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
|
||||
#elif defined(__clang__)
|
||||
#define RAPIDJSON_HAS_CXX11_NOEXCEPT __has_feature(cxx_noexcept)
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
(defined(_MSC_VER) && _MSC_VER >= 1900) || \
|
||||
(defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
#define RAPIDJSON_HAS_CXX11_NOEXCEPT 1
|
||||
@ -633,7 +639,7 @@ RAPIDJSON_NAMESPACE_END
|
||||
#ifndef RAPIDJSON_HAS_CXX11_RANGE_FOR
|
||||
#if defined(__clang__)
|
||||
#define RAPIDJSON_HAS_CXX11_RANGE_FOR __has_feature(cxx_range_for)
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4,6,0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
#elif (defined(RAPIDJSON_GNUC) && (RAPIDJSON_GNUC >= RAPIDJSON_VERSION_CODE(4, 6, 0)) && defined(__GXX_EXPERIMENTAL_CXX0X__)) || \
|
||||
(defined(_MSC_VER) && _MSC_VER >= 1700) || \
|
||||
(defined(__SUNPRO_CC) && __SUNPRO_CC >= 0x5140 && defined(__GXX_EXPERIMENTAL_CXX0X__))
|
||||
#define RAPIDJSON_HAS_CXX11_RANGE_FOR 1
|
||||
@ -650,23 +656,23 @@ RAPIDJSON_NAMESPACE_END
|
||||
#endif
|
||||
|
||||
#if RAPIDJSON_HAS_CXX17
|
||||
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
|
||||
#define RAPIDJSON_DELIBERATE_FALLTHROUGH [[fallthrough]]
|
||||
#elif defined(__has_cpp_attribute)
|
||||
# if __has_cpp_attribute(clang::fallthrough)
|
||||
# define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
|
||||
# elif __has_cpp_attribute(fallthrough)
|
||||
# define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
|
||||
# else
|
||||
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
|
||||
# endif
|
||||
#if __has_cpp_attribute(clang::fallthrough)
|
||||
#define RAPIDJSON_DELIBERATE_FALLTHROUGH [[clang::fallthrough]]
|
||||
#elif __has_cpp_attribute(fallthrough)
|
||||
#define RAPIDJSON_DELIBERATE_FALLTHROUGH __attribute__((fallthrough))
|
||||
#else
|
||||
# define RAPIDJSON_DELIBERATE_FALLTHROUGH
|
||||
#define RAPIDJSON_DELIBERATE_FALLTHROUGH
|
||||
#endif
|
||||
#else
|
||||
#define RAPIDJSON_DELIBERATE_FALLTHROUGH
|
||||
#endif
|
||||
|
||||
//!@endcond
|
||||
|
||||
//! Assertion (in non-throwing contexts).
|
||||
/*! \ingroup RAPIDJSON_CONFIG
|
||||
/*! \ingroup RAPIDJSON_CONFIG
|
||||
Some functions provide a \c noexcept guarantee, if the compiler supports it.
|
||||
In these cases, the \ref RAPIDJSON_ASSERT macro cannot be overridden to
|
||||
throw an exception. This macro adds a separate customization point for
|
||||
|
@ -40,9 +40,9 @@
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(old-style-cast)
|
||||
RAPIDJSON_DIAG_OFF(old - style - cast)
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_OFF(switch-enum)
|
||||
RAPIDJSON_DIAG_OFF(switch - enum)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
@ -194,7 +194,7 @@ concept Handler {
|
||||
/*! This can be used as base class of any reader handler.
|
||||
\note implements Handler concept
|
||||
*/
|
||||
template<typename Encoding = UTF8<>, typename Derived = void>
|
||||
template <typename Encoding = UTF8<>, typename Derived = void>
|
||||
struct BaseReaderHandler {
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
@ -223,35 +223,35 @@ struct BaseReaderHandler {
|
||||
|
||||
namespace internal {
|
||||
|
||||
template<typename Stream, int = StreamTraits<Stream>::copyOptimization>
|
||||
class StreamLocalCopy;
|
||||
template <typename Stream, int = StreamTraits<Stream>::copyOptimization>
|
||||
class StreamLocalCopy;
|
||||
|
||||
//! Do copy optimization.
|
||||
template<typename Stream>
|
||||
class StreamLocalCopy<Stream, 1> {
|
||||
public:
|
||||
//! Do copy optimization.
|
||||
template <typename Stream>
|
||||
class StreamLocalCopy<Stream, 1> {
|
||||
public:
|
||||
StreamLocalCopy(Stream& original) : s(original), original_(original) {}
|
||||
~StreamLocalCopy() { original_ = s; }
|
||||
|
||||
Stream s;
|
||||
|
||||
private:
|
||||
private:
|
||||
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
|
||||
|
||||
Stream& original_;
|
||||
};
|
||||
};
|
||||
|
||||
//! Keep reference.
|
||||
template<typename Stream>
|
||||
class StreamLocalCopy<Stream, 0> {
|
||||
public:
|
||||
//! Keep reference.
|
||||
template <typename Stream>
|
||||
class StreamLocalCopy<Stream, 0> {
|
||||
public:
|
||||
StreamLocalCopy(Stream& original) : s(original) {}
|
||||
|
||||
Stream& s;
|
||||
|
||||
private:
|
||||
private:
|
||||
StreamLocalCopy& operator=(const StreamLocalCopy&) /* = delete */;
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -262,7 +262,7 @@ private:
|
||||
/*! \param is A input stream for skipping white spaces.
|
||||
\note This function has SSE2/SSE4.2 specialization.
|
||||
*/
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
void SkipWhitespace(InputStream& is) {
|
||||
internal::StreamLocalCopy<InputStream> copy(is);
|
||||
InputStream& s(copy.s);
|
||||
@ -280,7 +280,7 @@ inline const char* SkipWhitespace(const char* p, const char* end) {
|
||||
|
||||
#ifdef RAPIDJSON_SSE42
|
||||
//! Skip whitespace with SSE 4.2 pcmpistrm instruction, testing 16 8-byte characters at once.
|
||||
inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p) {
|
||||
// Fast return for single non-whitespace
|
||||
if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
|
||||
++p;
|
||||
@ -297,17 +297,17 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
|
||||
// The rest of string using SIMD
|
||||
static const char whitespace[16] = " \n\r\t";
|
||||
const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
|
||||
const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespace[0]));
|
||||
|
||||
for (;; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
|
||||
if (r != 16) // some of characters is non-whitespace
|
||||
return p + r;
|
||||
}
|
||||
}
|
||||
|
||||
inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
// Fast return for single non-whitespace
|
||||
if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
|
||||
++p;
|
||||
@ -316,10 +316,10 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
|
||||
// The middle of string using SIMD
|
||||
static const char whitespace[16] = " \n\r\t";
|
||||
const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespace[0]));
|
||||
const __m128i w = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespace[0]));
|
||||
|
||||
for (; p <= end - 16; p += 16) {
|
||||
const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const int r = _mm_cmpistri(w, s, _SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_LEAST_SIGNIFICANT | _SIDD_NEGATIVE_POLARITY);
|
||||
if (r != 16) // some of characters is non-whitespace
|
||||
return p + r;
|
||||
@ -331,7 +331,7 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
#elif defined(RAPIDJSON_SSE2)
|
||||
|
||||
//! Skip whitespace with SSE2 instructions, testing 16 8-byte characters at once.
|
||||
inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p) {
|
||||
// Fast return for single non-whitespace
|
||||
if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
|
||||
++p;
|
||||
@ -346,18 +346,19 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
else
|
||||
return p;
|
||||
|
||||
// The rest of string
|
||||
#define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
|
||||
// The rest of string
|
||||
#define C16(c) \
|
||||
{ c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
|
||||
static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') };
|
||||
#undef C16
|
||||
#undef C16
|
||||
|
||||
const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
|
||||
const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
|
||||
const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
|
||||
const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
|
||||
const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[0][0]));
|
||||
const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[1][0]));
|
||||
const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[2][0]));
|
||||
const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[3][0]));
|
||||
|
||||
for (;; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
__m128i x = _mm_cmpeq_epi8(s, w0);
|
||||
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
|
||||
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
|
||||
@ -375,25 +376,26 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
}
|
||||
}
|
||||
|
||||
inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
// Fast return for single non-whitespace
|
||||
if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
|
||||
++p;
|
||||
else
|
||||
return p;
|
||||
|
||||
// The rest of string
|
||||
#define C16(c) { c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
|
||||
// The rest of string
|
||||
#define C16(c) \
|
||||
{ c, c, c, c, c, c, c, c, c, c, c, c, c, c, c, c }
|
||||
static const char whitespaces[4][16] = { C16(' '), C16('\n'), C16('\r'), C16('\t') };
|
||||
#undef C16
|
||||
#undef C16
|
||||
|
||||
const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[0][0]));
|
||||
const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[1][0]));
|
||||
const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[2][0]));
|
||||
const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&whitespaces[3][0]));
|
||||
const __m128i w0 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[0][0]));
|
||||
const __m128i w1 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[1][0]));
|
||||
const __m128i w2 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[2][0]));
|
||||
const __m128i w3 = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&whitespaces[3][0]));
|
||||
|
||||
for (; p <= end - 16; p += 16) {
|
||||
const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_loadu_si128(reinterpret_cast<const __m128i*>(p));
|
||||
__m128i x = _mm_cmpeq_epi8(s, w0);
|
||||
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w1));
|
||||
x = _mm_or_si128(x, _mm_cmpeq_epi8(s, w2));
|
||||
@ -416,7 +418,7 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
#elif defined(RAPIDJSON_NEON)
|
||||
|
||||
//! Skip whitespace with ARM Neon instructions, testing 16 8-byte characters at once.
|
||||
inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p) {
|
||||
// Fast return for single non-whitespace
|
||||
if (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t')
|
||||
++p;
|
||||
@ -437,7 +439,7 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
const uint8x16_t w3 = vmovq_n_u8('\t');
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, w0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, w1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w2));
|
||||
@ -453,14 +455,15 @@ inline const char *SkipWhitespace_SIMD(const char* p) {
|
||||
uint32_t lz = internal::clzll(high);
|
||||
return p + 8 + (lz >> 3);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
return p + (lz >> 3);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
inline const char* SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
// Fast return for single non-whitespace
|
||||
if (p != end && (*p == ' ' || *p == '\n' || *p == '\r' || *p == '\t'))
|
||||
++p;
|
||||
@ -473,7 +476,7 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
const uint8x16_t w3 = vmovq_n_u8('\t');
|
||||
|
||||
for (; p <= end - 16; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, w0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, w1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, w2));
|
||||
@ -489,7 +492,8 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
uint32_t lz = internal::clzll(high);
|
||||
return p + 8 + (lz >> 3);
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
return p + (lz >> 3);
|
||||
}
|
||||
@ -502,16 +506,19 @@ inline const char *SkipWhitespace_SIMD(const char* p, const char* end) {
|
||||
|
||||
#ifdef RAPIDJSON_SIMD
|
||||
//! Template function specialization for InsituStringStream
|
||||
template<> inline void SkipWhitespace(InsituStringStream& is) {
|
||||
template <>
|
||||
inline void SkipWhitespace(InsituStringStream& is) {
|
||||
is.src_ = const_cast<char*>(SkipWhitespace_SIMD(is.src_));
|
||||
}
|
||||
|
||||
//! Template function specialization for StringStream
|
||||
template<> inline void SkipWhitespace(StringStream& is) {
|
||||
template <>
|
||||
inline void SkipWhitespace(StringStream& is) {
|
||||
is.src_ = SkipWhitespace_SIMD(is.src_);
|
||||
}
|
||||
|
||||
template<> inline void SkipWhitespace(EncodedInputStream<UTF8<>, MemoryStream>& is) {
|
||||
template <>
|
||||
inline void SkipWhitespace(EncodedInputStream<UTF8<>, MemoryStream>& is) {
|
||||
is.is_.src_ = SkipWhitespace_SIMD(is.is_.src_, is.is_.end_);
|
||||
}
|
||||
#endif // RAPIDJSON_SIMD
|
||||
@ -544,8 +551,7 @@ public:
|
||||
/*! \param stackAllocator Optional allocator for allocating stack memory. (Only use for non-destructive parsing)
|
||||
\param stackCapacity stack capacity in bytes for storing a single decoded string. (Only use for non-destructive parsing)
|
||||
*/
|
||||
GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) :
|
||||
stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {}
|
||||
GenericReader(StackAllocator* stackAllocator = 0, size_t stackCapacity = kDefaultStackCapacity) : stack_(stackAllocator, stackCapacity), parseResult_(), state_(IterativeParsingStartState) {}
|
||||
|
||||
//! Parse JSON text.
|
||||
/*! \tparam parseFlags Combination of \ref ParseFlag.
|
||||
@ -701,13 +707,14 @@ private:
|
||||
struct ClearStackOnExit {
|
||||
explicit ClearStackOnExit(GenericReader& r) : r_(r) {}
|
||||
~ClearStackOnExit() { r_.ClearStack(); }
|
||||
|
||||
private:
|
||||
GenericReader& r_;
|
||||
ClearStackOnExit(const ClearStackOnExit&);
|
||||
ClearStackOnExit& operator=(const ClearStackOnExit&);
|
||||
};
|
||||
|
||||
template<unsigned parseFlags, typename InputStream>
|
||||
template <unsigned parseFlags, typename InputStream>
|
||||
void SkipWhitespaceAndComments(InputStream& is) {
|
||||
SkipWhitespace(is);
|
||||
|
||||
@ -736,7 +743,7 @@ private:
|
||||
}
|
||||
|
||||
// Parse object: { string : value, ... }
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseObject(InputStream& is, Handler& handler) {
|
||||
RAPIDJSON_ASSERT(is.Peek() == '{');
|
||||
is.Take(); // Skip '{'
|
||||
@ -789,7 +796,8 @@ private:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorTermination, is.Tell());
|
||||
return;
|
||||
default:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); break; // This useless break is only for making warning and coverage happy
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell());
|
||||
break; // This useless break is only for making warning and coverage happy
|
||||
}
|
||||
|
||||
if (parseFlags & kParseTrailingCommasFlag) {
|
||||
@ -804,7 +812,7 @@ private:
|
||||
}
|
||||
|
||||
// Parse array: [ value, ... ]
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseArray(InputStream& is, Handler& handler) {
|
||||
RAPIDJSON_ASSERT(is.Peek() == '[');
|
||||
is.Take(); // Skip '['
|
||||
@ -852,7 +860,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseNull(InputStream& is, Handler& handler) {
|
||||
RAPIDJSON_ASSERT(is.Peek() == 'n');
|
||||
is.Take();
|
||||
@ -865,7 +873,7 @@ private:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
|
||||
}
|
||||
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseTrue(InputStream& is, Handler& handler) {
|
||||
RAPIDJSON_ASSERT(is.Peek() == 't');
|
||||
is.Take();
|
||||
@ -878,7 +886,7 @@ private:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
|
||||
}
|
||||
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseFalse(InputStream& is, Handler& handler) {
|
||||
RAPIDJSON_ASSERT(is.Peek() == 'f');
|
||||
is.Take();
|
||||
@ -891,7 +899,7 @@ private:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
|
||||
}
|
||||
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
RAPIDJSON_FORCEINLINE static bool Consume(InputStream& is, typename InputStream::Ch expect) {
|
||||
if (RAPIDJSON_LIKELY(is.Peek() == expect)) {
|
||||
is.Take();
|
||||
@ -902,7 +910,7 @@ private:
|
||||
}
|
||||
|
||||
// Helper function to parse four hexadecimal digits in \uXXXX in ParseString().
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
unsigned ParseHex4(InputStream& is, size_t escapeOffset) {
|
||||
unsigned codepoint = 0;
|
||||
for (int i = 0; i < 4; i++) {
|
||||
@ -955,7 +963,7 @@ private:
|
||||
};
|
||||
|
||||
// Parse string and generate String event. Different code paths for kParseInsituFlag.
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseString(InputStream& is, Handler& handler, bool isKey = false) {
|
||||
internal::StreamLocalCopy<InputStream> copy(is);
|
||||
InputStream& s(copy.s);
|
||||
@ -965,7 +973,7 @@ private:
|
||||
|
||||
bool success = false;
|
||||
if (parseFlags & kParseInsituFlag) {
|
||||
typename InputStream::Ch *head = s.PutBegin();
|
||||
typename InputStream::Ch* head = s.PutBegin();
|
||||
ParseStringToStream<parseFlags, SourceEncoding, SourceEncoding>(s, s);
|
||||
RAPIDJSON_PARSE_ERROR_EARLY_RETURN_VOID;
|
||||
size_t length = s.PutEnd(head) - 1;
|
||||
@ -987,19 +995,19 @@ private:
|
||||
|
||||
// Parse string to an output is
|
||||
// This function handles the prefix/suffix double quotes, escaping, and optional encoding validation.
|
||||
template<unsigned parseFlags, typename SEncoding, typename TEncoding, typename InputStream, typename OutputStream>
|
||||
template <unsigned parseFlags, typename SEncoding, typename TEncoding, typename InputStream, typename OutputStream>
|
||||
RAPIDJSON_FORCEINLINE void ParseStringToStream(InputStream& is, OutputStream& os) {
|
||||
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
|
||||
#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
#define Z16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
static const char escape[256] = {
|
||||
Z16, Z16, 0, 0,'\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/',
|
||||
Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0,
|
||||
0, 0,'\b', 0, 0, 0,'\f', 0, 0, 0, 0, 0, 0, 0,'\n', 0,
|
||||
0, 0,'\r', 0,'\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
Z16, Z16, 0, 0, '\"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '/',
|
||||
Z16, Z16, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\\', 0, 0, 0,
|
||||
0, 0, '\b', 0, 0, 0, '\f', 0, 0, 0, 0, 0, 0, 0, '\n', 0,
|
||||
0, 0, '\r', 0, '\t', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||
Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16
|
||||
};
|
||||
#undef Z16
|
||||
//!@endcond
|
||||
//!@endcond
|
||||
|
||||
for (;;) {
|
||||
// Scan and copy string before "\\\"" or < 0x20. This is an optional optimzation.
|
||||
@ -1036,8 +1044,7 @@ private:
|
||||
codepoint = (((codepoint - 0xD800) << 10) | (codepoint2 - 0xDC00)) + 0x10000;
|
||||
}
|
||||
// single low surrogate
|
||||
else
|
||||
{
|
||||
else {
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorStringUnicodeSurrogateInvalid, escapeOffset);
|
||||
}
|
||||
}
|
||||
@ -1059,15 +1066,13 @@ private:
|
||||
}
|
||||
else {
|
||||
size_t offset = is.Tell();
|
||||
if (RAPIDJSON_UNLIKELY((parseFlags & kParseValidateEncodingFlag ?
|
||||
!Transcoder<SEncoding, TEncoding>::Validate(is, os) :
|
||||
!Transcoder<SEncoding, TEncoding>::Transcode(is, os))))
|
||||
if (RAPIDJSON_UNLIKELY((parseFlags & kParseValidateEncodingFlag ? !Transcoder<SEncoding, TEncoding>::Validate(is, os) : !Transcoder<SEncoding, TEncoding>::Transcode(is, os))))
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorStringInvalidEncoding, offset);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
template<typename InputStream, typename OutputStream>
|
||||
template <typename InputStream, typename OutputStream>
|
||||
static RAPIDJSON_FORCEINLINE void ScanCopyUnescapedString(InputStream&, OutputStream&) {
|
||||
// Do nothing for generic version
|
||||
}
|
||||
@ -1091,12 +1096,12 @@ private:
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
|
||||
|
||||
for (;; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
@ -1104,13 +1109,13 @@ private:
|
||||
unsigned short r = static_cast<unsigned short>(_mm_movemask_epi8(x));
|
||||
if (RAPIDJSON_UNLIKELY(r != 0)) { // some of characters is escaped
|
||||
SizeType length;
|
||||
#ifdef _MSC_VER // Find the index of first escaped
|
||||
#ifdef _MSC_VER // Find the index of first escaped
|
||||
unsigned long offset;
|
||||
_BitScanForward(&offset, r);
|
||||
length = offset;
|
||||
#else
|
||||
#else
|
||||
length = static_cast<SizeType>(__builtin_ffs(r) - 1);
|
||||
#endif
|
||||
#endif
|
||||
if (length != 0) {
|
||||
char* q = reinterpret_cast<char*>(os.Push(length));
|
||||
for (size_t i = 0; i < length; i++)
|
||||
@ -1120,7 +1125,7 @@ private:
|
||||
}
|
||||
break;
|
||||
}
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i *>(os.Push(16)), s);
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i*>(os.Push(16)), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
@ -1137,7 +1142,7 @@ private:
|
||||
}
|
||||
|
||||
char* p = is.src_;
|
||||
char *q = is.dst_;
|
||||
char* q = is.dst_;
|
||||
|
||||
// Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
@ -1154,12 +1159,12 @@ private:
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
|
||||
|
||||
for (;; p += 16, q += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
@ -1174,11 +1179,11 @@ private:
|
||||
#else
|
||||
length = static_cast<size_t>(__builtin_ffs(r) - 1);
|
||||
#endif
|
||||
for (const char* pend = p + length; p != pend; )
|
||||
for (const char* pend = p + length; p != pend;)
|
||||
*q++ = *p++;
|
||||
break;
|
||||
}
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i *>(q), s);
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i*>(q), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
@ -1202,12 +1207,12 @@ private:
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
|
||||
|
||||
for (;; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
@ -1251,7 +1256,7 @@ private:
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
@ -1269,7 +1274,8 @@ private:
|
||||
length = 8 + (lz >> 3);
|
||||
escaped = true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
length = lz >> 3;
|
||||
escaped = true;
|
||||
@ -1284,7 +1290,7 @@ private:
|
||||
}
|
||||
break;
|
||||
}
|
||||
vst1q_u8(reinterpret_cast<uint8_t *>(os.Push(16)), s);
|
||||
vst1q_u8(reinterpret_cast<uint8_t*>(os.Push(16)), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
@ -1301,7 +1307,7 @@ private:
|
||||
}
|
||||
|
||||
char* p = is.src_;
|
||||
char *q = is.dst_;
|
||||
char* q = is.dst_;
|
||||
|
||||
// Scan one by one until alignment (unaligned load may cross page boundary and cause crash)
|
||||
const char* nextAligned = reinterpret_cast<const char*>((reinterpret_cast<size_t>(p) + 15) & static_cast<size_t>(~15));
|
||||
@ -1321,7 +1327,7 @@ private:
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16, q += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
@ -1339,18 +1345,19 @@ private:
|
||||
length = 8 + (lz >> 3);
|
||||
escaped = true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
length = lz >> 3;
|
||||
escaped = true;
|
||||
}
|
||||
if (RAPIDJSON_UNLIKELY(escaped)) { // some of characters is escaped
|
||||
for (const char* pend = p + length; p != pend; ) {
|
||||
for (const char* pend = p + length; p != pend;) {
|
||||
*q++ = *p++;
|
||||
}
|
||||
break;
|
||||
}
|
||||
vst1q_u8(reinterpret_cast<uint8_t *>(q), s);
|
||||
vst1q_u8(reinterpret_cast<uint8_t*>(q), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
@ -1377,7 +1384,7 @@ private:
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (;; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
@ -1393,7 +1400,8 @@ private:
|
||||
p += 8 + (lz >> 3);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
p += lz >> 3;
|
||||
break;
|
||||
@ -1404,10 +1412,10 @@ private:
|
||||
}
|
||||
#endif // RAPIDJSON_NEON
|
||||
|
||||
template<typename InputStream, bool backup, bool pushOnTake>
|
||||
template <typename InputStream, bool backup, bool pushOnTake>
|
||||
class NumberStream;
|
||||
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
class NumberStream<InputStream, false, false> {
|
||||
public:
|
||||
typedef typename InputStream::Ch Ch;
|
||||
@ -1429,9 +1437,10 @@ private:
|
||||
InputStream& is;
|
||||
};
|
||||
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
class NumberStream<InputStream, true, false> : public NumberStream<InputStream, false, false> {
|
||||
typedef NumberStream<InputStream, false, false> Base;
|
||||
|
||||
public:
|
||||
NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is), stackStream(reader.stack_) {}
|
||||
|
||||
@ -1455,24 +1464,24 @@ private:
|
||||
StackStream<char> stackStream;
|
||||
};
|
||||
|
||||
template<typename InputStream>
|
||||
template <typename InputStream>
|
||||
class NumberStream<InputStream, true, true> : public NumberStream<InputStream, true, false> {
|
||||
typedef NumberStream<InputStream, true, false> Base;
|
||||
|
||||
public:
|
||||
NumberStream(GenericReader& reader, InputStream& is) : Base(reader, is) {}
|
||||
|
||||
RAPIDJSON_FORCEINLINE Ch Take() { return Base::TakePush(); }
|
||||
};
|
||||
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseNumber(InputStream& is, Handler& handler) {
|
||||
internal::StreamLocalCopy<InputStream> copy(is);
|
||||
NumberStream<InputStream,
|
||||
((parseFlags & kParseNumbersAsStringsFlag) != 0) ?
|
||||
((parseFlags & kParseInsituFlag) == 0) :
|
||||
((parseFlags & kParseFullPrecisionFlag) != 0),
|
||||
((parseFlags & kParseNumbersAsStringsFlag) != 0) ? ((parseFlags & kParseInsituFlag) == 0) : ((parseFlags & kParseFullPrecisionFlag) != 0),
|
||||
(parseFlags & kParseNumbersAsStringsFlag) != 0 &&
|
||||
(parseFlags & kParseInsituFlag) == 0> s(*this, copy.s);
|
||||
(parseFlags & kParseInsituFlag) == 0>
|
||||
s(*this, copy.s);
|
||||
|
||||
size_t startOffset = s.Tell();
|
||||
double d = 0.0;
|
||||
@ -1531,8 +1540,7 @@ private:
|
||||
d = (minus ? -std::numeric_limits<double>::infinity() : std::numeric_limits<double>::infinity());
|
||||
useNanOrInf = true;
|
||||
|
||||
if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n')
|
||||
&& Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y')))) {
|
||||
if (RAPIDJSON_UNLIKELY(s.Peek() == 'i' && !(Consume(s, 'i') && Consume(s, 'n') && Consume(s, 'i') && Consume(s, 't') && Consume(s, 'y')))) {
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, s.Tell());
|
||||
}
|
||||
}
|
||||
@ -1746,19 +1754,30 @@ private:
|
||||
}
|
||||
|
||||
// Parse any JSON value
|
||||
template<unsigned parseFlags, typename InputStream, typename Handler>
|
||||
template <unsigned parseFlags, typename InputStream, typename Handler>
|
||||
void ParseValue(InputStream& is, Handler& handler) {
|
||||
switch (is.Peek()) {
|
||||
case 'n': ParseNull <parseFlags>(is, handler); break;
|
||||
case 't': ParseTrue <parseFlags>(is, handler); break;
|
||||
case 'f': ParseFalse <parseFlags>(is, handler); break;
|
||||
case '"': ParseString<parseFlags>(is, handler); break;
|
||||
case '{': ParseObject<parseFlags>(is, handler); break;
|
||||
case '[': ParseArray <parseFlags>(is, handler); break;
|
||||
default :
|
||||
case 'n':
|
||||
ParseNull<parseFlags>(is, handler);
|
||||
break;
|
||||
case 't':
|
||||
ParseTrue<parseFlags>(is, handler);
|
||||
break;
|
||||
case 'f':
|
||||
ParseFalse<parseFlags>(is, handler);
|
||||
break;
|
||||
case '"':
|
||||
ParseString<parseFlags>(is, handler);
|
||||
break;
|
||||
case '{':
|
||||
ParseObject<parseFlags>(is, handler);
|
||||
break;
|
||||
case '[':
|
||||
ParseArray<parseFlags>(is, handler);
|
||||
break;
|
||||
default:
|
||||
ParseNumber<parseFlags>(is, handler);
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@ -1816,7 +1835,7 @@ private:
|
||||
|
||||
//!@cond RAPIDJSON_HIDDEN_FROM_DOXYGEN
|
||||
#define N NumberToken
|
||||
#define N16 N,N,N,N,N,N,N,N,N,N,N,N,N,N,N,N
|
||||
#define N16 N, N, N, N, N, N, N, N, N, N, N, N, N, N, N, N
|
||||
// Maps from ASCII to Token
|
||||
static const unsigned char tokenMap[256] = {
|
||||
N16, // 00~0F
|
||||
@ -1831,7 +1850,7 @@ private:
|
||||
};
|
||||
#undef N
|
||||
#undef N16
|
||||
//!@endcond
|
||||
//!@endcond
|
||||
|
||||
if (sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256)
|
||||
return static_cast<Token>(tokenMap[static_cast<unsigned char>(c)]);
|
||||
@ -1846,14 +1865,12 @@ private:
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
IterativeParsingErrorState },
|
||||
// Error(sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
IterativeParsingErrorState },
|
||||
// Start
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket
|
||||
@ -1914,8 +1931,7 @@ private:
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
IterativeParsingErrorState },
|
||||
// ArrayInitial
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket(push Element state)
|
||||
@ -1948,14 +1964,12 @@ private:
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
IterativeParsingErrorState },
|
||||
// Single Value (sink state)
|
||||
{
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
|
||||
IterativeParsingErrorState
|
||||
},
|
||||
IterativeParsingErrorState },
|
||||
// ElementDelimiter
|
||||
{
|
||||
IterativeParsingArrayInitialState, // Left bracket(push Element state)
|
||||
@ -2014,8 +2028,7 @@ private:
|
||||
return dst;
|
||||
|
||||
case IterativeParsingObjectInitialState:
|
||||
case IterativeParsingArrayInitialState:
|
||||
{
|
||||
case IterativeParsingArrayInitialState: {
|
||||
// Push the state(Element or MemeberValue) if we are nested in another array or value of member.
|
||||
// In this way we can get the correct state on ObjectFinish or ArrayFinish by frame pop.
|
||||
IterativeParsingState n = src;
|
||||
@ -2075,8 +2088,7 @@ private:
|
||||
*stack_.template Top<SizeType>() = *stack_.template Top<SizeType>() + 1;
|
||||
return dst;
|
||||
|
||||
case IterativeParsingObjectFinishState:
|
||||
{
|
||||
case IterativeParsingObjectFinishState: {
|
||||
// Transit from delimiter is only allowed when trailing commas are enabled
|
||||
if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingMemberDelimiterState) {
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorObjectMissName, is.Tell());
|
||||
@ -2105,8 +2117,7 @@ private:
|
||||
}
|
||||
}
|
||||
|
||||
case IterativeParsingArrayFinishState:
|
||||
{
|
||||
case IterativeParsingArrayFinishState: {
|
||||
// Transit from delimiter is only allowed when trailing commas are enabled
|
||||
if (!(parseFlags & kParseTrailingCommasFlag) && src == IterativeParsingElementDelimiterState) {
|
||||
RAPIDJSON_PARSE_ERROR_NORETURN(kParseErrorValueInvalid, is.Tell());
|
||||
@ -2165,16 +2176,31 @@ private:
|
||||
}
|
||||
|
||||
switch (src) {
|
||||
case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell()); return;
|
||||
case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell()); return;
|
||||
case IterativeParsingStartState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell());
|
||||
return;
|
||||
case IterativeParsingFinishState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell());
|
||||
return;
|
||||
case IterativeParsingObjectInitialState:
|
||||
case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell()); return;
|
||||
case IterativeParsingMemberKeyState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell()); return;
|
||||
case IterativeParsingMemberValueState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell()); return;
|
||||
case IterativeParsingMemberDelimiterState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell());
|
||||
return;
|
||||
case IterativeParsingMemberKeyState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissColon, is.Tell());
|
||||
return;
|
||||
case IterativeParsingMemberValueState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissCommaOrCurlyBracket, is.Tell());
|
||||
return;
|
||||
case IterativeParsingKeyValueDelimiterState:
|
||||
case IterativeParsingArrayInitialState:
|
||||
case IterativeParsingElementDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell()); return;
|
||||
default: RAPIDJSON_ASSERT(src == IterativeParsingElementState); RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell()); return;
|
||||
case IterativeParsingElementDelimiterState:
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorValueInvalid, is.Tell());
|
||||
return;
|
||||
default:
|
||||
RAPIDJSON_ASSERT(src == IterativeParsingElementState);
|
||||
RAPIDJSON_PARSE_ERROR(kParseErrorArrayMissCommaOrSquareBracket, is.Tell());
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@ -2228,7 +2254,7 @@ private:
|
||||
}; // class GenericReader
|
||||
|
||||
//! Reader with UTF8 encoding and default allocator.
|
||||
typedef GenericReader<UTF8<>, UTF8<> > Reader;
|
||||
typedef GenericReader<UTF8<>, UTF8<>> Reader;
|
||||
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#define RAPIDJSON_SCHEMA_USE_INTERNALREGEX 0
|
||||
#endif
|
||||
|
||||
#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >=201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
|
||||
#if !RAPIDJSON_SCHEMA_USE_INTERNALREGEX && defined(RAPIDJSON_SCHEMA_USE_STDREGEX) && (__cplusplus >= 201103L || (defined(_MSC_VER) && _MSC_VER >= 1800))
|
||||
#define RAPIDJSON_SCHEMA_USE_STDREGEX 1
|
||||
#else
|
||||
#define RAPIDJSON_SCHEMA_USE_STDREGEX 0
|
||||
@ -60,10 +60,10 @@ RAPIDJSON_DIAG_OFF(effc++)
|
||||
#endif
|
||||
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_OFF(weak-vtables)
|
||||
RAPIDJSON_DIAG_OFF(exit-time-destructors)
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat-pedantic)
|
||||
RAPIDJSON_DIAG_OFF(variadic-macros)
|
||||
RAPIDJSON_DIAG_OFF(weak - vtables)
|
||||
RAPIDJSON_DIAG_OFF(exit - time - destructors)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat - pedantic)
|
||||
RAPIDJSON_DIAG_OFF(variadic - macros)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
|
||||
#endif
|
||||
@ -77,29 +77,29 @@ RAPIDJSON_NAMESPACE_BEGIN
|
||||
|
||||
namespace internal {
|
||||
|
||||
inline void PrintInvalidKeyword(const char* keyword) {
|
||||
inline void PrintInvalidKeyword(const char* keyword) {
|
||||
printf("Fail keyword: %s\n", keyword);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintInvalidKeyword(const wchar_t* keyword) {
|
||||
inline void PrintInvalidKeyword(const wchar_t* keyword) {
|
||||
wprintf(L"Fail keyword: %ls\n", keyword);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintInvalidDocument(const char* document) {
|
||||
inline void PrintInvalidDocument(const char* document) {
|
||||
printf("Fail document: %s\n\n", document);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintInvalidDocument(const wchar_t* document) {
|
||||
inline void PrintInvalidDocument(const wchar_t* document) {
|
||||
wprintf(L"Fail document: %ls\n\n", document);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintValidatorPointers(unsigned depth, const char* s, const char* d) {
|
||||
inline void PrintValidatorPointers(unsigned depth, const char* s, const char* d) {
|
||||
printf("S: %*s%s\nD: %*s%s\n\n", depth * 4, " ", s, depth * 4, " ", d);
|
||||
}
|
||||
}
|
||||
|
||||
inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar_t* d) {
|
||||
inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar_t* d) {
|
||||
wprintf(L"S: %*ls%ls\nD: %*ls%ls\n\n", depth * 4, L" ", s, depth * 4, L" ", d);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -114,13 +114,13 @@ inline void PrintValidatorPointers(unsigned depth, const wchar_t* s, const wchar
|
||||
#define RAPIDJSON_INVALID_KEYWORD_VERBOSE(keyword)
|
||||
#endif
|
||||
|
||||
#define RAPIDJSON_INVALID_KEYWORD_RETURN(code)\
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN\
|
||||
context.invalidCode = code;\
|
||||
context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString();\
|
||||
RAPIDJSON_INVALID_KEYWORD_VERBOSE(context.invalidKeyword);\
|
||||
return false;\
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
#define RAPIDJSON_INVALID_KEYWORD_RETURN(code) \
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
||||
context.invalidCode = code; \
|
||||
context.invalidKeyword = SchemaType::GetValidateErrorKeyword(code).GetString(); \
|
||||
RAPIDJSON_INVALID_KEYWORD_VERBOSE(context.invalidKeyword); \
|
||||
return false; \
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ValidateFlag
|
||||
@ -152,26 +152,26 @@ class GenericSchemaDocument;
|
||||
|
||||
namespace internal {
|
||||
|
||||
template <typename SchemaDocumentType>
|
||||
class Schema;
|
||||
template <typename SchemaDocumentType>
|
||||
class Schema;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ISchemaValidator
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ISchemaValidator
|
||||
|
||||
class ISchemaValidator {
|
||||
public:
|
||||
class ISchemaValidator {
|
||||
public:
|
||||
virtual ~ISchemaValidator() {}
|
||||
virtual bool IsValid() const = 0;
|
||||
virtual void SetValidateFlags(unsigned flags) = 0;
|
||||
virtual unsigned GetValidateFlags() const = 0;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ISchemaStateFactory
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// ISchemaStateFactory
|
||||
|
||||
template <typename SchemaType>
|
||||
class ISchemaStateFactory {
|
||||
public:
|
||||
template <typename SchemaType>
|
||||
class ISchemaStateFactory {
|
||||
public:
|
||||
virtual ~ISchemaStateFactory() {}
|
||||
virtual ISchemaValidator* CreateSchemaValidator(const SchemaType&, const bool inheritContinueOnErrors) = 0;
|
||||
virtual void DestroySchemaValidator(ISchemaValidator* validator) = 0;
|
||||
@ -180,14 +180,14 @@ public:
|
||||
virtual void DestroryHasher(void* hasher) = 0;
|
||||
virtual void* MallocState(size_t size) = 0;
|
||||
virtual void FreeState(void* p) = 0;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IValidationErrorHandler
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// IValidationErrorHandler
|
||||
|
||||
template <typename SchemaType>
|
||||
class IValidationErrorHandler {
|
||||
public:
|
||||
template <typename SchemaType>
|
||||
class IValidationErrorHandler {
|
||||
public:
|
||||
typedef typename SchemaType::Ch Ch;
|
||||
typedef typename SchemaType::SValue SValue;
|
||||
|
||||
@ -235,30 +235,52 @@ public:
|
||||
virtual void NoneOf(ISchemaValidator** subvalidators, SizeType count) = 0;
|
||||
virtual void NotOneOf(ISchemaValidator** subvalidators, SizeType count, bool matched) = 0;
|
||||
virtual void Disallowed() = 0;
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Hasher
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Hasher
|
||||
|
||||
// For comparison of compound value
|
||||
template<typename Encoding, typename Allocator>
|
||||
class Hasher {
|
||||
public:
|
||||
// For comparison of compound value
|
||||
template <typename Encoding, typename Allocator>
|
||||
class Hasher {
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
Hasher(Allocator* allocator = 0, size_t stackCapacity = kDefaultSize) : stack_(allocator, stackCapacity) {}
|
||||
|
||||
bool Null() { return WriteType(kNullType); }
|
||||
bool Bool(bool b) { return WriteType(b ? kTrueType : kFalseType); }
|
||||
bool Int(int i) { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
|
||||
bool Uint(unsigned u) { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
|
||||
bool Int64(int64_t i) { Number n; n.u.i = i; n.d = static_cast<double>(i); return WriteNumber(n); }
|
||||
bool Uint64(uint64_t u) { Number n; n.u.u = u; n.d = static_cast<double>(u); return WriteNumber(n); }
|
||||
bool Int(int i) {
|
||||
Number n;
|
||||
n.u.i = i;
|
||||
n.d = static_cast<double>(i);
|
||||
return WriteNumber(n);
|
||||
}
|
||||
bool Uint(unsigned u) {
|
||||
Number n;
|
||||
n.u.u = u;
|
||||
n.d = static_cast<double>(u);
|
||||
return WriteNumber(n);
|
||||
}
|
||||
bool Int64(int64_t i) {
|
||||
Number n;
|
||||
n.u.i = i;
|
||||
n.d = static_cast<double>(i);
|
||||
return WriteNumber(n);
|
||||
}
|
||||
bool Uint64(uint64_t u) {
|
||||
Number n;
|
||||
n.u.u = u;
|
||||
n.d = static_cast<double>(u);
|
||||
return WriteNumber(n);
|
||||
}
|
||||
bool Double(double d) {
|
||||
Number n;
|
||||
if (d < 0) n.u.i = static_cast<int64_t>(d);
|
||||
else n.u.u = static_cast<uint64_t>(d);
|
||||
if (d < 0)
|
||||
n.u.i = static_cast<int64_t>(d);
|
||||
else
|
||||
n.u.u = static_cast<uint64_t>(d);
|
||||
n.d = d;
|
||||
return WriteNumber(n);
|
||||
}
|
||||
@ -301,13 +323,13 @@ public:
|
||||
return *stack_.template Top<uint64_t>();
|
||||
}
|
||||
|
||||
private:
|
||||
private:
|
||||
static const size_t kDefaultSize = 256;
|
||||
struct Number {
|
||||
union U {
|
||||
uint64_t u;
|
||||
int64_t i;
|
||||
}u;
|
||||
} u;
|
||||
double d;
|
||||
};
|
||||
|
||||
@ -333,13 +355,13 @@ private:
|
||||
}
|
||||
|
||||
Stack<Allocator> stack_;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SchemaValidationContext
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// SchemaValidationContext
|
||||
|
||||
template <typename SchemaDocumentType>
|
||||
struct SchemaValidationContext {
|
||||
template <typename SchemaDocumentType>
|
||||
struct SchemaValidationContext {
|
||||
typedef Schema<SchemaDocumentType> SchemaType;
|
||||
typedef ISchemaStateFactory<SchemaType> SchemaValidatorFactoryType;
|
||||
typedef IValidationErrorHandler<SchemaType> ErrorHandlerType;
|
||||
@ -352,8 +374,7 @@ struct SchemaValidationContext {
|
||||
kPatternValidatorWithAdditionalProperty
|
||||
};
|
||||
|
||||
SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s) :
|
||||
factory(f),
|
||||
SchemaValidationContext(SchemaValidatorFactoryType& f, ErrorHandlerType& eh, const SchemaType* s) : factory(f),
|
||||
error_handler(eh),
|
||||
schema(s),
|
||||
valueSchema(),
|
||||
@ -371,8 +392,7 @@ struct SchemaValidationContext {
|
||||
propertyExist(),
|
||||
inArray(false),
|
||||
valueUniqueness(false),
|
||||
arrayUniqueness(false)
|
||||
{
|
||||
arrayUniqueness(false) {
|
||||
}
|
||||
|
||||
~SchemaValidationContext() {
|
||||
@ -415,14 +435,14 @@ struct SchemaValidationContext {
|
||||
bool inArray;
|
||||
bool valueUniqueness;
|
||||
bool arrayUniqueness;
|
||||
};
|
||||
};
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Schema
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// Schema
|
||||
|
||||
template <typename SchemaDocumentType>
|
||||
class Schema {
|
||||
public:
|
||||
template <typename SchemaDocumentType>
|
||||
class Schema {
|
||||
public:
|
||||
typedef typename SchemaDocumentType::ValueType ValueType;
|
||||
typedef typename SchemaDocumentType::AllocatorType AllocatorType;
|
||||
typedef typename SchemaDocumentType::PointerType PointerType;
|
||||
@ -434,8 +454,7 @@ public:
|
||||
typedef IValidationErrorHandler<Schema> ErrorHandler;
|
||||
friend class GenericSchemaDocument<ValueType, AllocatorType>;
|
||||
|
||||
Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) :
|
||||
allocator_(allocator),
|
||||
Schema(SchemaDocumentType* schemaDocument, const PointerType& p, const ValueType& value, const ValueType& document, AllocatorType* allocator) : allocator_(allocator),
|
||||
uri_(schemaDocument->GetURI(), *allocator),
|
||||
pointer_(p, allocator),
|
||||
typeless_(schemaDocument->GetTypeless()),
|
||||
@ -469,8 +488,7 @@ public:
|
||||
maxLength_(~SizeType(0)),
|
||||
exclusiveMinimum_(false),
|
||||
exclusiveMaximum_(false),
|
||||
defaultValueLength_(0)
|
||||
{
|
||||
defaultValueLength_(0) {
|
||||
typedef typename ValueType::ConstValueIterator ConstValueIterator;
|
||||
typedef typename ValueType::ConstMemberIterator ConstMemberIterator;
|
||||
|
||||
@ -490,7 +508,7 @@ public:
|
||||
if (v->IsArray() && v->Size() > 0) {
|
||||
enum_ = static_cast<uint64_t*>(allocator_->Malloc(sizeof(uint64_t) * v->Size()));
|
||||
for (ConstValueIterator itr = v->Begin(); itr != v->End(); ++itr) {
|
||||
typedef Hasher<EncodingType, MemoryPoolAllocator<> > EnumHasherType;
|
||||
typedef Hasher<EncodingType, MemoryPoolAllocator<>> EnumHasherType;
|
||||
char buffer[256u + 24];
|
||||
MemoryPoolAllocator<> hasherAllocator(buffer, sizeof(buffer));
|
||||
EnumHasherType h(&hasherAllocator, 256);
|
||||
@ -590,7 +608,7 @@ public:
|
||||
if (FindPropertyIndex(itr->name, &sourceIndex)) {
|
||||
if (itr->value.IsArray()) {
|
||||
properties_[sourceIndex].dependencies = static_cast<bool*>(allocator_->Malloc(sizeof(bool) * propertyCount_));
|
||||
std::memset(properties_[sourceIndex].dependencies, 0, sizeof(bool)* propertyCount_);
|
||||
std::memset(properties_[sourceIndex].dependencies, 0, sizeof(bool) * propertyCount_);
|
||||
for (ConstValueIterator targetItr = itr->value.Begin(); targetItr != itr->value.End(); ++targetItr) {
|
||||
SizeType targetIndex;
|
||||
if (FindPropertyIndex(*targetItr, &targetIndex))
|
||||
@ -669,7 +687,6 @@ public:
|
||||
if (const ValueType* v = GetMember(value, GetDefaultValueString()))
|
||||
if (v->IsString())
|
||||
defaultValueLength_ = v->GetStringLength();
|
||||
|
||||
}
|
||||
|
||||
~Schema() {
|
||||
@ -801,7 +818,8 @@ public:
|
||||
if (oneValid) {
|
||||
context.error_handler.NotOneOf(&context.validators[oneOf_.begin], oneOf_.count, true);
|
||||
RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorOneOfMatch);
|
||||
} else
|
||||
}
|
||||
else
|
||||
oneValid = true;
|
||||
}
|
||||
if (!oneValid) {
|
||||
@ -982,7 +1000,7 @@ public:
|
||||
context.error_handler.StartMissingProperties();
|
||||
for (SizeType index = 0; index < propertyCount_; index++)
|
||||
if (properties_[index].required && !context.propertyExist[index])
|
||||
if (properties_[index].schema->defaultValueLength_ == 0 )
|
||||
if (properties_[index].schema->defaultValueLength_ == 0)
|
||||
context.error_handler.AddMissingProperty(properties_[index].name);
|
||||
if (context.error_handler.EndMissingProperties())
|
||||
RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorRequired);
|
||||
@ -1054,48 +1072,74 @@ public:
|
||||
|
||||
static const ValueType& GetValidateErrorKeyword(ValidateErrorCode validateErrorCode) {
|
||||
switch (validateErrorCode) {
|
||||
case kValidateErrorMultipleOf: return GetMultipleOfString();
|
||||
case kValidateErrorMaximum: return GetMaximumString();
|
||||
case kValidateErrorExclusiveMaximum: return GetMaximumString(); // Same
|
||||
case kValidateErrorMinimum: return GetMinimumString();
|
||||
case kValidateErrorExclusiveMinimum: return GetMinimumString(); // Same
|
||||
case kValidateErrorMultipleOf:
|
||||
return GetMultipleOfString();
|
||||
case kValidateErrorMaximum:
|
||||
return GetMaximumString();
|
||||
case kValidateErrorExclusiveMaximum:
|
||||
return GetMaximumString(); // Same
|
||||
case kValidateErrorMinimum:
|
||||
return GetMinimumString();
|
||||
case kValidateErrorExclusiveMinimum:
|
||||
return GetMinimumString(); // Same
|
||||
|
||||
case kValidateErrorMaxLength: return GetMaxLengthString();
|
||||
case kValidateErrorMinLength: return GetMinLengthString();
|
||||
case kValidateErrorPattern: return GetPatternString();
|
||||
case kValidateErrorMaxLength:
|
||||
return GetMaxLengthString();
|
||||
case kValidateErrorMinLength:
|
||||
return GetMinLengthString();
|
||||
case kValidateErrorPattern:
|
||||
return GetPatternString();
|
||||
|
||||
case kValidateErrorMaxItems: return GetMaxItemsString();
|
||||
case kValidateErrorMinItems: return GetMinItemsString();
|
||||
case kValidateErrorUniqueItems: return GetUniqueItemsString();
|
||||
case kValidateErrorAdditionalItems: return GetAdditionalItemsString();
|
||||
case kValidateErrorMaxItems:
|
||||
return GetMaxItemsString();
|
||||
case kValidateErrorMinItems:
|
||||
return GetMinItemsString();
|
||||
case kValidateErrorUniqueItems:
|
||||
return GetUniqueItemsString();
|
||||
case kValidateErrorAdditionalItems:
|
||||
return GetAdditionalItemsString();
|
||||
|
||||
case kValidateErrorMaxProperties: return GetMaxPropertiesString();
|
||||
case kValidateErrorMinProperties: return GetMinPropertiesString();
|
||||
case kValidateErrorRequired: return GetRequiredString();
|
||||
case kValidateErrorAdditionalProperties: return GetAdditionalPropertiesString();
|
||||
case kValidateErrorPatternProperties: return GetPatternPropertiesString();
|
||||
case kValidateErrorDependencies: return GetDependenciesString();
|
||||
case kValidateErrorMaxProperties:
|
||||
return GetMaxPropertiesString();
|
||||
case kValidateErrorMinProperties:
|
||||
return GetMinPropertiesString();
|
||||
case kValidateErrorRequired:
|
||||
return GetRequiredString();
|
||||
case kValidateErrorAdditionalProperties:
|
||||
return GetAdditionalPropertiesString();
|
||||
case kValidateErrorPatternProperties:
|
||||
return GetPatternPropertiesString();
|
||||
case kValidateErrorDependencies:
|
||||
return GetDependenciesString();
|
||||
|
||||
case kValidateErrorEnum: return GetEnumString();
|
||||
case kValidateErrorType: return GetTypeString();
|
||||
case kValidateErrorEnum:
|
||||
return GetEnumString();
|
||||
case kValidateErrorType:
|
||||
return GetTypeString();
|
||||
|
||||
case kValidateErrorOneOf: return GetOneOfString();
|
||||
case kValidateErrorOneOfMatch: return GetOneOfString(); // Same
|
||||
case kValidateErrorAllOf: return GetAllOfString();
|
||||
case kValidateErrorAnyOf: return GetAnyOfString();
|
||||
case kValidateErrorNot: return GetNotString();
|
||||
case kValidateErrorOneOf:
|
||||
return GetOneOfString();
|
||||
case kValidateErrorOneOfMatch:
|
||||
return GetOneOfString(); // Same
|
||||
case kValidateErrorAllOf:
|
||||
return GetAllOfString();
|
||||
case kValidateErrorAnyOf:
|
||||
return GetAnyOfString();
|
||||
case kValidateErrorNot:
|
||||
return GetNotString();
|
||||
|
||||
default: return GetNullString();
|
||||
default:
|
||||
return GetNullString();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Generate functions for string literal according to Ch
|
||||
#define RAPIDJSON_STRING_(name, ...) \
|
||||
static const ValueType& Get##name##String() {\
|
||||
static const Ch s[] = { __VA_ARGS__, '\0' };\
|
||||
static const ValueType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1));\
|
||||
return v;\
|
||||
static const ValueType& Get##name##String() { \
|
||||
static const Ch s[] = { __VA_ARGS__, '\0' }; \
|
||||
static const ValueType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1)); \
|
||||
return v; \
|
||||
}
|
||||
|
||||
RAPIDJSON_STRING_(Null, 'n', 'u', 'l', 'l')
|
||||
@ -1135,7 +1179,7 @@ public:
|
||||
|
||||
#undef RAPIDJSON_STRING_
|
||||
|
||||
private:
|
||||
private:
|
||||
enum SchemaValueType {
|
||||
kNullSchemaType,
|
||||
kBooleanSchemaType,
|
||||
@ -1195,7 +1239,7 @@ private:
|
||||
PointerType q = p.Append(name, allocator_);
|
||||
out.count = v->Size();
|
||||
out.schemas = static_cast<const Schema**>(allocator_->Malloc(out.count * sizeof(const Schema*)));
|
||||
memset(out.schemas, 0, sizeof(Schema*)* out.count);
|
||||
memset(out.schemas, 0, sizeof(Schema*) * out.count);
|
||||
for (SizeType i = 0; i < out.count; i++)
|
||||
schemaDocument.CreateSchema(&out.schemas[i], q.Append(i, allocator_), (*v)[i], document);
|
||||
out.begin = validatorCount_;
|
||||
@ -1219,7 +1263,7 @@ private:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType) {
|
||||
static bool IsPatternMatch(const RegexType* pattern, const Ch* str, SizeType) {
|
||||
GenericRegexSearch<RegexType> rs(*pattern);
|
||||
return rs.Search(str);
|
||||
}
|
||||
@ -1227,7 +1271,7 @@ private:
|
||||
template <typename ValueType>
|
||||
RegexType* CreatePattern(const ValueType& value) {
|
||||
if (value.IsString()) {
|
||||
RegexType *r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType)));
|
||||
RegexType* r = static_cast<RegexType*>(allocator_->Malloc(sizeof(RegexType)));
|
||||
try {
|
||||
return new (r) RegexType(value.GetString(), std::size_t(value.GetStringLength()), std::regex_constants::ECMAScript);
|
||||
}
|
||||
@ -1238,7 +1282,7 @@ private:
|
||||
return 0;
|
||||
}
|
||||
|
||||
static bool IsPatternMatch(const RegexType* pattern, const Ch *str, SizeType length) {
|
||||
static bool IsPatternMatch(const RegexType* pattern, const Ch* str, SizeType length) {
|
||||
std::match_results<const Ch*> r;
|
||||
return std::regex_search(str, str + length, r, *pattern);
|
||||
}
|
||||
@ -1246,17 +1290,24 @@ private:
|
||||
template <typename ValueType>
|
||||
RegexType* CreatePattern(const ValueType&) { return 0; }
|
||||
|
||||
static bool IsPatternMatch(const RegexType*, const Ch *, SizeType) { return true; }
|
||||
static bool IsPatternMatch(const RegexType*, const Ch*, SizeType) { return true; }
|
||||
#endif // RAPIDJSON_SCHEMA_USE_STDREGEX
|
||||
|
||||
void AddType(const ValueType& type) {
|
||||
if (type == GetNullString() ) type_ |= 1 << kNullSchemaType;
|
||||
else if (type == GetBooleanString()) type_ |= 1 << kBooleanSchemaType;
|
||||
else if (type == GetObjectString() ) type_ |= 1 << kObjectSchemaType;
|
||||
else if (type == GetArrayString() ) type_ |= 1 << kArraySchemaType;
|
||||
else if (type == GetStringString() ) type_ |= 1 << kStringSchemaType;
|
||||
else if (type == GetIntegerString()) type_ |= 1 << kIntegerSchemaType;
|
||||
else if (type == GetNumberString() ) type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType);
|
||||
if (type == GetNullString())
|
||||
type_ |= 1 << kNullSchemaType;
|
||||
else if (type == GetBooleanString())
|
||||
type_ |= 1 << kBooleanSchemaType;
|
||||
else if (type == GetObjectString())
|
||||
type_ |= 1 << kObjectSchemaType;
|
||||
else if (type == GetArrayString())
|
||||
type_ |= 1 << kArraySchemaType;
|
||||
else if (type == GetStringString())
|
||||
type_ |= 1 << kStringSchemaType;
|
||||
else if (type == GetIntegerString())
|
||||
type_ |= 1 << kIntegerSchemaType;
|
||||
else if (type == GetNumberString())
|
||||
type_ |= (1 << kNumberSchemaType) | (1 << kIntegerSchemaType);
|
||||
}
|
||||
|
||||
bool CreateParallelValidator(Context& context) const {
|
||||
@ -1302,8 +1353,7 @@ private:
|
||||
const Ch* str = name.GetString();
|
||||
for (SizeType index = 0; index < propertyCount_; index++)
|
||||
if (properties_[index].name.GetStringLength() == len &&
|
||||
(std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0))
|
||||
{
|
||||
(std::memcmp(properties_[index].name.GetString(), str, sizeof(Ch) * len) == 0)) {
|
||||
*outIndex = index;
|
||||
return true;
|
||||
}
|
||||
@ -1338,7 +1388,8 @@ private:
|
||||
RAPIDJSON_INVALID_KEYWORD_RETURN(exclusiveMaximum_ ? kValidateErrorExclusiveMaximum : kValidateErrorMaximum);
|
||||
}
|
||||
}
|
||||
else if (maximum_.IsUint64()) { }
|
||||
else if (maximum_.IsUint64()) {
|
||||
}
|
||||
/* do nothing */ // i <= max(int64_t) < maximum_.GetUint64()
|
||||
else if (!CheckDoubleMaximum(context, static_cast<double>(i)))
|
||||
return false;
|
||||
@ -1443,8 +1494,10 @@ private:
|
||||
if (type_ & (1 << kArraySchemaType)) eh.AddExpectedType(GetArrayString());
|
||||
if (type_ & (1 << kStringSchemaType)) eh.AddExpectedType(GetStringString());
|
||||
|
||||
if (type_ & (1 << kNumberSchemaType)) eh.AddExpectedType(GetNumberString());
|
||||
else if (type_ & (1 << kIntegerSchemaType)) eh.AddExpectedType(GetIntegerString());
|
||||
if (type_ & (1 << kNumberSchemaType))
|
||||
eh.AddExpectedType(GetNumberString());
|
||||
else if (type_ & (1 << kIntegerSchemaType))
|
||||
eh.AddExpectedType(GetIntegerString());
|
||||
|
||||
eh.EndDisallowedType(actualType);
|
||||
}
|
||||
@ -1518,10 +1571,10 @@ private:
|
||||
bool exclusiveMaximum_;
|
||||
|
||||
SizeType defaultValueLength_;
|
||||
};
|
||||
};
|
||||
|
||||
template<typename Stack, typename Ch>
|
||||
struct TokenHelper {
|
||||
template <typename Stack, typename Ch>
|
||||
struct TokenHelper {
|
||||
RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) {
|
||||
*documentStack.template Push<Ch>() = '/';
|
||||
char buffer[21];
|
||||
@ -1529,26 +1582,26 @@ struct TokenHelper {
|
||||
for (size_t i = 0; i < length; i++)
|
||||
*documentStack.template Push<Ch>() = static_cast<Ch>(buffer[i]);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// Partial specialized version for char to prevent buffer copying.
|
||||
template <typename Stack>
|
||||
struct TokenHelper<Stack, char> {
|
||||
// Partial specialized version for char to prevent buffer copying.
|
||||
template <typename Stack>
|
||||
struct TokenHelper<Stack, char> {
|
||||
RAPIDJSON_FORCEINLINE static void AppendIndexToken(Stack& documentStack, SizeType index) {
|
||||
if (sizeof(SizeType) == 4) {
|
||||
char *buffer = documentStack.template Push<char>(1 + 10); // '/' + uint
|
||||
char* buffer = documentStack.template Push<char>(1 + 10); // '/' + uint
|
||||
*buffer++ = '/';
|
||||
const char* end = internal::u32toa(index, buffer);
|
||||
documentStack.template Pop<char>(static_cast<size_t>(10 - (end - buffer)));
|
||||
}
|
||||
else {
|
||||
char *buffer = documentStack.template Push<char>(1 + 20); // '/' + uint64
|
||||
char* buffer = documentStack.template Push<char>(1 + 20); // '/' + uint64
|
||||
*buffer++ = '/';
|
||||
const char* end = internal::u64toa(index, buffer);
|
||||
documentStack.template Pop<char>(static_cast<size_t>(20 - (end - buffer)));
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
} // namespace internal
|
||||
|
||||
@ -1602,19 +1655,17 @@ public:
|
||||
\param allocator An optional allocator instance for allocating memory. Can be null.
|
||||
*/
|
||||
explicit GenericSchemaDocument(const ValueType& document, const Ch* uri = 0, SizeType uriLength = 0,
|
||||
IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) :
|
||||
remoteProvider_(remoteProvider),
|
||||
IRemoteSchemaDocumentProviderType* remoteProvider = 0, Allocator* allocator = 0) : remoteProvider_(remoteProvider),
|
||||
allocator_(allocator),
|
||||
ownAllocator_(),
|
||||
root_(),
|
||||
typeless_(),
|
||||
schemaMap_(allocator, kInitialSchemaMapSize),
|
||||
schemaRef_(allocator, kInitialSchemaRefSize)
|
||||
{
|
||||
schemaRef_(allocator, kInitialSchemaRefSize) {
|
||||
if (!allocator_)
|
||||
ownAllocator_ = allocator_ = RAPIDJSON_NEW(Allocator)();
|
||||
|
||||
Ch noUri[1] = {0};
|
||||
Ch noUri[1] = { 0 };
|
||||
uri_.SetString(uri ? uri : noUri, uriLength, *allocator_);
|
||||
|
||||
typeless_ = static_cast<SchemaType*>(allocator_->Malloc(sizeof(SchemaType)));
|
||||
@ -1649,16 +1700,14 @@ public:
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
//! Move constructor in C++11
|
||||
GenericSchemaDocument(GenericSchemaDocument&& rhs) RAPIDJSON_NOEXCEPT :
|
||||
remoteProvider_(rhs.remoteProvider_),
|
||||
GenericSchemaDocument(GenericSchemaDocument&& rhs) RAPIDJSON_NOEXCEPT : remoteProvider_(rhs.remoteProvider_),
|
||||
allocator_(rhs.allocator_),
|
||||
ownAllocator_(rhs.ownAllocator_),
|
||||
root_(rhs.root_),
|
||||
typeless_(rhs.typeless_),
|
||||
schemaMap_(std::move(rhs.schemaMap_)),
|
||||
schemaRef_(std::move(rhs.schemaRef_)),
|
||||
uri_(std::move(rhs.uri_))
|
||||
{
|
||||
uri_(std::move(rhs.uri_)) {
|
||||
rhs.remoteProvider_ = 0;
|
||||
rhs.allocator_ = 0;
|
||||
rhs.ownAllocator_ = 0;
|
||||
@ -1691,7 +1740,7 @@ private:
|
||||
GenericSchemaDocument& operator=(const GenericSchemaDocument&);
|
||||
|
||||
struct SchemaRefEntry {
|
||||
SchemaRefEntry(const PointerType& s, const PointerType& t, const SchemaType** outSchema, Allocator *allocator) : source(s, allocator), target(t, allocator), schema(outSchema) {}
|
||||
SchemaRefEntry(const PointerType& s, const PointerType& t, const SchemaType** outSchema, Allocator* allocator) : source(s, allocator), target(t, allocator), schema(outSchema) {}
|
||||
PointerType source;
|
||||
PointerType target;
|
||||
const SchemaType** schema;
|
||||
@ -1806,8 +1855,8 @@ private:
|
||||
static const size_t kInitialSchemaRefSize = 64;
|
||||
|
||||
IRemoteSchemaDocumentProviderType* remoteProvider_;
|
||||
Allocator *allocator_;
|
||||
Allocator *ownAllocator_;
|
||||
Allocator* allocator_;
|
||||
Allocator* ownAllocator_;
|
||||
const SchemaType* root_; //!< Root schema.
|
||||
SchemaType* typeless_;
|
||||
internal::Stack<Allocator> schemaMap_; // Stores created Pointer -> Schemas
|
||||
@ -1839,8 +1888,7 @@ template <
|
||||
typename SchemaDocumentType,
|
||||
typename OutputHandler = BaseReaderHandler<typename SchemaDocumentType::SchemaType::EncodingType>,
|
||||
typename StateAllocator = CrtAllocator>
|
||||
class GenericSchemaValidator :
|
||||
public internal::ISchemaStateFactory<typename SchemaDocumentType::SchemaType>,
|
||||
class GenericSchemaValidator : public internal::ISchemaStateFactory<typename SchemaDocumentType::SchemaType>,
|
||||
public internal::ISchemaValidator,
|
||||
public internal::IValidationErrorHandler<typename SchemaDocumentType::SchemaType> {
|
||||
public:
|
||||
@ -1864,8 +1912,7 @@ public:
|
||||
StateAllocator* allocator = 0,
|
||||
size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
|
||||
size_t documentStackCapacity = kDefaultDocumentStackCapacity)
|
||||
:
|
||||
schemaDocument_(&schemaDocument),
|
||||
: schemaDocument_(&schemaDocument),
|
||||
root_(schemaDocument.GetRoot()),
|
||||
stateAllocator_(allocator),
|
||||
ownStateAllocator_(0),
|
||||
@ -1878,7 +1925,8 @@ public:
|
||||
valid_(true),
|
||||
flags_(kValidateDefaultFlags)
|
||||
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||
, depth_(0)
|
||||
,
|
||||
depth_(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
@ -1896,8 +1944,7 @@ public:
|
||||
StateAllocator* allocator = 0,
|
||||
size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
|
||||
size_t documentStackCapacity = kDefaultDocumentStackCapacity)
|
||||
:
|
||||
schemaDocument_(&schemaDocument),
|
||||
: schemaDocument_(&schemaDocument),
|
||||
root_(schemaDocument.GetRoot()),
|
||||
stateAllocator_(allocator),
|
||||
ownStateAllocator_(0),
|
||||
@ -1910,7 +1957,8 @@ public:
|
||||
valid_(true),
|
||||
flags_(kValidateDefaultFlags)
|
||||
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||
, depth_(0)
|
||||
,
|
||||
depth_(0)
|
||||
#endif
|
||||
{
|
||||
}
|
||||
@ -2168,10 +2216,10 @@ public:
|
||||
}
|
||||
|
||||
#define RAPIDJSON_STRING_(name, ...) \
|
||||
static const StringRefType& Get##name##String() {\
|
||||
static const Ch s[] = { __VA_ARGS__, '\0' };\
|
||||
static const StringRefType& Get##name##String() { \
|
||||
static const Ch s[] = { __VA_ARGS__, '\0' }; \
|
||||
static const StringRefType v(s, static_cast<SizeType>(sizeof(s) / sizeof(Ch) - 1)); \
|
||||
return v;\
|
||||
return v; \
|
||||
}
|
||||
|
||||
RAPIDJSON_STRING_(InstanceRef, 'i', 'n', 's', 't', 'a', 'n', 'c', 'e', 'R', 'e', 'f')
|
||||
@ -2189,54 +2237,52 @@ public:
|
||||
|
||||
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_() \
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN\
|
||||
*documentStack_.template Push<Ch>() = '\0';\
|
||||
documentStack_.template Pop<Ch>(1);\
|
||||
internal::PrintInvalidDocument(documentStack_.template Bottom<Ch>());\
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
RAPIDJSON_MULTILINEMACRO_BEGIN \
|
||||
*documentStack_.template Push<Ch>() = '\0'; \
|
||||
documentStack_.template Pop<Ch>(1); \
|
||||
internal::PrintInvalidDocument(documentStack_.template Bottom<Ch>()); \
|
||||
RAPIDJSON_MULTILINEMACRO_END
|
||||
#else
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_()
|
||||
#endif
|
||||
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1)\
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1) \
|
||||
if (!valid_) return false; \
|
||||
if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) {\
|
||||
RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_();\
|
||||
return valid_ = false;\
|
||||
if ((!BeginValue() && !GetContinueOnErrors()) || (!CurrentSchema().method arg1 && !GetContinueOnErrors())) { \
|
||||
RAPIDJSON_SCHEMA_HANDLE_BEGIN_VERBOSE_(); \
|
||||
return valid_ = false; \
|
||||
}
|
||||
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2)\
|
||||
for (Context* context = schemaStack_.template Bottom<Context>(); context != schemaStack_.template End<Context>(); context++) {\
|
||||
if (context->hasher)\
|
||||
static_cast<HasherType*>(context->hasher)->method arg2;\
|
||||
if (context->validators)\
|
||||
for (SizeType i_ = 0; i_ < context->validatorCount; i_++)\
|
||||
static_cast<GenericSchemaValidator*>(context->validators[i_])->method arg2;\
|
||||
if (context->patternPropertiesValidators)\
|
||||
for (SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++)\
|
||||
static_cast<GenericSchemaValidator*>(context->patternPropertiesValidators[i_])->method arg2;\
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2) \
|
||||
for (Context* context = schemaStack_.template Bottom<Context>(); context != schemaStack_.template End<Context>(); context++) { \
|
||||
if (context->hasher) \
|
||||
static_cast<HasherType*>(context->hasher)->method arg2; \
|
||||
if (context->validators) \
|
||||
for (SizeType i_ = 0; i_ < context->validatorCount; i_++) \
|
||||
static_cast<GenericSchemaValidator*>(context->validators[i_])->method arg2; \
|
||||
if (context->patternPropertiesValidators) \
|
||||
for (SizeType i_ = 0; i_ < context->patternPropertiesValidatorCount; i_++) \
|
||||
static_cast<GenericSchemaValidator*>(context->patternPropertiesValidators[i_])->method arg2; \
|
||||
}
|
||||
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)\
|
||||
valid_ = (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2);\
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2) \
|
||||
valid_ = (EndValue() || GetContinueOnErrors()) && (!outputHandler_ || outputHandler_->method arg2); \
|
||||
return valid_;
|
||||
|
||||
#define RAPIDJSON_SCHEMA_HANDLE_VALUE_(method, arg1, arg2) \
|
||||
RAPIDJSON_SCHEMA_HANDLE_BEGIN_ (method, arg1);\
|
||||
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2);\
|
||||
RAPIDJSON_SCHEMA_HANDLE_END_ (method, arg2)
|
||||
RAPIDJSON_SCHEMA_HANDLE_BEGIN_(method, arg1); \
|
||||
RAPIDJSON_SCHEMA_HANDLE_PARALLEL_(method, arg2); \
|
||||
RAPIDJSON_SCHEMA_HANDLE_END_(method, arg2)
|
||||
|
||||
bool Null() { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Null, (CurrentContext()), ( )); }
|
||||
bool Null() { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Null, (CurrentContext()), ()); }
|
||||
bool Bool(bool b) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Bool, (CurrentContext(), b), (b)); }
|
||||
bool Int(int i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int, (CurrentContext(), i), (i)); }
|
||||
bool Uint(unsigned u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint, (CurrentContext(), u), (u)); }
|
||||
bool Int64(int64_t i) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Int64, (CurrentContext(), i), (i)); }
|
||||
bool Uint64(uint64_t u) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Uint64, (CurrentContext(), u), (u)); }
|
||||
bool Double(double d) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(Double, (CurrentContext(), d), (d)); }
|
||||
bool RawNumber(const Ch* str, SizeType length, bool copy)
|
||||
{ RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
|
||||
bool String(const Ch* str, SizeType length, bool copy)
|
||||
{ RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
|
||||
bool RawNumber(const Ch* str, SizeType length, bool copy) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
|
||||
bool String(const Ch* str, SizeType length, bool copy) { RAPIDJSON_SCHEMA_HANDLE_VALUE_(String, (CurrentContext(), str, length, copy), (str, length, copy)); }
|
||||
|
||||
bool StartObject() {
|
||||
RAPIDJSON_SCHEMA_HANDLE_BEGIN_(StartObject, (CurrentContext()));
|
||||
@ -2331,8 +2377,7 @@ private:
|
||||
StateAllocator* allocator = 0,
|
||||
size_t schemaStackCapacity = kDefaultSchemaStackCapacity,
|
||||
size_t documentStackCapacity = kDefaultDocumentStackCapacity)
|
||||
:
|
||||
schemaDocument_(&schemaDocument),
|
||||
: schemaDocument_(&schemaDocument),
|
||||
root_(root),
|
||||
stateAllocator_(allocator),
|
||||
ownStateAllocator_(0),
|
||||
@ -2345,7 +2390,8 @@ private:
|
||||
valid_(true),
|
||||
flags_(kValidateDefaultFlags)
|
||||
#if RAPIDJSON_SCHEMA_VERBOSE
|
||||
, depth_(depth)
|
||||
,
|
||||
depth_(depth)
|
||||
#endif
|
||||
{
|
||||
if (basePath && basePathSize)
|
||||
@ -2423,7 +2469,8 @@ private:
|
||||
// Cleanup before returning if continuing
|
||||
if (GetContinueOnErrors()) {
|
||||
a->PushBack(h, GetStateAllocator());
|
||||
while (!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) != '/');
|
||||
while (!documentStack_.Empty() && *documentStack_.template Pop<Ch>(1) != '/')
|
||||
;
|
||||
}
|
||||
RAPIDJSON_INVALID_KEYWORD_RETURN(kValidateErrorUniqueItems);
|
||||
}
|
||||
@ -2471,7 +2518,8 @@ private:
|
||||
PointerType instancePointer = GetInvalidDocumentPointer();
|
||||
((parent && instancePointer.GetTokenCount() > 0)
|
||||
? PointerType(instancePointer.GetTokens(), instancePointer.GetTokenCount() - 1)
|
||||
: instancePointer).StringifyUriFragment(sb);
|
||||
: instancePointer)
|
||||
.StringifyUriFragment(sb);
|
||||
ValueType instanceRef(sb.GetString(), static_cast<SizeType>(sb.GetSize() / sizeof(Ch)),
|
||||
GetStateAllocator());
|
||||
result.AddMember(GetInstanceRefString(), instanceRef, GetStateAllocator());
|
||||
@ -2481,8 +2529,10 @@ private:
|
||||
GenericStringBuffer<EncodingType> sb;
|
||||
SizeType len = CurrentSchema().GetURI().GetStringLength();
|
||||
if (len) memcpy(sb.Push(len), CurrentSchema().GetURI().GetString(), len * sizeof(Ch));
|
||||
if (schema.GetTokenCount()) schema.StringifyUriFragment(sb);
|
||||
else GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
||||
if (schema.GetTokenCount())
|
||||
schema.StringifyUriFragment(sb);
|
||||
else
|
||||
GetInvalidSchemaPointer().StringifyUriFragment(sb);
|
||||
ValueType schemaRef(sb.GetString(), static_cast<SizeType>(sb.GetSize() / sizeof(Ch)),
|
||||
GetStateAllocator());
|
||||
result.AddMember(GetSchemaRefString(), schemaRef, GetStateAllocator());
|
||||
|
@ -69,7 +69,7 @@ concept Stream {
|
||||
For custom stream, this type can be specialized for other configuration.
|
||||
See TEST(Reader, CustomStringStream) in readertest.cpp for example.
|
||||
*/
|
||||
template<typename Stream>
|
||||
template <typename Stream>
|
||||
struct StreamTraits {
|
||||
//! Whether to make local copy of stream for optimization during parsing.
|
||||
/*!
|
||||
@ -80,20 +80,20 @@ struct StreamTraits {
|
||||
};
|
||||
|
||||
//! Reserve n characters for writing to a stream.
|
||||
template<typename Stream>
|
||||
template <typename Stream>
|
||||
inline void PutReserve(Stream& stream, size_t count) {
|
||||
(void)stream;
|
||||
(void)count;
|
||||
}
|
||||
|
||||
//! Write character to a stream, presuming buffer is reserved.
|
||||
template<typename Stream>
|
||||
template <typename Stream>
|
||||
inline void PutUnsafe(Stream& stream, typename Stream::Ch c) {
|
||||
stream.Put(c);
|
||||
}
|
||||
|
||||
//! Put N copies of a character to a stream.
|
||||
template<typename Stream, typename Ch>
|
||||
template <typename Stream, typename Ch>
|
||||
inline void PutN(Stream& stream, Ch c, size_t n) {
|
||||
PutReserve(stream, n);
|
||||
for (size_t i = 0; i < n; i++)
|
||||
@ -115,11 +115,11 @@ RAPIDJSON_DIAG_OFF(4702) // unreachable code
|
||||
RAPIDJSON_DIAG_OFF(4512) // assignment operator could not be generated
|
||||
#endif
|
||||
|
||||
template <typename InputStream, typename Encoding = UTF8<> >
|
||||
template <typename InputStream, typename Encoding = UTF8<>>
|
||||
class GenericStreamWrapper {
|
||||
public:
|
||||
typedef typename Encoding::Ch Ch;
|
||||
GenericStreamWrapper(InputStream& is): is_(is) {}
|
||||
GenericStreamWrapper(InputStream& is) : is_(is) {}
|
||||
|
||||
Ch Peek() const { return is_.Peek(); }
|
||||
Ch Take() { return is_.Take(); }
|
||||
@ -154,28 +154,34 @@ template <typename Encoding>
|
||||
struct GenericStringStream {
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
GenericStringStream(const Ch *src) : src_(src), head_(src) {}
|
||||
GenericStringStream(const Ch* src) : src_(src), head_(src) {}
|
||||
|
||||
Ch Peek() const { return *src_; }
|
||||
Ch Take() { return *src_++; }
|
||||
size_t Tell() const { return static_cast<size_t>(src_ - head_); }
|
||||
|
||||
Ch* PutBegin() { RAPIDJSON_ASSERT(false); return 0; }
|
||||
Ch* PutBegin() {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
void Put(Ch) { RAPIDJSON_ASSERT(false); }
|
||||
void Flush() { RAPIDJSON_ASSERT(false); }
|
||||
size_t PutEnd(Ch*) { RAPIDJSON_ASSERT(false); return 0; }
|
||||
size_t PutEnd(Ch*) {
|
||||
RAPIDJSON_ASSERT(false);
|
||||
return 0;
|
||||
}
|
||||
|
||||
const Ch* src_; //!< Current read position.
|
||||
const Ch* head_; //!< Original head of the string.
|
||||
};
|
||||
|
||||
template <typename Encoding>
|
||||
struct StreamTraits<GenericStringStream<Encoding> > {
|
||||
struct StreamTraits<GenericStringStream<Encoding>> {
|
||||
enum { copyOptimization = 1 };
|
||||
};
|
||||
|
||||
//! String stream with UTF8 encoding.
|
||||
typedef GenericStringStream<UTF8<> > StringStream;
|
||||
typedef GenericStringStream<UTF8<>> StringStream;
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////
|
||||
// InsituStringStream
|
||||
@ -188,7 +194,7 @@ template <typename Encoding>
|
||||
struct GenericInsituStringStream {
|
||||
typedef typename Encoding::Ch Ch;
|
||||
|
||||
GenericInsituStringStream(Ch *src) : src_(src), dst_(0), head_(src) {}
|
||||
GenericInsituStringStream(Ch* src) : src_(src), dst_(0), head_(src) {}
|
||||
|
||||
// Read
|
||||
Ch Peek() { return *src_; }
|
||||
@ -196,13 +202,20 @@ struct GenericInsituStringStream {
|
||||
size_t Tell() { return static_cast<size_t>(src_ - head_); }
|
||||
|
||||
// Write
|
||||
void Put(Ch c) { RAPIDJSON_ASSERT(dst_ != 0); *dst_++ = c; }
|
||||
void Put(Ch c) {
|
||||
RAPIDJSON_ASSERT(dst_ != 0);
|
||||
*dst_++ = c;
|
||||
}
|
||||
|
||||
Ch* PutBegin() { return dst_ = src_; }
|
||||
size_t PutEnd(Ch* begin) { return static_cast<size_t>(dst_ - begin); }
|
||||
void Flush() {}
|
||||
|
||||
Ch* Push(size_t count) { Ch* begin = dst_; dst_ += count; return begin; }
|
||||
Ch* Push(size_t count) {
|
||||
Ch* begin = dst_;
|
||||
dst_ += count;
|
||||
return begin;
|
||||
}
|
||||
void Pop(size_t count) { dst_ -= count; }
|
||||
|
||||
Ch* src_;
|
||||
@ -211,12 +224,12 @@ struct GenericInsituStringStream {
|
||||
};
|
||||
|
||||
template <typename Encoding>
|
||||
struct StreamTraits<GenericInsituStringStream<Encoding> > {
|
||||
struct StreamTraits<GenericInsituStringStream<Encoding>> {
|
||||
enum { copyOptimization = 1 };
|
||||
};
|
||||
|
||||
//! Insitu string stream with UTF8 encoding.
|
||||
typedef GenericInsituStringStream<UTF8<> > InsituStringStream;
|
||||
typedef GenericInsituStringStream<UTF8<>> InsituStringStream;
|
||||
|
||||
RAPIDJSON_NAMESPACE_END
|
||||
|
||||
|
@ -26,7 +26,7 @@
|
||||
|
||||
#if defined(__clang__)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
|
||||
#endif
|
||||
|
||||
RAPIDJSON_NAMESPACE_BEGIN
|
||||
@ -94,21 +94,21 @@ private:
|
||||
};
|
||||
|
||||
//! String buffer with UTF8 encoding
|
||||
typedef GenericStringBuffer<UTF8<> > StringBuffer;
|
||||
typedef GenericStringBuffer<UTF8<>> StringBuffer;
|
||||
|
||||
template<typename Encoding, typename Allocator>
|
||||
template <typename Encoding, typename Allocator>
|
||||
inline void PutReserve(GenericStringBuffer<Encoding, Allocator>& stream, size_t count) {
|
||||
stream.Reserve(count);
|
||||
}
|
||||
|
||||
template<typename Encoding, typename Allocator>
|
||||
template <typename Encoding, typename Allocator>
|
||||
inline void PutUnsafe(GenericStringBuffer<Encoding, Allocator>& stream, typename Encoding::Ch c) {
|
||||
stream.PutUnsafe(c);
|
||||
}
|
||||
|
||||
//! Implement specialized version of PutN() with memset() for better performance.
|
||||
template<>
|
||||
inline void PutN(GenericStringBuffer<UTF8<> >& stream, char c, size_t n) {
|
||||
template <>
|
||||
inline void PutN(GenericStringBuffer<UTF8<>>& stream, char c, size_t n) {
|
||||
std::memset(stream.stack_.Push<char>(n), c, n * sizeof(c));
|
||||
}
|
||||
|
||||
|
@ -40,8 +40,8 @@
|
||||
#ifdef __clang__
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(padded)
|
||||
RAPIDJSON_DIAG_OFF(unreachable-code)
|
||||
RAPIDJSON_DIAG_OFF(c++98-compat)
|
||||
RAPIDJSON_DIAG_OFF(unreachable - code)
|
||||
RAPIDJSON_DIAG_OFF(c++ 98 - compat)
|
||||
#elif defined(_MSC_VER)
|
||||
RAPIDJSON_DIAG_PUSH
|
||||
RAPIDJSON_DIAG_OFF(4127) // conditional expression is constant
|
||||
@ -86,7 +86,7 @@ enum WriteFlag {
|
||||
\tparam StackAllocator Type of allocator for allocating memory of stack.
|
||||
\note implements Handler concept
|
||||
*/
|
||||
template<typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
|
||||
template <typename OutputStream, typename SourceEncoding = UTF8<>, typename TargetEncoding = UTF8<>, typename StackAllocator = CrtAllocator, unsigned writeFlags = kWriteDefaultFlags>
|
||||
class Writer {
|
||||
public:
|
||||
typedef typename SourceEncoding::Ch Ch;
|
||||
@ -98,17 +98,12 @@ public:
|
||||
\param stackAllocator User supplied allocator. If it is null, it will create a private one.
|
||||
\param levelDepth Initial capacity of stack.
|
||||
*/
|
||||
explicit
|
||||
Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = kDefaultLevelDepth) :
|
||||
os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
|
||||
explicit Writer(OutputStream& os, StackAllocator* stackAllocator = 0, size_t levelDepth = kDefaultLevelDepth) : os_(&os), level_stack_(stackAllocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
|
||||
|
||||
explicit
|
||||
Writer(StackAllocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) :
|
||||
os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
|
||||
explicit Writer(StackAllocator* allocator = 0, size_t levelDepth = kDefaultLevelDepth) : os_(0), level_stack_(allocator, levelDepth * sizeof(Level)), maxDecimalPlaces_(kDefaultMaxDecimalPlaces), hasRoot_(false) {}
|
||||
|
||||
#if RAPIDJSON_HAS_CXX11_RVALUE_REFS
|
||||
Writer(Writer&& rhs) :
|
||||
os_(rhs.os_), level_stack_(std::move(rhs.level_stack_)), maxDecimalPlaces_(rhs.maxDecimalPlaces_), hasRoot_(rhs.hasRoot_) {
|
||||
Writer(Writer&& rhs) : os_(rhs.os_), level_stack_(std::move(rhs.level_stack_)), maxDecimalPlaces_(rhs.maxDecimalPlaces_), hasRoot_(rhs.hasRoot_) {
|
||||
rhs.os_ = 0;
|
||||
}
|
||||
#endif
|
||||
@ -179,19 +174,40 @@ public:
|
||||
*/
|
||||
//@{
|
||||
|
||||
bool Null() { Prefix(kNullType); return EndValue(WriteNull()); }
|
||||
bool Bool(bool b) { Prefix(b ? kTrueType : kFalseType); return EndValue(WriteBool(b)); }
|
||||
bool Int(int i) { Prefix(kNumberType); return EndValue(WriteInt(i)); }
|
||||
bool Uint(unsigned u) { Prefix(kNumberType); return EndValue(WriteUint(u)); }
|
||||
bool Int64(int64_t i64) { Prefix(kNumberType); return EndValue(WriteInt64(i64)); }
|
||||
bool Uint64(uint64_t u64) { Prefix(kNumberType); return EndValue(WriteUint64(u64)); }
|
||||
bool Null() {
|
||||
Prefix(kNullType);
|
||||
return EndValue(WriteNull());
|
||||
}
|
||||
bool Bool(bool b) {
|
||||
Prefix(b ? kTrueType : kFalseType);
|
||||
return EndValue(WriteBool(b));
|
||||
}
|
||||
bool Int(int i) {
|
||||
Prefix(kNumberType);
|
||||
return EndValue(WriteInt(i));
|
||||
}
|
||||
bool Uint(unsigned u) {
|
||||
Prefix(kNumberType);
|
||||
return EndValue(WriteUint(u));
|
||||
}
|
||||
bool Int64(int64_t i64) {
|
||||
Prefix(kNumberType);
|
||||
return EndValue(WriteInt64(i64));
|
||||
}
|
||||
bool Uint64(uint64_t u64) {
|
||||
Prefix(kNumberType);
|
||||
return EndValue(WriteUint64(u64));
|
||||
}
|
||||
|
||||
//! Writes the given \c double value to the stream
|
||||
/*!
|
||||
\param d The value to be written.
|
||||
\return Whether it is succeed.
|
||||
*/
|
||||
bool Double(double d) { Prefix(kNumberType); return EndValue(WriteDouble(d)); }
|
||||
bool Double(double d) {
|
||||
Prefix(kNumberType);
|
||||
return EndValue(WriteDouble(d));
|
||||
}
|
||||
|
||||
bool RawNumber(const Ch* str, SizeType length, bool copy = false) {
|
||||
RAPIDJSON_ASSERT(str != 0);
|
||||
@ -222,8 +238,7 @@ public:
|
||||
bool Key(const Ch* str, SizeType length, bool copy = false) { return String(str, length, copy); }
|
||||
|
||||
#if RAPIDJSON_HAS_STDSTRING
|
||||
bool Key(const std::basic_string<Ch>& str)
|
||||
{
|
||||
bool Key(const std::basic_string<Ch>& str) {
|
||||
return Key(str.data(), SizeType(str.size()));
|
||||
}
|
||||
#endif
|
||||
@ -295,17 +310,28 @@ protected:
|
||||
|
||||
bool WriteNull() {
|
||||
PutReserve(*os_, 4);
|
||||
PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 'l'); return true;
|
||||
PutUnsafe(*os_, 'n');
|
||||
PutUnsafe(*os_, 'u');
|
||||
PutUnsafe(*os_, 'l');
|
||||
PutUnsafe(*os_, 'l');
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteBool(bool b) {
|
||||
if (b) {
|
||||
PutReserve(*os_, 4);
|
||||
PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'r'); PutUnsafe(*os_, 'u'); PutUnsafe(*os_, 'e');
|
||||
PutUnsafe(*os_, 't');
|
||||
PutUnsafe(*os_, 'r');
|
||||
PutUnsafe(*os_, 'u');
|
||||
PutUnsafe(*os_, 'e');
|
||||
}
|
||||
else {
|
||||
PutReserve(*os_, 5);
|
||||
PutUnsafe(*os_, 'f'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'l'); PutUnsafe(*os_, 's'); PutUnsafe(*os_, 'e');
|
||||
PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'a');
|
||||
PutUnsafe(*os_, 'l');
|
||||
PutUnsafe(*os_, 's');
|
||||
PutUnsafe(*os_, 'e');
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@ -352,7 +378,9 @@ protected:
|
||||
return false;
|
||||
if (internal::Double(d).IsNan()) {
|
||||
PutReserve(*os_, 3);
|
||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||
PutUnsafe(*os_, 'N');
|
||||
PutUnsafe(*os_, 'a');
|
||||
PutUnsafe(*os_, 'N');
|
||||
return true;
|
||||
}
|
||||
if (internal::Double(d).Sign()) {
|
||||
@ -361,8 +389,14 @@ protected:
|
||||
}
|
||||
else
|
||||
PutReserve(*os_, 8);
|
||||
PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
||||
PutUnsafe(*os_, 'I');
|
||||
PutUnsafe(*os_, 'n');
|
||||
PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i');
|
||||
PutUnsafe(*os_, 'n');
|
||||
PutUnsafe(*os_, 'i');
|
||||
PutUnsafe(*os_, 't');
|
||||
PutUnsafe(*os_, 'y');
|
||||
return true;
|
||||
}
|
||||
|
||||
@ -377,13 +411,13 @@ protected:
|
||||
bool WriteString(const Ch* str, SizeType length) {
|
||||
static const typename OutputStream::Ch hexDigits[16] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F' };
|
||||
static const char escape[256] = {
|
||||
#define Z16 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
|
||||
#define Z16 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
|
||||
//0 1 2 3 4 5 6 7 8 9 A B C D E F
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'b', 't', 'n', 'u', 'f', 'r', 'u', 'u', // 00
|
||||
'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', 'u', // 10
|
||||
0, 0, '"', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20
|
||||
Z16, Z16, // 30~4F
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,'\\', 0, 0, 0, // 50
|
||||
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '\\', 0, 0, 0, // 50
|
||||
Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16, Z16 // 60~FF
|
||||
#undef Z16
|
||||
};
|
||||
@ -408,7 +442,7 @@ protected:
|
||||
PutUnsafe(*os_, hexDigits[(codepoint >> 12) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(codepoint >> 8) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(codepoint >> 4) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(codepoint ) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(codepoint)&15]);
|
||||
}
|
||||
else {
|
||||
RAPIDJSON_ASSERT(codepoint >= 0x010000 && codepoint <= 0x10FFFF);
|
||||
@ -419,13 +453,13 @@ protected:
|
||||
PutUnsafe(*os_, hexDigits[(lead >> 12) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(lead >> 8) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(lead >> 4) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(lead ) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(lead)&15]);
|
||||
PutUnsafe(*os_, '\\');
|
||||
PutUnsafe(*os_, 'u');
|
||||
PutUnsafe(*os_, hexDigits[(trail >> 12) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(trail >> 8) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(trail >> 4) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(trail ) & 15]);
|
||||
PutUnsafe(*os_, hexDigits[(trail)&15]);
|
||||
}
|
||||
}
|
||||
else if ((sizeof(Ch) == 1 || static_cast<unsigned>(c) < 256) && RAPIDJSON_UNLIKELY(escape[static_cast<unsigned char>(c)])) {
|
||||
@ -439,9 +473,7 @@ protected:
|
||||
PutUnsafe(*os_, hexDigits[static_cast<unsigned char>(c) & 0xF]);
|
||||
}
|
||||
}
|
||||
else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
|
||||
Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) :
|
||||
Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
|
||||
else if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ? Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) : Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
|
||||
return false;
|
||||
}
|
||||
PutUnsafe(*os_, '\"');
|
||||
@ -452,19 +484,29 @@ protected:
|
||||
return RAPIDJSON_LIKELY(is.Tell() < length);
|
||||
}
|
||||
|
||||
bool WriteStartObject() { os_->Put('{'); return true; }
|
||||
bool WriteEndObject() { os_->Put('}'); return true; }
|
||||
bool WriteStartArray() { os_->Put('['); return true; }
|
||||
bool WriteEndArray() { os_->Put(']'); return true; }
|
||||
bool WriteStartObject() {
|
||||
os_->Put('{');
|
||||
return true;
|
||||
}
|
||||
bool WriteEndObject() {
|
||||
os_->Put('}');
|
||||
return true;
|
||||
}
|
||||
bool WriteStartArray() {
|
||||
os_->Put('[');
|
||||
return true;
|
||||
}
|
||||
bool WriteEndArray() {
|
||||
os_->Put(']');
|
||||
return true;
|
||||
}
|
||||
|
||||
bool WriteRawValue(const Ch* json, size_t length) {
|
||||
PutReserve(*os_, length);
|
||||
GenericStringStream<SourceEncoding> is(json);
|
||||
while (RAPIDJSON_LIKELY(is.Tell() < length)) {
|
||||
RAPIDJSON_ASSERT(is.Peek() != '\0');
|
||||
if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ?
|
||||
Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) :
|
||||
Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
|
||||
if (RAPIDJSON_UNLIKELY(!(writeFlags & kWriteValidateEncodingFlag ? Transcoder<SourceEncoding, TargetEncoding>::Validate(is, *os_) : Transcoder<SourceEncoding, TargetEncoding>::TranscodeUnsafe(is, *os_))))
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
@ -510,39 +552,39 @@ private:
|
||||
|
||||
// Full specialization for StringStream to prevent memory copying
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::WriteInt(int i) {
|
||||
char *buffer = os_->Push(11);
|
||||
char* buffer = os_->Push(11);
|
||||
const char* end = internal::i32toa(i, buffer);
|
||||
os_->Pop(static_cast<size_t>(11 - (end - buffer)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::WriteUint(unsigned u) {
|
||||
char *buffer = os_->Push(10);
|
||||
char* buffer = os_->Push(10);
|
||||
const char* end = internal::u32toa(u, buffer);
|
||||
os_->Pop(static_cast<size_t>(10 - (end - buffer)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::WriteInt64(int64_t i64) {
|
||||
char *buffer = os_->Push(21);
|
||||
char* buffer = os_->Push(21);
|
||||
const char* end = internal::i64toa(i64, buffer);
|
||||
os_->Pop(static_cast<size_t>(21 - (end - buffer)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::WriteUint64(uint64_t u) {
|
||||
char *buffer = os_->Push(20);
|
||||
char* buffer = os_->Push(20);
|
||||
const char* end = internal::u64toa(u, buffer);
|
||||
os_->Pop(static_cast<size_t>(20 - (end - buffer)));
|
||||
return true;
|
||||
}
|
||||
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::WriteDouble(double d) {
|
||||
if (internal::Double(d).IsNanOrInf()) {
|
||||
// Note: This code path can only be reached if (RAPIDJSON_WRITE_DEFAULT_FLAGS & kWriteNanAndInfFlag).
|
||||
@ -550,7 +592,9 @@ inline bool Writer<StringBuffer>::WriteDouble(double d) {
|
||||
return false;
|
||||
if (internal::Double(d).IsNan()) {
|
||||
PutReserve(*os_, 3);
|
||||
PutUnsafe(*os_, 'N'); PutUnsafe(*os_, 'a'); PutUnsafe(*os_, 'N');
|
||||
PutUnsafe(*os_, 'N');
|
||||
PutUnsafe(*os_, 'a');
|
||||
PutUnsafe(*os_, 'N');
|
||||
return true;
|
||||
}
|
||||
if (internal::Double(d).Sign()) {
|
||||
@ -559,19 +603,25 @@ inline bool Writer<StringBuffer>::WriteDouble(double d) {
|
||||
}
|
||||
else
|
||||
PutReserve(*os_, 8);
|
||||
PutUnsafe(*os_, 'I'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 'n'); PutUnsafe(*os_, 'i'); PutUnsafe(*os_, 't'); PutUnsafe(*os_, 'y');
|
||||
PutUnsafe(*os_, 'I');
|
||||
PutUnsafe(*os_, 'n');
|
||||
PutUnsafe(*os_, 'f');
|
||||
PutUnsafe(*os_, 'i');
|
||||
PutUnsafe(*os_, 'n');
|
||||
PutUnsafe(*os_, 'i');
|
||||
PutUnsafe(*os_, 't');
|
||||
PutUnsafe(*os_, 'y');
|
||||
return true;
|
||||
}
|
||||
|
||||
char *buffer = os_->Push(25);
|
||||
char* buffer = os_->Push(25);
|
||||
char* end = internal::dtoa(d, buffer, maxDecimalPlaces_);
|
||||
os_->Pop(static_cast<size_t>(25 - (end - buffer)));
|
||||
return true;
|
||||
}
|
||||
|
||||
#if defined(RAPIDJSON_SSE2) || defined(RAPIDJSON_SSE42)
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
|
||||
if (length < 16)
|
||||
return RAPIDJSON_LIKELY(is.Tell() < length);
|
||||
@ -598,12 +648,12 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
|
||||
static const char dquote[16] = { '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"', '\"' };
|
||||
static const char bslash[16] = { '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\', '\\' };
|
||||
static const char space[16] = { 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F, 0x1F };
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i *>(&space[0]));
|
||||
const __m128i dq = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&dquote[0]));
|
||||
const __m128i bs = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&bslash[0]));
|
||||
const __m128i sp = _mm_loadu_si128(reinterpret_cast<const __m128i*>(&space[0]));
|
||||
|
||||
for (; p != endAligned; p += 16) {
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i *>(p));
|
||||
const __m128i s = _mm_load_si128(reinterpret_cast<const __m128i*>(p));
|
||||
const __m128i t1 = _mm_cmpeq_epi8(s, dq);
|
||||
const __m128i t2 = _mm_cmpeq_epi8(s, bs);
|
||||
const __m128i t3 = _mm_cmpeq_epi8(_mm_max_epu8(s, sp), sp); // s < 0x20 <=> max(s, 0x1F) == 0x1F
|
||||
@ -625,14 +675,14 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
|
||||
p += len;
|
||||
break;
|
||||
}
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i *>(os_->PushUnsafe(16)), s);
|
||||
_mm_storeu_si128(reinterpret_cast<__m128i*>(os_->PushUnsafe(16)), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
return RAPIDJSON_LIKELY(is.Tell() < length);
|
||||
}
|
||||
#elif defined(RAPIDJSON_NEON)
|
||||
template<>
|
||||
template <>
|
||||
inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, size_t length) {
|
||||
if (length < 16)
|
||||
return RAPIDJSON_LIKELY(is.Tell() < length);
|
||||
@ -662,7 +712,7 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
|
||||
const uint8x16_t s3 = vmovq_n_u8(32);
|
||||
|
||||
for (; p != endAligned; p += 16) {
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t *>(p));
|
||||
const uint8x16_t s = vld1q_u8(reinterpret_cast<const uint8_t*>(p));
|
||||
uint8x16_t x = vceqq_u8(s, s0);
|
||||
x = vorrq_u8(x, vceqq_u8(s, s1));
|
||||
x = vorrq_u8(x, vceqq_u8(s, s2));
|
||||
@ -680,7 +730,8 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
|
||||
len = 8 + (lz >> 3);
|
||||
escaped = true;
|
||||
}
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
uint32_t lz = internal::clzll(low);
|
||||
len = lz >> 3;
|
||||
escaped = true;
|
||||
@ -693,7 +744,7 @@ inline bool Writer<StringBuffer>::ScanWriteUnescapedString(StringStream& is, siz
|
||||
p += len;
|
||||
break;
|
||||
}
|
||||
vst1q_u8(reinterpret_cast<uint8_t *>(os_->PushUnsafe(16)), s);
|
||||
vst1q_u8(reinterpret_cast<uint8_t*>(os_->PushUnsafe(16)), s);
|
||||
}
|
||||
|
||||
is.src_ = p;
|
||||
|
@ -16,22 +16,15 @@ struct Backoff {
|
||||
double rand01() { return randDistribution(randGenerator); }
|
||||
|
||||
Backoff(int64_t min, int64_t max)
|
||||
: minAmount(min)
|
||||
, maxAmount(max)
|
||||
, current(min)
|
||||
, fails(0)
|
||||
, randGenerator((uint64_t)time(0))
|
||||
{
|
||||
: minAmount(min), maxAmount(max), current(min), fails(0), randGenerator((uint64_t)time(0)) {
|
||||
}
|
||||
|
||||
void reset()
|
||||
{
|
||||
void reset() {
|
||||
fails = 0;
|
||||
current = minAmount;
|
||||
}
|
||||
|
||||
int64_t nextDelay()
|
||||
{
|
||||
int64_t nextDelay() {
|
||||
++fails;
|
||||
int64_t delay = (int64_t)((double)current * 2.0 * rand01());
|
||||
current = std::min(current + delay, maxAmount);
|
||||
|
@ -11,7 +11,7 @@ int GetProcessId();
|
||||
struct BaseConnection {
|
||||
static BaseConnection* Create();
|
||||
static void Destroy(BaseConnection*&);
|
||||
bool isOpen{false};
|
||||
bool isOpen{ false };
|
||||
bool Open();
|
||||
bool Close();
|
||||
bool Write(const void* data, size_t length);
|
||||
|
@ -9,13 +9,12 @@
|
||||
#include <sys/un.h>
|
||||
#include <unistd.h>
|
||||
|
||||
int GetProcessId()
|
||||
{
|
||||
int GetProcessId() {
|
||||
return ::getpid();
|
||||
}
|
||||
|
||||
struct BaseConnectionUnix : public BaseConnection {
|
||||
int sock{-1};
|
||||
int sock{ -1 };
|
||||
};
|
||||
|
||||
static BaseConnectionUnix Connection;
|
||||
@ -26,8 +25,7 @@ static int MsgFlags = MSG_NOSIGNAL;
|
||||
static int MsgFlags = 0;
|
||||
#endif
|
||||
|
||||
static const char* GetTempPath()
|
||||
{
|
||||
static const char* GetTempPath() {
|
||||
const char* temp = getenv("XDG_RUNTIME_DIR");
|
||||
temp = temp ? temp : getenv("TMPDIR");
|
||||
temp = temp ? temp : getenv("TMP");
|
||||
@ -36,21 +34,18 @@ static const char* GetTempPath()
|
||||
return temp;
|
||||
}
|
||||
|
||||
/*static*/ BaseConnection* BaseConnection::Create()
|
||||
{
|
||||
/*static*/ BaseConnection* BaseConnection::Create() {
|
||||
PipeAddr.sun_family = AF_UNIX;
|
||||
return &Connection;
|
||||
}
|
||||
|
||||
/*static*/ void BaseConnection::Destroy(BaseConnection*& c)
|
||||
{
|
||||
/*static*/ void BaseConnection::Destroy(BaseConnection*& c) {
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(c);
|
||||
self->Close();
|
||||
c = nullptr;
|
||||
}
|
||||
|
||||
bool BaseConnection::Open()
|
||||
{
|
||||
bool BaseConnection::Open() {
|
||||
const char* tempPath = GetTempPath();
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||
self->sock = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
@ -76,8 +71,7 @@ bool BaseConnection::Open()
|
||||
return false;
|
||||
}
|
||||
|
||||
bool BaseConnection::Close()
|
||||
{
|
||||
bool BaseConnection::Close() {
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||
if (self->sock == -1) {
|
||||
return false;
|
||||
@ -88,8 +82,7 @@ bool BaseConnection::Close()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseConnection::Write(const void* data, size_t length)
|
||||
{
|
||||
bool BaseConnection::Write(const void* data, size_t length) {
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||
|
||||
if (self->sock == -1) {
|
||||
@ -103,8 +96,7 @@ bool BaseConnection::Write(const void* data, size_t length)
|
||||
return sentBytes == (ssize_t)length;
|
||||
}
|
||||
|
||||
bool BaseConnection::Read(void* data, size_t length)
|
||||
{
|
||||
bool BaseConnection::Read(void* data, size_t length) {
|
||||
auto self = reinterpret_cast<BaseConnectionUnix*>(this);
|
||||
|
||||
if (self->sock == -1) {
|
||||
|
@ -7,32 +7,28 @@
|
||||
#include <assert.h>
|
||||
#include <windows.h>
|
||||
|
||||
int GetProcessId()
|
||||
{
|
||||
int GetProcessId() {
|
||||
return (int)::GetCurrentProcessId();
|
||||
}
|
||||
|
||||
struct BaseConnectionWin : public BaseConnection {
|
||||
HANDLE pipe{INVALID_HANDLE_VALUE};
|
||||
HANDLE pipe{ INVALID_HANDLE_VALUE };
|
||||
};
|
||||
|
||||
static BaseConnectionWin Connection;
|
||||
|
||||
/*static*/ BaseConnection* BaseConnection::Create()
|
||||
{
|
||||
/*static*/ BaseConnection* BaseConnection::Create() {
|
||||
return &Connection;
|
||||
}
|
||||
|
||||
/*static*/ void BaseConnection::Destroy(BaseConnection*& c)
|
||||
{
|
||||
/*static*/ void BaseConnection::Destroy(BaseConnection*& c) {
|
||||
auto self = reinterpret_cast<BaseConnectionWin*>(c);
|
||||
self->Close();
|
||||
c = nullptr;
|
||||
}
|
||||
|
||||
bool BaseConnection::Open()
|
||||
{
|
||||
wchar_t pipeName[]{L"\\\\?\\pipe\\discord-ipc-0"};
|
||||
bool BaseConnection::Open() {
|
||||
wchar_t pipeName[]{ L"\\\\?\\pipe\\discord-ipc-0" };
|
||||
const size_t pipeDigit = sizeof(pipeName) / sizeof(wchar_t) - 2;
|
||||
pipeName[pipeDigit] = L'0';
|
||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||
@ -61,8 +57,7 @@ bool BaseConnection::Open()
|
||||
}
|
||||
}
|
||||
|
||||
bool BaseConnection::Close()
|
||||
{
|
||||
bool BaseConnection::Close() {
|
||||
auto self = reinterpret_cast<BaseConnectionWin*>(this);
|
||||
::CloseHandle(self->pipe);
|
||||
self->pipe = INVALID_HANDLE_VALUE;
|
||||
@ -70,8 +65,7 @@ bool BaseConnection::Close()
|
||||
return true;
|
||||
}
|
||||
|
||||
bool BaseConnection::Write(const void* data, size_t length)
|
||||
{
|
||||
bool BaseConnection::Write(const void* data, size_t length) {
|
||||
if (length == 0) {
|
||||
return true;
|
||||
}
|
||||
@ -93,8 +87,7 @@ bool BaseConnection::Write(const void* data, size_t length)
|
||||
bytesWritten == bytesLength;
|
||||
}
|
||||
|
||||
bool BaseConnection::Read(void* data, size_t length)
|
||||
{
|
||||
bool BaseConnection::Read(void* data, size_t length) {
|
||||
assert(data);
|
||||
if (!data) {
|
||||
return false;
|
||||
|
@ -9,8 +9,7 @@
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
||||
static bool Mkdir(const char* path)
|
||||
{
|
||||
static bool Mkdir(const char* path) {
|
||||
int result = mkdir(path, 0755);
|
||||
if (result == 0) {
|
||||
return true;
|
||||
@ -22,8 +21,7 @@ static bool Mkdir(const char* path)
|
||||
}
|
||||
|
||||
// we want to register games so we can run them from Discord client as discord-<appid>://
|
||||
extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command) {
|
||||
// Add a desktop file and update some mime handlers so that xdg-open does the right thing.
|
||||
|
||||
const char* home = getenv("HOME");
|
||||
@ -94,8 +92,7 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId,
|
||||
const char* steamId)
|
||||
{
|
||||
const char* steamId) {
|
||||
char command[256];
|
||||
sprintf(command, "xdg-open steam://rungameid/%s", steamId);
|
||||
Discord_Register(applicationId, command);
|
||||
|
@ -21,8 +21,7 @@
|
||||
#ifdef __MINGW32__
|
||||
#include <wchar.h>
|
||||
/// strsafe.h fixes
|
||||
static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat, ...)
|
||||
{
|
||||
static HRESULT StringCbPrintfW(LPWSTR pszDest, size_t cbDest, LPCWSTR pszFormat, ...) {
|
||||
HRESULT ret;
|
||||
va_list va;
|
||||
va_start(va, pszFormat);
|
||||
@ -51,8 +50,7 @@ static LSTATUS regset(HKEY hkey,
|
||||
LPCWSTR name,
|
||||
DWORD type,
|
||||
const void* data,
|
||||
DWORD len)
|
||||
{
|
||||
DWORD len) {
|
||||
HKEY htkey = hkey, hsubkey = nullptr;
|
||||
LSTATUS ret;
|
||||
if (subkey && subkey[0]) {
|
||||
@ -67,8 +65,7 @@ static LSTATUS regset(HKEY hkey,
|
||||
return ret;
|
||||
}
|
||||
|
||||
static void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command)
|
||||
{
|
||||
static void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* command) {
|
||||
// https://msdn.microsoft.com/en-us/library/aa767914(v=vs.85).aspx
|
||||
// we want to register games so we can run them as discord-<appid>://
|
||||
// Update the HKEY_CURRENT_USER, because it doesn't seem to require special permissions.
|
||||
@ -131,8 +128,7 @@ static void Discord_RegisterW(const wchar_t* applicationId, const wchar_t* comma
|
||||
RegCloseKey(key);
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const char* command) {
|
||||
wchar_t appId[32];
|
||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||
|
||||
@ -148,8 +144,7 @@ extern "C" DISCORD_EXPORT void Discord_Register(const char* applicationId, const
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_RegisterSteamGame(const char* applicationId,
|
||||
const char* steamId)
|
||||
{
|
||||
const char* steamId) {
|
||||
wchar_t appId[32];
|
||||
MultiByteToWideChar(CP_UTF8, 0, applicationId, -1, appId, 32);
|
||||
|
||||
|
@ -15,16 +15,15 @@
|
||||
#include <thread>
|
||||
#endif
|
||||
|
||||
constexpr size_t MaxMessageSize{16 * 1024};
|
||||
constexpr size_t MessageQueueSize{8};
|
||||
constexpr size_t JoinQueueSize{8};
|
||||
constexpr size_t MaxMessageSize{ 16 * 1024 };
|
||||
constexpr size_t MessageQueueSize{ 8 };
|
||||
constexpr size_t JoinQueueSize{ 8 };
|
||||
|
||||
struct QueuedMessage {
|
||||
size_t length;
|
||||
char buffer[MaxMessageSize];
|
||||
|
||||
void Copy(const QueuedMessage& other)
|
||||
{
|
||||
void Copy(const QueuedMessage& other) {
|
||||
length = other.length;
|
||||
if (length) {
|
||||
memcpy(buffer, other.buffer, length);
|
||||
@ -46,20 +45,20 @@ struct User {
|
||||
// Rounded way up because I'm paranoid about games breaking from future changes in these sizes
|
||||
};
|
||||
|
||||
static RpcConnection* Connection{nullptr};
|
||||
static RpcConnection* Connection{ nullptr };
|
||||
static DiscordEventHandlers QueuedHandlers{};
|
||||
static DiscordEventHandlers Handlers{};
|
||||
static std::atomic_bool WasJustConnected{false};
|
||||
static std::atomic_bool WasJustDisconnected{false};
|
||||
static std::atomic_bool GotErrorMessage{false};
|
||||
static std::atomic_bool WasJoinGame{false};
|
||||
static std::atomic_bool WasSpectateGame{false};
|
||||
static std::atomic_bool UpdatePresence{false};
|
||||
static std::atomic_bool WasJustConnected{ false };
|
||||
static std::atomic_bool WasJustDisconnected{ false };
|
||||
static std::atomic_bool GotErrorMessage{ false };
|
||||
static std::atomic_bool WasJoinGame{ false };
|
||||
static std::atomic_bool WasSpectateGame{ false };
|
||||
static std::atomic_bool UpdatePresence{ false };
|
||||
static char JoinGameSecret[256];
|
||||
static char SpectateGameSecret[256];
|
||||
static int LastErrorCode{0};
|
||||
static int LastErrorCode{ 0 };
|
||||
static char LastErrorMessage[256];
|
||||
static int LastDisconnectErrorCode{0};
|
||||
static int LastDisconnectErrorCode{ 0 };
|
||||
static char LastDisconnectErrorMessage[256];
|
||||
static std::mutex PresenceMutex;
|
||||
static std::mutex HandlerMutex;
|
||||
@ -72,24 +71,23 @@ static User connectedUser;
|
||||
// backoff from 0.5 seconds to 1 minute
|
||||
static Backoff ReconnectTimeMs(500, 60 * 1000);
|
||||
static auto NextConnect = std::chrono::system_clock::now();
|
||||
static int Pid{0};
|
||||
static int Nonce{1};
|
||||
static int Pid{ 0 };
|
||||
static int Nonce{ 1 };
|
||||
|
||||
#ifndef DISCORD_DISABLE_IO_THREAD
|
||||
static void Discord_UpdateConnection(void);
|
||||
class IoThreadHolder {
|
||||
private:
|
||||
std::atomic_bool keepRunning{true};
|
||||
std::atomic_bool keepRunning{ true };
|
||||
std::mutex waitForIOMutex;
|
||||
std::condition_variable waitForIOActivity;
|
||||
std::thread ioThread;
|
||||
|
||||
public:
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
keepRunning.store(true);
|
||||
ioThread = std::thread([&]() {
|
||||
const std::chrono::duration<int64_t, std::milli> maxWait{500LL};
|
||||
const std::chrono::duration<int64_t, std::milli> maxWait{ 500LL };
|
||||
Discord_UpdateConnection();
|
||||
while (keepRunning.load()) {
|
||||
std::unique_lock<std::mutex> lock(waitForIOMutex);
|
||||
@ -101,8 +99,7 @@ public:
|
||||
|
||||
void Notify() { waitForIOActivity.notify_all(); }
|
||||
|
||||
void Stop()
|
||||
{
|
||||
void Stop() {
|
||||
keepRunning.exchange(false);
|
||||
Notify();
|
||||
if (ioThread.joinable()) {
|
||||
@ -120,12 +117,11 @@ public:
|
||||
void Notify() {}
|
||||
};
|
||||
#endif // DISCORD_DISABLE_IO_THREAD
|
||||
static IoThreadHolder* IoThread{nullptr};
|
||||
static IoThreadHolder* IoThread{ nullptr };
|
||||
|
||||
static void UpdateReconnectTime()
|
||||
{
|
||||
static void UpdateReconnectTime() {
|
||||
NextConnect = std::chrono::system_clock::now() +
|
||||
std::chrono::duration<int64_t, std::milli>{ReconnectTimeMs.nextDelay()};
|
||||
std::chrono::duration<int64_t, std::milli>{ ReconnectTimeMs.nextDelay() };
|
||||
}
|
||||
|
||||
#ifdef DISCORD_DISABLE_IO_THREAD
|
||||
@ -237,15 +233,13 @@ static void Discord_UpdateConnection(void)
|
||||
}
|
||||
}
|
||||
|
||||
static void SignalIOActivity()
|
||||
{
|
||||
static void SignalIOActivity() {
|
||||
if (IoThread != nullptr) {
|
||||
IoThread->Notify();
|
||||
}
|
||||
}
|
||||
|
||||
static bool RegisterForEvent(const char* evtName)
|
||||
{
|
||||
static bool RegisterForEvent(const char* evtName) {
|
||||
auto qmessage = SendQueue.GetNextAddMessage();
|
||||
if (qmessage) {
|
||||
qmessage->length =
|
||||
@ -257,8 +251,7 @@ static bool RegisterForEvent(const char* evtName)
|
||||
return false;
|
||||
}
|
||||
|
||||
static bool DeregisterForEvent(const char* evtName)
|
||||
{
|
||||
static bool DeregisterForEvent(const char* evtName) {
|
||||
auto qmessage = SendQueue.GetNextAddMessage();
|
||||
if (qmessage) {
|
||||
qmessage->length =
|
||||
@ -273,8 +266,7 @@ static bool DeregisterForEvent(const char* evtName)
|
||||
extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||
DiscordEventHandlers* handlers,
|
||||
int autoRegister,
|
||||
const char* optionalSteamId)
|
||||
{
|
||||
const char* optionalSteamId) {
|
||||
IoThread = new (std::nothrow) IoThreadHolder();
|
||||
if (IoThread == nullptr) {
|
||||
return;
|
||||
@ -347,8 +339,7 @@ extern "C" DISCORD_EXPORT void Discord_Initialize(const char* applicationId,
|
||||
IoThread->Start();
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_Shutdown(void)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_Shutdown(void) {
|
||||
if (!Connection) {
|
||||
return;
|
||||
}
|
||||
@ -366,8 +357,7 @@ extern "C" DISCORD_EXPORT void Discord_Shutdown(void)
|
||||
RpcConnection::Destroy(Connection);
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence* presence) {
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(PresenceMutex);
|
||||
QueuedPresence.length = JsonWriteRichPresenceObj(
|
||||
@ -377,13 +367,11 @@ extern "C" DISCORD_EXPORT void Discord_UpdatePresence(const DiscordRichPresence*
|
||||
SignalIOActivity();
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_ClearPresence(void)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_ClearPresence(void) {
|
||||
Discord_UpdatePresence(nullptr);
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_Respond(const char* userId, /* DISCORD_REPLY_ */ int reply)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_Respond(const char* userId, /* DISCORD_REPLY_ */ int reply) {
|
||||
// if we are not connected, let's not batch up stale messages for later
|
||||
if (!Connection || !Connection->IsOpen()) {
|
||||
return;
|
||||
@ -397,8 +385,7 @@ extern "C" DISCORD_EXPORT void Discord_Respond(const char* userId, /* DISCORD_RE
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_RunCallbacks(void)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_RunCallbacks(void) {
|
||||
// Note on some weirdness: internally we might connect, get other signals, disconnect any number
|
||||
// of times inbetween calls here. Externally, we want the sequence to seem sane, so any other
|
||||
// signals are book-ended by calls to ready and disconnect.
|
||||
@ -421,10 +408,10 @@ extern "C" DISCORD_EXPORT void Discord_RunCallbacks(void)
|
||||
if (WasJustConnected.exchange(false)) {
|
||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||
if (Handlers.ready) {
|
||||
DiscordUser du{connectedUser.userId,
|
||||
DiscordUser du{ connectedUser.userId,
|
||||
connectedUser.username,
|
||||
connectedUser.discriminator,
|
||||
connectedUser.avatar};
|
||||
connectedUser.avatar };
|
||||
Handlers.ready(&du);
|
||||
}
|
||||
}
|
||||
@ -460,7 +447,7 @@ extern "C" DISCORD_EXPORT void Discord_RunCallbacks(void)
|
||||
{
|
||||
std::lock_guard<std::mutex> guard(HandlerMutex);
|
||||
if (Handlers.joinRequest) {
|
||||
DiscordUser du{req->userId, req->username, req->discriminator, req->avatar};
|
||||
DiscordUser du{ req->userId, req->username, req->discriminator, req->avatar };
|
||||
Handlers.joinRequest(&du);
|
||||
}
|
||||
}
|
||||
@ -476,8 +463,7 @@ extern "C" DISCORD_EXPORT void Discord_RunCallbacks(void)
|
||||
}
|
||||
}
|
||||
|
||||
extern "C" DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* newHandlers)
|
||||
{
|
||||
extern "C" DISCORD_EXPORT void Discord_UpdateHandlers(DiscordEventHandlers* newHandlers) {
|
||||
if (newHandlers) {
|
||||
#define HANDLE_EVENT_REGISTRATION(handler_name, event) \
|
||||
if (!Handlers.handler_name && newHandlers->handler_name) { \
|
||||
|
@ -2,7 +2,6 @@
|
||||
|
||||
// outsmart GCC's missing-declarations warning
|
||||
BOOL WINAPI DllMain(HMODULE, DWORD, LPVOID);
|
||||
BOOL WINAPI DllMain(HMODULE, DWORD, LPVOID)
|
||||
{
|
||||
BOOL WINAPI DllMain(HMODULE, DWORD, LPVOID) {
|
||||
return TRUE;
|
||||
}
|
||||
|
@ -8,15 +8,14 @@
|
||||
template <typename ElementType, size_t QueueSize>
|
||||
class MsgQueue {
|
||||
ElementType queue_[QueueSize];
|
||||
std::atomic_uint nextAdd_{0};
|
||||
std::atomic_uint nextSend_{0};
|
||||
std::atomic_uint pendingSends_{0};
|
||||
std::atomic_uint nextAdd_{ 0 };
|
||||
std::atomic_uint nextSend_{ 0 };
|
||||
std::atomic_uint pendingSends_{ 0 };
|
||||
|
||||
public:
|
||||
MsgQueue() {}
|
||||
|
||||
ElementType* GetNextAddMessage()
|
||||
{
|
||||
ElementType* GetNextAddMessage() {
|
||||
// if we are falling behind, bail
|
||||
if (pendingSends_.load() >= QueueSize) {
|
||||
return nullptr;
|
||||
@ -27,8 +26,7 @@ public:
|
||||
void CommitAdd() { ++pendingSends_; }
|
||||
|
||||
bool HavePendingSends() const { return pendingSends_.load() != 0; }
|
||||
ElementType* GetNextSendMessage()
|
||||
{
|
||||
ElementType* GetNextSendMessage() {
|
||||
auto index = (nextSend_++) % QueueSize;
|
||||
return &queue_[index];
|
||||
}
|
||||
|
@ -6,22 +6,19 @@
|
||||
static const int RpcVersion = 1;
|
||||
static RpcConnection Instance;
|
||||
|
||||
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId)
|
||||
{
|
||||
/*static*/ RpcConnection* RpcConnection::Create(const char* applicationId) {
|
||||
Instance.connection = BaseConnection::Create();
|
||||
StringCopy(Instance.appId, applicationId);
|
||||
return &Instance;
|
||||
}
|
||||
|
||||
/*static*/ void RpcConnection::Destroy(RpcConnection*& c)
|
||||
{
|
||||
/*static*/ void RpcConnection::Destroy(RpcConnection*& c) {
|
||||
c->Close();
|
||||
BaseConnection::Destroy(c->connection);
|
||||
c = nullptr;
|
||||
}
|
||||
|
||||
void RpcConnection::Open()
|
||||
{
|
||||
void RpcConnection::Open() {
|
||||
if (state == State::Connected) {
|
||||
return;
|
||||
}
|
||||
@ -57,8 +54,7 @@ void RpcConnection::Open()
|
||||
}
|
||||
}
|
||||
|
||||
void RpcConnection::Close()
|
||||
{
|
||||
void RpcConnection::Close() {
|
||||
if (onDisconnect && (state == State::Connected || state == State::SentHandshake)) {
|
||||
onDisconnect(lastErrorCode, lastErrorMessage);
|
||||
}
|
||||
@ -66,8 +62,7 @@ void RpcConnection::Close()
|
||||
state = State::Disconnected;
|
||||
}
|
||||
|
||||
bool RpcConnection::Write(const void* data, size_t length)
|
||||
{
|
||||
bool RpcConnection::Write(const void* data, size_t length) {
|
||||
sendFrame.opcode = Opcode::Frame;
|
||||
memcpy(sendFrame.message, data, length);
|
||||
sendFrame.length = (uint32_t)length;
|
||||
@ -78,8 +73,7 @@ bool RpcConnection::Write(const void* data, size_t length)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RpcConnection::Read(JsonDocument& message)
|
||||
{
|
||||
bool RpcConnection::Read(JsonDocument& message) {
|
||||
if (state != State::Connected && state != State::SentHandshake) {
|
||||
return false;
|
||||
}
|
||||
|
@ -38,12 +38,12 @@ struct RpcConnection {
|
||||
Connected,
|
||||
};
|
||||
|
||||
BaseConnection* connection{nullptr};
|
||||
State state{State::Disconnected};
|
||||
void (*onConnect)(JsonDocument& message){nullptr};
|
||||
void (*onDisconnect)(int errorCode, const char* message){nullptr};
|
||||
BaseConnection* connection{ nullptr };
|
||||
State state{ State::Disconnected };
|
||||
void (*onConnect)(JsonDocument& message){ nullptr };
|
||||
void (*onDisconnect)(int errorCode, const char* message){ nullptr };
|
||||
char appId[64]{};
|
||||
int lastErrorCode{0};
|
||||
int lastErrorCode{ 0 };
|
||||
char lastErrorMessage[256]{};
|
||||
RpcConnection::MessageFrame sendFrame;
|
||||
|
||||
|
@ -3,8 +3,7 @@
|
||||
#include "discord_rpc.h"
|
||||
|
||||
template <typename T>
|
||||
void NumberToString(char* dest, T number)
|
||||
{
|
||||
void NumberToString(char* dest, T number) {
|
||||
if (!number) {
|
||||
*dest++ = '0';
|
||||
*dest++ = 0;
|
||||
@ -29,22 +28,19 @@ void NumberToString(char* dest, T number)
|
||||
|
||||
// it's ever so slightly faster to not have to strlen the key
|
||||
template <typename T>
|
||||
void WriteKey(JsonWriter& w, T& k)
|
||||
{
|
||||
void WriteKey(JsonWriter& w, T& k) {
|
||||
w.Key(k, sizeof(T) - 1);
|
||||
}
|
||||
|
||||
struct WriteObject {
|
||||
JsonWriter& writer;
|
||||
WriteObject(JsonWriter& w)
|
||||
: writer(w)
|
||||
{
|
||||
: writer(w) {
|
||||
writer.StartObject();
|
||||
}
|
||||
template <typename T>
|
||||
WriteObject(JsonWriter& w, T& name)
|
||||
: writer(w)
|
||||
{
|
||||
: writer(w) {
|
||||
WriteKey(writer, name);
|
||||
writer.StartObject();
|
||||
}
|
||||
@ -55,8 +51,7 @@ struct WriteArray {
|
||||
JsonWriter& writer;
|
||||
template <typename T>
|
||||
WriteArray(JsonWriter& w, T& name)
|
||||
: writer(w)
|
||||
{
|
||||
: writer(w) {
|
||||
WriteKey(writer, name);
|
||||
writer.StartArray();
|
||||
}
|
||||
@ -64,16 +59,14 @@ struct WriteArray {
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
void WriteOptionalString(JsonWriter& w, T& k, const char* value)
|
||||
{
|
||||
void WriteOptionalString(JsonWriter& w, T& k, const char* value) {
|
||||
if (value && value[0]) {
|
||||
w.Key(k, sizeof(T) - 1);
|
||||
w.String(value);
|
||||
}
|
||||
}
|
||||
|
||||
static void JsonWriteNonce(JsonWriter& writer, int nonce)
|
||||
{
|
||||
static void JsonWriteNonce(JsonWriter& writer, int nonce) {
|
||||
WriteKey(writer, "nonce");
|
||||
char nonceBuffer[32];
|
||||
NumberToString(nonceBuffer, nonce);
|
||||
@ -84,8 +77,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
|
||||
size_t maxLen,
|
||||
int nonce,
|
||||
int pid,
|
||||
const DiscordRichPresence* presence)
|
||||
{
|
||||
const DiscordRichPresence* presence) {
|
||||
JsonWriter writer(dest, maxLen);
|
||||
|
||||
{
|
||||
@ -167,8 +159,7 @@ size_t JsonWriteRichPresenceObj(char* dest,
|
||||
return writer.Size();
|
||||
}
|
||||
|
||||
size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char* applicationId)
|
||||
{
|
||||
size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char* applicationId) {
|
||||
JsonWriter writer(dest, maxLen);
|
||||
|
||||
{
|
||||
@ -182,8 +173,7 @@ size_t JsonWriteHandshakeObj(char* dest, size_t maxLen, int version, const char*
|
||||
return writer.Size();
|
||||
}
|
||||
|
||||
size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName)
|
||||
{
|
||||
size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName) {
|
||||
JsonWriter writer(dest, maxLen);
|
||||
|
||||
{
|
||||
@ -201,8 +191,7 @@ size_t JsonWriteSubscribeCommand(char* dest, size_t maxLen, int nonce, const cha
|
||||
return writer.Size();
|
||||
}
|
||||
|
||||
size_t JsonWriteUnsubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName)
|
||||
{
|
||||
size_t JsonWriteUnsubscribeCommand(char* dest, size_t maxLen, int nonce, const char* evtName) {
|
||||
JsonWriter writer(dest, maxLen);
|
||||
|
||||
{
|
||||
@ -220,8 +209,7 @@ size_t JsonWriteUnsubscribeCommand(char* dest, size_t maxLen, int nonce, const c
|
||||
return writer.Size();
|
||||
}
|
||||
|
||||
size_t JsonWriteJoinReply(char* dest, size_t maxLen, const char* userId, int reply, int nonce)
|
||||
{
|
||||
size_t JsonWriteJoinReply(char* dest, size_t maxLen, const char* userId, int reply, int nonce) {
|
||||
JsonWriter writer(dest, maxLen);
|
||||
|
||||
{
|
||||
|
@ -22,8 +22,7 @@
|
||||
|
||||
// if only there was a standard library function for this
|
||||
template <size_t Len>
|
||||
inline size_t StringCopy(char (&dest)[Len], const char* src)
|
||||
{
|
||||
inline size_t StringCopy(char (&dest)[Len], const char* src) {
|
||||
if (!src || !Len) {
|
||||
return 0;
|
||||
}
|
||||
@ -58,18 +57,14 @@ class LinearAllocator {
|
||||
public:
|
||||
char* buffer_;
|
||||
char* end_;
|
||||
LinearAllocator()
|
||||
{
|
||||
LinearAllocator() {
|
||||
assert(0); // needed for some default case in rapidjson, should not use
|
||||
}
|
||||
LinearAllocator(char* buffer, size_t size)
|
||||
: buffer_(buffer)
|
||||
, end_(buffer + size)
|
||||
{
|
||||
: buffer_(buffer), end_(buffer + size) {
|
||||
}
|
||||
static const bool kNeedFree = false;
|
||||
void* Malloc(size_t size)
|
||||
{
|
||||
void* Malloc(size_t size) {
|
||||
char* res = buffer_;
|
||||
buffer_ += size;
|
||||
if (buffer_ > end_) {
|
||||
@ -78,8 +73,7 @@ public:
|
||||
}
|
||||
return res;
|
||||
}
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize)
|
||||
{
|
||||
void* Realloc(void* originalPtr, size_t originalSize, size_t newSize) {
|
||||
if (newSize == 0) {
|
||||
return nullptr;
|
||||
}
|
||||
@ -90,8 +84,7 @@ public:
|
||||
(void)(originalSize);
|
||||
return Malloc(newSize);
|
||||
}
|
||||
static void Free(void* ptr)
|
||||
{
|
||||
static void Free(void* ptr) {
|
||||
/* shrug */
|
||||
(void)ptr;
|
||||
}
|
||||
@ -102,8 +95,7 @@ class FixedLinearAllocator : public LinearAllocator {
|
||||
public:
|
||||
char fixedBuffer_[Size];
|
||||
FixedLinearAllocator()
|
||||
: LinearAllocator(fixedBuffer_, Size)
|
||||
{
|
||||
: LinearAllocator(fixedBuffer_, Size) {
|
||||
}
|
||||
static const bool kNeedFree = false;
|
||||
};
|
||||
@ -117,14 +109,10 @@ public:
|
||||
char* current_;
|
||||
|
||||
DirectStringBuffer(char* buffer, size_t maxLen)
|
||||
: buffer_(buffer)
|
||||
, end_(buffer + maxLen)
|
||||
, current_(buffer)
|
||||
{
|
||||
: buffer_(buffer), end_(buffer + maxLen), current_(buffer) {
|
||||
}
|
||||
|
||||
void Put(char c)
|
||||
{
|
||||
void Put(char c) {
|
||||
if (current_ < end_) {
|
||||
*current_++ = c;
|
||||
}
|
||||
@ -147,10 +135,7 @@ public:
|
||||
StackAllocator stackAlloc_;
|
||||
|
||||
JsonWriter(char* dest, size_t maxLen)
|
||||
: JsonWriterBase(stringBuffer_, &stackAlloc_, WriterNestingLevels)
|
||||
, stringBuffer_(dest, maxLen)
|
||||
, stackAlloc_()
|
||||
{
|
||||
: JsonWriterBase(stringBuffer_, &stackAlloc_, WriterNestingLevels), stringBuffer_(dest, maxLen), stackAlloc_() {
|
||||
}
|
||||
|
||||
size_t Size() const { return stringBuffer_.GetSize(); }
|
||||
@ -170,17 +155,14 @@ public:
|
||||
: JsonDocumentBase(rapidjson::kObjectType,
|
||||
&poolAllocator_,
|
||||
sizeof(stackAllocator_.fixedBuffer_),
|
||||
&stackAllocator_)
|
||||
, poolAllocator_(parseBuffer_, sizeof(parseBuffer_), kDefaultChunkCapacity, &mallocAllocator_)
|
||||
, stackAllocator_()
|
||||
{
|
||||
&stackAllocator_),
|
||||
poolAllocator_(parseBuffer_, sizeof(parseBuffer_), kDefaultChunkCapacity, &mallocAllocator_), stackAllocator_() {
|
||||
}
|
||||
};
|
||||
|
||||
using JsonValue = rapidjson::GenericValue<UTF8, PoolAllocator>;
|
||||
|
||||
inline JsonValue* GetObjMember(JsonValue* obj, const char* name)
|
||||
{
|
||||
inline JsonValue* GetObjMember(JsonValue* obj, const char* name) {
|
||||
if (obj) {
|
||||
auto member = obj->FindMember(name);
|
||||
if (member != obj->MemberEnd() && member->value.IsObject()) {
|
||||
@ -190,8 +172,7 @@ inline JsonValue* GetObjMember(JsonValue* obj, const char* name)
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
inline int GetIntMember(JsonValue* obj, const char* name, int notFoundDefault = 0)
|
||||
{
|
||||
inline int GetIntMember(JsonValue* obj, const char* name, int notFoundDefault = 0) {
|
||||
if (obj) {
|
||||
auto member = obj->FindMember(name);
|
||||
if (member != obj->MemberEnd() && member->value.IsInt()) {
|
||||
@ -203,8 +184,7 @@ inline int GetIntMember(JsonValue* obj, const char* name, int notFoundDefault =
|
||||
|
||||
inline const char* GetStrMember(JsonValue* obj,
|
||||
const char* name,
|
||||
const char* notFoundDefault = nullptr)
|
||||
{
|
||||
const char* notFoundDefault = nullptr) {
|
||||
if (obj) {
|
||||
auto member = obj->FindMember(name);
|
||||
if (member != obj->MemberEnd() && member->value.IsString()) {
|
||||
|
Loading…
Reference in New Issue
Block a user