15 #ifndef RAPIDJSON_POINTER_H_ 16 #define RAPIDJSON_POINTER_H_ 23 RAPIDJSON_DIAG_OFF(
switch-
enum)
24 #elif defined(_MSC_VER) 26 RAPIDJSON_DIAG_OFF(4512)
78 template <
typename ValueType,
typename Allocator = CrtAllocator>
118 #if RAPIDJSON_HAS_STDSTRING 217 Ch *
p =
r.CopyFromRaw(*
this, 1, token.
length + 1);
243 template <
typename T>
249 #if RAPIDJSON_HAS_STDSTRING 273 if (
sizeof(
Ch) == 1) {
274 Token token = {
reinterpret_cast<Ch*
>(
buffer), length, index };
279 for (
size_t i = 0;
i <= length;
i++)
281 Token token = {
name, length, index };
293 if (token.IsString())
317 Allocator& GetAllocator() {
return *
allocator_; }
326 size_t GetTokenCount()
const {
return tokenCount_; }
369 template<
typename OutputStream>
371 return Stringify<false, OutputStream>(os);
379 template<
typename OutputStream>
380 bool StringifyUriFragment(OutputStream& os)
const {
381 return Stringify<true, OutputStream>(os);
404 ValueType& Create(ValueType& root,
typename ValueType::AllocatorType&
allocator,
bool* alreadyExist = 0)
const {
406 ValueType* v = &root;
409 if (v->IsArray() &&
t->name[0] ==
'-' &&
t->length == 1) {
410 v->PushBack(ValueType().Move(),
allocator);
411 v = &((*v)[v->Size() - 1]);
420 if (!v->IsArray() && !v->IsObject())
425 if (
t->index >= v->Size()) {
427 while (
t->index >= v->Size())
428 v->PushBack(ValueType().Move(),
allocator);
431 v = &((*v)[
t->index]);
435 if (m == v->MemberEnd()) {
437 v = &(--v->MemberEnd())->
value;
447 *alreadyExist = exist;
458 template <
typename stackAllocator>
482 ValueType* Get(ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
484 ValueType* v = &root;
486 switch (v->GetType()) {
490 if (m == v->MemberEnd())
498 v = &((*v)[
t->index]);
505 if (unresolvedTokenIndex)
506 *unresolvedTokenIndex =
static_cast<size_t>(
t -
tokens_);
517 const ValueType* Get(
const ValueType& root,
size_t* unresolvedTokenIndex = 0)
const {
518 return Get(const_cast<ValueType&>(root), unresolvedTokenIndex);
536 ValueType& GetWithDefault(ValueType& root,
const ValueType&
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
538 ValueType& v = Create(root,
allocator, &alreadyExist);
543 ValueType& GetWithDefault(ValueType& root,
const Ch*
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
545 ValueType& v = Create(root,
allocator, &alreadyExist);
549 #if RAPIDJSON_HAS_STDSTRING 550 ValueType& GetWithDefault(ValueType& root,
const std::basic_string<Ch>&
defaultValue,
typename ValueType::AllocatorType&
allocator)
const {
553 ValueType& v = Create(root,
allocator, &alreadyExist);
562 template <
typename T>
569 template <
typename stackAllocator>
575 template <
typename stackAllocator>
580 #if RAPIDJSON_HAS_STDSTRING 581 template <
typename stackAllocator>
592 template <
typename T,
typename stackAllocator>
613 ValueType&
Set(ValueType& root, ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
618 ValueType&
Set(ValueType& root,
const ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
627 #if RAPIDJSON_HAS_STDSTRING 628 ValueType&
Set(ValueType& root,
const std::basic_string<Ch>&
value,
typename ValueType::AllocatorType&
allocator)
const {
638 template <
typename T>
645 template <
typename stackAllocator>
651 template <
typename stackAllocator>
657 template <
typename stackAllocator>
662 #if RAPIDJSON_HAS_STDSTRING 663 template <
typename stackAllocator>
674 template <
typename T,
typename stackAllocator>
695 ValueType&
Swap(ValueType& root, ValueType&
value,
typename ValueType::AllocatorType&
allocator)
const {
700 template <
typename stackAllocator>
719 ValueType* v = &root;
722 switch (v->GetType()) {
726 if (m == v->MemberEnd())
734 v = &((*v)[
t->index]);
741 switch (v->GetType()) {
747 v->Erase(v->Begin() + last->
index);
768 nameBufferSize +=
t->length;
776 if (nameBufferSize > 0) {
794 return !((
c >=
'0' && c <= '9') || (c >=
'A' && c <='Z') || (c >=
'a' &&
c <=
'z') ||
c ==
'-' ||
c ==
'.' ||
c ==
'_' ||
c ==
'~');
798 #ifndef __clang__ // -Wdocumentation 825 bool uriFragment =
false;
831 if (
i != length &&
source[
i] !=
'/') {
841 bool isNumber =
true;
843 while (
i < length &&
source[
i] !=
'/') {
855 size_t len = os.
PutEnd(begin);
878 if (
c ==
'0')
c =
'~';
879 else if (
c ==
'1')
c =
'/';
893 if (c < '0' || c >
'9')
904 if (isNumber && token->
length > 1 && token->
name[0] ==
'0')
910 for (
size_t j = 0; j < token->
length; j++) {
943 template<
bool uriFragment,
typename OutputStream>
952 for (
size_t j = 0; j <
t->length; j++) {
1001 for (
int j = 0; j < 2; j++) {
1002 c =
static_cast<Ch>(
c << 4);
1004 if (
h >=
'0' &&
h <=
'9')
c =
static_cast<Ch>(
c +
h -
'0');
1005 else if (
h >=
'A' &&
h <=
'F')
c =
static_cast<Ch>(
c +
h -
'A' + 10);
1006 else if (
h >=
'a' &&
h <=
'f')
c =
static_cast<Ch>(
c +
h -
'a' + 10);
1027 template <
typename OutputStream>
1032 unsigned char u =
static_cast<unsigned char>(
c);
1033 static const char hexDigits[16] = {
'0',
'1',
'2',
'3',
'4',
'5',
'6',
'7',
'8',
'9',
'A',
'B',
'C',
'D',
'E',
'F' };
1035 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[
u >> 4]));
1036 os_.Put(static_cast<typename OutputStream::Ch>(hexDigits[
u & 15]));
1059 template <
typename T>
1064 template <
typename T,
typename CharType,
size_t N>
1071 template <
typename DocumentType>
1073 return pointer.Create(document);
1076 template <
typename DocumentType,
typename CharType,
size_t N>
1083 template <
typename T>
1085 return pointer.Get(root, unresolvedTokenIndex);
1088 template <
typename T>
1090 return pointer.Get(root, unresolvedTokenIndex);
1093 template <
typename T,
typename CharType,
size_t N>
1098 template <
typename T,
typename CharType,
size_t N>
1105 template <
typename T>
1110 template <
typename T>
1115 #if RAPIDJSON_HAS_STDSTRING 1116 template <
typename T>
1122 template <
typename T,
typename T2>
1128 template <
typename T,
typename CharType,
size_t N>
1133 template <
typename T,
typename CharType,
size_t N>
1138 #if RAPIDJSON_HAS_STDSTRING 1139 template <
typename T,
typename CharType,
size_t N>
1145 template <
typename T,
typename CharType,
size_t N,
typename T2>
1153 template <
typename DocumentType>
1158 template <
typename DocumentType>
1163 #if RAPIDJSON_HAS_STDSTRING 1164 template <
typename DocumentType>
1170 template <
typename DocumentType,
typename T2>
1176 template <
typename DocumentType,
typename CharType,
size_t N>
1181 template <
typename DocumentType,
typename CharType,
size_t N>
1186 #if RAPIDJSON_HAS_STDSTRING 1187 template <
typename DocumentType,
typename CharType,
size_t N>
1193 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1201 template <
typename T>
1206 template <
typename T>
1211 template <
typename T>
1216 #if RAPIDJSON_HAS_STDSTRING 1217 template <
typename T>
1223 template <
typename T,
typename T2>
1229 template <
typename T,
typename CharType,
size_t N>
1234 template <
typename T,
typename CharType,
size_t N>
1239 template <
typename T,
typename CharType,
size_t N>
1244 #if RAPIDJSON_HAS_STDSTRING 1245 template <
typename T,
typename CharType,
size_t N>
1246 typename T::ValueType&
SetValueByPointer(
T& root,
const CharType(&
source)[N],
const std::basic_string<typename T::Ch>&
value,
typename T::AllocatorType&
a) {
1251 template <
typename T,
typename CharType,
size_t N,
typename T2>
1259 template <
typename DocumentType>
1264 template <
typename DocumentType>
1269 template <
typename DocumentType>
1274 #if RAPIDJSON_HAS_STDSTRING 1275 template <
typename DocumentType>
1281 template <
typename DocumentType,
typename T2>
1287 template <
typename DocumentType,
typename CharType,
size_t N>
1292 template <
typename DocumentType,
typename CharType,
size_t N>
1297 template <
typename DocumentType,
typename CharType,
size_t N>
1302 #if RAPIDJSON_HAS_STDSTRING 1303 template <
typename DocumentType,
typename CharType,
size_t N>
1304 typename DocumentType::ValueType&
SetValueByPointer(DocumentType& document,
const CharType(&
source)[N],
const std::basic_string<typename DocumentType::Ch>&
value) {
1309 template <
typename DocumentType,
typename CharType,
size_t N,
typename T2>
1317 template <
typename T>
1322 template <
typename T,
typename CharType,
size_t N>
1327 template <
typename DocumentType>
1332 template <
typename DocumentType,
typename CharType,
size_t N>
1339 template <
typename T>
1344 template <
typename T,
typename CharType,
size_t N>
1353 #if defined(__clang__) || defined(_MSC_VER) 1357 #endif // RAPIDJSON_POINTER_H_ GenericPointer(const Token *tokens, size_t tokenCount)
Constructor with user-supplied tokens.
Definition: pointer.h:163
T::ValueType & GetValueByPointerWithDefault(T &root, const GenericPointer< typename T::ValueType > &pointer, const typename T::ValueType &defaultValue, typename T::AllocatorType &a)
Definition: pointer.h:1106
bool IsValid() const
Definition: pointer.h:1017
char * u64toa(uint64_t value, char *buffer)
Definition: itoa.h:126
Invalid escape.
Definition: pointer.h:41
const uint32_t T[512]
Definition: groestl_tables.h:36
Encoding conversion.
Definition: encodings.h:658
const CharType(& source)[N]
Definition: pointer.h:1147
bool Stringify(OutputStream &os) const
Stringify to string or URI fragment representation.
Definition: pointer.h:944
RAPIDJSON_NAMESPACE_BEGIN typedef unsigned SizeType
Size type (for string lengths, array sizes, etc.)
Definition: rapidjson.h:389
#define RAPIDJSON_ASSERT(x)
Assertion.
Definition: rapidjson.h:411
void Parse(const Ch *source, size_t length)
Parse a JSON String or its URI fragment representation into tokens.
Definition: pointer.h:805
bool operator!=(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:113
int i
Definition: pymoduletest.py:23
object
Definition: rapidjson.h:627
Ch * CopyFromRaw(const GenericPointer &rhs, size_t extraToken=0, size_t extraNameBufferSize=0)
Clone the content from rhs to this.
Definition: pointer.h:762
u
Definition: pymoduletest.py:20
Read-only string stream.
Definition: fwd.h:47
Ch * nameBuffer_
A buffer containing all names in tokens.
Definition: pointer.h:1044
#define RAPIDJSON_NAMESPACE_END
provide custom rapidjson namespace (closing expression)
Definition: rapidjson.h:124
bool operator==(const ipv4_network_address &lhs, const ipv4_network_address &rhs) noexcept
Definition: net_utils_base.h:111
array
Definition: rapidjson.h:628
#define Ch(x, y, z)
Definition: sha512-blocks.c:34
t
Definition: console.py:33
ValueType::EncodingType EncodingType
Encoding type from Value.
Definition: pointer.h:81
Invalid percent encoding in URI fragment.
Definition: pointer.h:42
GenericPointer Append(const Token &token, Allocator *allocator=0) const
Append a token and return a new Pointer.
Definition: pointer.h:214
GenericPointer(const Ch *source, size_t length, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation, with length of the source string...
Definition: pointer.h:137
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const Ch *value) const
Set a null-terminated string in a document.
Definition: pointer.h:658
PointerParseErrorCode parseErrorCode_
Parsing error code.
Definition: pointer.h:1048
const Ch * head_
Original head of the string.
Definition: pointer.h:1021
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Set a value in a document, with move semantics.
Definition: pointer.h:646
const char * s
Definition: minissdp.c:596
PercentDecodeStream(const Ch *source, const Ch *end)
Constructor.
Definition: pointer.h:992
GenericPointer(const GenericPointer &rhs)
Copy constructor.
Definition: pointer.h:166
Token * tokens_
A list of tokens.
Definition: pointer.h:1045
static RAPIDJSON_NAMESPACE_BEGIN const SizeType kPointerInvalidIndex
Represents an invalid index in GenericPointer::Token.
Definition: pointer.h:31
A helper stream for decoding a percent-encoded sequence into code unit.
Definition: pointer.h:983
size_t Tell() const
Definition: pointer.h:1016
SizeType index
A valid array index, if it is not equal to kPointerInvalidIndex.
Definition: pointer.h:100
T::ValueType & SwapValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
Definition: pointer.h:1318
#define RAPIDJSON_NAMESPACE_BEGIN
provide custom rapidjson namespace (opening expression)
Definition: rapidjson.h:121
ValueType & Set(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with move semantics.
Definition: pointer.h:613
A token is the basic units of internal representation.
Definition: pointer.h:97
A document for parsing JSON text as DOM.
Definition: document.h:60
A token must begin with a '/'.
Definition: pointer.h:40
A read-write string stream.
Definition: fwd.h:52
ValueType & Set(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, const ValueType &value) const
Set a value in a document, with copy semantics.
Definition: pointer.h:652
SizeType length
Length of the name.
Definition: pointer.h:99
ValueType::Ch Ch
Definition: pointer.h:985
bool valid_
Whether the parsing is valid.
Definition: pointer.h:1023
GenericPointer(const Ch *source, Allocator *allocator=0)
Constructor that parses a string or URI fragment representation.
Definition: pointer.h:114
size_t parseErrorOffset_
Offset in code unit when parsing fail.
Definition: pointer.h:1047
UTF-8 encoding.
Definition: encodings.h:96
#define RAPIDJSON_NEW(TypeName)
! customization point for global new
Definition: rapidjson.h:606
ValueType & Swap(GenericDocument< EncodingType, typename ValueType::AllocatorType, stackAllocator > &document, ValueType &value) const
Swap a value with a value in a document.
Definition: pointer.h:701
Allocator stackAllocator stackAllocator & document
Definition: pointer.h:594
Represents a JSON Pointer. Use Pointer for UTF8 encoding and default allocator.
Definition: fwd.h:126
const T buffer
Definition: byte_slice.cpp:83
GenericPointer & operator=(const GenericPointer &rhs)
Assignment operator.
Definition: pointer.h:183
const Ch * end_
Past-the-end position.
Definition: pointer.h:1022
A helper stream to encode character (UTF-8 code unit) into percent-encoded sequence.
Definition: pointer.h:1028
GenericPointer< Value > Pointer
GenericPointer for Value (UTF-8, default allocator).
Definition: pointer.h:1052
GenericPointer Append(const Ch *name, SizeType length, Allocator *allocator=0) const
Append a name token with length, and return a new Pointer.
Definition: pointer.h:232
PercentEncodeStream(OutputStream &os)
Definition: pointer.h:1030
RAPIDJSON_DISABLEIF_RETURN((internal::NotExpr< internal::IsSame< typename internal::RemoveConst< T >::Type, Ch > >),(GenericPointer)) Append(T *name
Append a name token without length, and return a new Pointer.
size_t tokenCount_
Number of tokens in tokens_.
Definition: pointer.h:1046
void Swap(T &a, T &b) RAPIDJSON_NOEXCEPT
Custom swap() to avoid dependency on C++ <algorithm> header.
Definition: swap.h:33
#define RAPIDJSON_DELETE(x)
! customization point for global delete
Definition: rapidjson.h:610
char * u32toa(uint32_t value, char *buffer)
Definition: itoa.h:39
T::ValueType & CreateValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::AllocatorType &a)
Definition: pointer.h:1060
T value
Definition: pointer.h:640
GenericPointer(const GenericPointer &rhs, Allocator *allocator)
Copy constructor.
Definition: pointer.h:171
Allocator * allocator
Definition: pointer.h:245
diff
Definition: gen_wide_data.py:42
const GenericPointer< typename T::ValueType > T2 T::AllocatorType & a
Definition: pointer.h:1124
r
Definition: testupnpigd.py:61
ValueType::Ch Ch
Character type from Value.
Definition: pointer.h:82
const Ch * name
Name of the token. It has null character at the end but it can contain null character.
Definition: pointer.h:98
bool Erase(ValueType &root) const
Erase a value in a subtree.
Definition: pointer.h:714
PointerParseErrorCode
Error code of parsing.
Definition: pointer.h:37
OutputStream & os_
Definition: pointer.h:1039
ValueType & Set(ValueType &root, const Ch *value, typename ValueType::AllocatorType &allocator) const
Set a null-terminated string in a subtree.
Definition: pointer.h:623
const GenericPointer< typename T::ValueType > T2 value
Definition: pointer.h:1225
void * memcpy(void *a, const void *b, size_t c)
Definition: glibc_compat.cpp:16
def GetTokens(source)
Definition: tokenize.py:119
bool EraseValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer)
Definition: pointer.h:1340
void Put(char c)
Definition: pointer.h:1031
Ch Take()
Definition: pointer.h:994
bool NeedPercentEncode(Ch c) const
Check whether a character should be percent-encoded.
Definition: pointer.h:793
p
Definition: pymoduletest.py:75
const GenericPointer< typename T::ValueType > T2 defaultValue
Definition: pointer.h:1124
SizeType StrLen(const Ch *s)
Custom strlen() which works on different character types.
Definition: strfunc.h:31
Reference to a constant string (not taking a copy)
Definition: document.h:253
Definition: document.h:416
ValueType & Swap(ValueType &root, ValueType &value, typename ValueType::AllocatorType &allocator) const
Swap a value with a value in a subtree.
Definition: pointer.h:695
The parse is successful.
Definition: pointer.h:38
ValueType & Set(ValueType &root, const ValueType &value, typename ValueType::AllocatorType &allocator) const
Set a value in a subtree, with copy semantics.
Definition: pointer.h:618
size_t PutEnd(Ch *begin)
Definition: stream.h:202
Allocator * allocator_
The current allocator. It is either user-supplied or equal to ownAllocator_.
Definition: pointer.h:1042
const GenericPointer< typename T::ValueType > & pointer
Definition: pointer.h:1124
const char * name
Definition: options.c:30
Type
Type of JSON value.
Definition: rapidjson.h:623
A character must percent encoded in URI fragment.
Definition: pointer.h:43
Allocator * ownAllocator_
Allocator owned by this Pointer.
Definition: pointer.h:1043
error
Tracks LMDB error codes.
Definition: error.h:44
#define const
Definition: ipfrdr.c:80
T::ValueType & SetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, typename T::ValueType &value, typename T::AllocatorType &a)
Definition: pointer.h:1202
GenericPointer(Allocator *allocator=0)
Default constructor.
Definition: pointer.h:107
RAPIDJSON_DISABLEIF_RETURN((internal::OrExpr< internal::IsPointer< T2 >, internal::IsGenericValue< T2 > >),(typename T::ValueType &)) GetValueByPointerWithDefault(T &root
static uint64_t h
Definition: blockchain_stats.cpp:55
#define true
Definition: stdbool.h:36
const Ch * src_
Current read position.
Definition: pointer.h:1020
T::ValueType * GetValueByPointer(T &root, const GenericPointer< typename T::ValueType > &pointer, size_t *unresolvedTokenIndex=0)
Definition: pointer.h:1084
c
Definition: pymoduletest.py:79
Ch * PutBegin()
Definition: stream.h:201
~GenericPointer()
Destructor.
Definition: pointer.h:176