88 #ifndef LIB_JSONCPP_JSON_TOOL_H_INCLUDED 89 # define LIB_JSONCPP_JSON_TOOL_H_INCLUDED 100 static inline std::string
110 result[0] =
static_cast<char>(cp);
112 else if (cp <= 0x7FF)
115 result[1] =
static_cast<char>(0x80 | (0x3f & cp));
116 result[0] =
static_cast<char>(0xC0 | (0x1f & (cp >> 6)));
118 else if (cp <= 0xFFFF)
121 result[2] =
static_cast<char>(0x80 | (0x3f & cp));
122 result[1] = 0x80 |
static_cast<char>((0x3f & (cp >> 6)));
123 result[0] = 0xE0 |
static_cast<char>((0xf & (cp >> 12)));
125 else if (cp <= 0x10FFFF)
128 result[3] =
static_cast<char>(0x80 | (0x3f & cp));
129 result[2] =
static_cast<char>(0x80 | (0x3f & (cp >> 6)));
130 result[1] =
static_cast<char>(0x80 | (0x3f & (cp >> 12)));
131 result[0] =
static_cast<char>(0xF0 | (0x7 & (cp >> 18)));
142 return ch > 0 && ch <= 0x1F;
167 *--current = char(value % 10) +
'0';
170 while ( value != 0 );
175 #endif // LIB_JSONCPP_JSON_TOOL_H_INCLUDED 195 #if !defined(JSON_IS_AMALGAMATION) 196 # include <json/reader.h> 197 # include <json/value.h> 198 # include "json_tool.h" 199 #endif // if !defined(JSON_IS_AMALGAMATION) 207 #if _MSC_VER >= 1400 // VC++ 8.0 208 #pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. 217 : allowComments_( true )
218 , strictRoot_( false )
246 return c == c1 || c == c2 || c == c3 || c == c4;
252 return c == c1 || c == c2 || c == c3 || c == c4 || c == c5;
260 for ( ;begin < end; ++begin )
261 if ( *begin ==
'\n' || *begin ==
'\r' )
285 bool collectComments )
289 const char *end = begin +
document_.length();
290 return parse( begin, end, root, collectComments );
297 bool collectComments )
307 std::getline(sin, doc, (
char)EOF);
308 return parse( doc, root, collectComments );
314 bool collectComments )
318 collectComments =
false;
346 addError(
"A valid JSON document must be either an array or an object value.",
360 bool successful =
true;
369 switch ( token.
type_ )
393 return addError(
"Syntax error: value, object or array expected.", token );
428 if ( token.
type_ != type )
479 ok =
match(
"rue", 3 );
483 ok =
match(
"alse", 4 );
487 ok =
match(
"ull", 3 );
515 if ( c ==
' ' || c ==
'\t' || c ==
'\r' || c ==
'\n' )
529 int index = patternLength;
531 if (
current_[index] != pattern[index] )
543 bool successful =
false;
605 if ( c ==
'\r' || c ==
'\n' )
648 bool initialTokenOk =
true;
651 if ( !initialTokenOk )
686 bool finalizeTokenOk =
true;
729 if ( !ok || badTokenType )
745 bool isDouble =
false;
749 ||
in( *inspect,
'.',
'e',
'E',
'+' )
750 || ( *inspect ==
'-' && inspect != token.
start_ );
758 bool isNegative = *current ==
'-';
763 Value::LargestUInt threshold = maxIntegerValue / 10;
765 assert( lastDigitThreshold >=0 && lastDigitThreshold <= 9 );
766 Value::LargestUInt value = 0;
767 while ( current < token.
end_ )
770 if ( c < '0' || c >
'9' )
771 return addError(
"'" + std::string( token.
start_, token.
end_ ) +
"' is not a number.", token );
773 if ( value >= threshold )
778 if ( current != token.
end_ || digit > lastDigitThreshold )
783 value = value * 10 + digit;
799 const int bufferSize = 32;
802 if ( length <= bufferSize )
804 Char buffer[bufferSize+1];
805 memcpy( buffer, token.
start_, length );
807 count = sscanf( buffer,
"%lf", &value );
811 std::string buffer( token.
start_, token.
end_ );
812 count = sscanf( buffer.c_str(),
"%lf", &value );
816 return addError(
"'" + std::string( token.
start_, token.
end_ ) +
"' is not a number.", token );
836 decoded.reserve( token.
end_ - token.
start_ - 2 );
839 while ( current != end )
844 else if ( c ==
'\\' )
846 if ( current == end )
847 return addError(
"Empty escape sequence in string", token, current );
848 Char escape = *current++;
851 case '"': decoded +=
'"';
break;
852 case '/': decoded +=
'/';
break;
853 case '\\': decoded +=
'\\';
break;
854 case 'b': decoded +=
'\b';
break;
855 case 'f': decoded +=
'\f';
break;
856 case 'n': decoded +=
'\n';
break;
857 case 'r': decoded +=
'\r';
break;
858 case 't': decoded +=
'\t';
break;
861 unsigned int unicode;
868 return addError(
"Bad escape sequence in string", token, current );
883 unsigned int &unicode )
888 if (unicode >= 0xD800 && unicode <= 0xDBFF)
891 if (end - current < 6)
892 return addError(
"additional six characters expected to parse unicode surrogate pair.", token, current );
893 unsigned int surrogatePair;
894 if (*(current++) ==
'\\' && *(current++)==
'u')
898 unicode = 0x10000 + ((unicode & 0x3FF) << 10) + (surrogatePair & 0x3FF);
904 return addError(
"expecting another \\u token to begin the second half of a unicode surrogate pair", token, current );
913 unsigned int &unicode )
915 if ( end - current < 4 )
916 return addError(
"Bad unicode escape sequence in string: four digits expected.", token, current );
918 for (
int index =0; index < 4; ++index )
922 if ( c >=
'0' && c <=
'9' )
924 else if ( c >=
'a' && c <=
'f' )
925 unicode += c -
'a' + 10;
926 else if ( c >=
'A' && c <=
'F' )
927 unicode += c -
'A' + 10;
929 return addError(
"Bad unicode escape sequence in string: hexadecimal digit expected.", token, current );
952 int errorCount = int(
errors_.size());
1000 while ( current < location && current !=
end_ )
1002 Char c = *current++;
1005 if ( *current ==
'\n' )
1007 lastLineStart = current;
1010 else if ( c ==
'\n' )
1012 lastLineStart = current;
1017 column = int(location - lastLineStart) + 1;
1027 char buffer[18+16+16+1];
1028 sprintf( buffer,
"Line %d, Column %d", line, column );
1044 std::string formattedMessage;
1045 for ( Errors::const_iterator itError =
errors_.begin();
1051 formattedMessage +=
" " + error.
message_ +
"\n";
1055 return formattedMessage;
1062 bool ok = reader.
parse(sin, root,
true);
1089 #ifndef JSONCPP_BATCHALLOCATOR_H_INCLUDED 1090 # define JSONCPP_BATCHALLOCATOR_H_INCLUDED 1092 # include <stdlib.h> 1095 # ifndef JSONCPP_DOC_EXCLUDE_IMPLEMENTATION 1111 template<
typename AllocatedType
1112 ,
const unsigned int objectPerAllocation>
1120 , objectsPerPage_( objectsPerPage )
1123 assert(
sizeof(AllocatedType) * objectPerAllocation >=
sizeof(AllocatedType *) );
1124 assert( objectsPerPage >= 16 );
1125 batches_ = allocateBatch( 0 );
1126 currentBatch_ = batches_;
1131 for (
BatchInfo *batch = batches_; batch; )
1145 AllocatedType *
object = freeHead_;
1146 freeHead_ = *(AllocatedType **)
object;
1149 if ( currentBatch_->used_ == currentBatch_->end_ )
1151 currentBatch_ = currentBatch_->next_;
1152 while ( currentBatch_ && currentBatch_->used_ == currentBatch_->end_ )
1153 currentBatch_ = currentBatch_->next_;
1155 if ( !currentBatch_ )
1157 currentBatch_ = allocateBatch( objectsPerPage_ );
1158 currentBatch_->next_ = batches_;
1159 batches_ = currentBatch_;
1162 AllocatedType *allocated = currentBatch_->used_;
1163 currentBatch_->used_ += objectPerAllocation;
1171 assert(
object != 0 );
1172 *(AllocatedType **)
object = freeHead_;
1182 AllocatedType buffer_[objectPerAllocation];
1191 const unsigned int mallocSize =
sizeof(
BatchInfo) -
sizeof(AllocatedType)* objectPerAllocation
1192 +
sizeof(AllocatedType) * objectPerAllocation * objectsPerPage;
1195 batch->
used_ = batch->buffer_;
1196 batch->end_ = batch->buffer_ + objectsPerPage;
1210 # endif // ifndef JSONCPP_DOC_INCLUDE_IMPLEMENTATION 1212 #endif // JSONCPP_BATCHALLOCATOR_H_INCLUDED 1246 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1255 iterator_.array_ = ValueInternalArray::IteratorState();
1260 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1270 iterator_.array_ = state;
1277 iterator_.map_ = state;
1284 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1288 return ValueInternalArray::dereference( iterator_.array_ );
1289 return ValueInternalMap::value( iterator_.map_ );
1297 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1301 ValueInternalArray::increment( iterator_.array_ );
1302 ValueInternalMap::increment( iterator_.map_ );
1310 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1314 ValueInternalArray::decrement( iterator_.array_ );
1315 ValueInternalMap::decrement( iterator_.map_ );
1323 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1324 # ifdef JSON_USE_CPPTL_SMALLMAP 1343 for ( Value::ObjectValues::iterator it =
current_; it != other.
current_; ++it )
1351 return ValueInternalArray::distance( iterator_.array_, other.iterator_.array_ );
1352 return ValueInternalMap::distance( iterator_.map_, other.iterator_.map_ );
1360 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1368 return ValueInternalArray::equals( iterator_.array_, other.iterator_.array_ );
1369 return ValueInternalMap::equals( iterator_.map_, other.iterator_.map_ );
1377 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1381 iterator_.array_ = other.iterator_.array_;
1382 iterator_.map_ = other.iterator_.map_;
1390 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1392 if ( czstring.
c_str() )
1401 return Value( ValueInternalArray::indexOf( iterator_.array_ ) );
1403 const char *
memberName = ValueInternalMap::key( iterator_.map_, isStatic );
1406 return Value( memberName );
1414 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1416 if ( !czstring.
c_str() )
1417 return czstring.
index();
1421 return Value::UInt( ValueInternalArray::indexOf( iterator_.array_ ) );
1430 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1431 const char *name = (*current_).first.c_str();
1432 return name ? name :
"";
1435 return ValueInternalMap::key( iterator_.map_ );
1454 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1492 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1546 #if !defined(JSON_IS_AMALGAMATION) 1547 # include <json/value.h> 1548 # include <json/writer.h> 1549 # ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1550 # include "json_batchallocator.h" 1551 # endif // #ifndef JSON_USE_SIMPLE_INTERNAL_ALLOCATOR 1552 #endif // if !defined(JSON_IS_AMALGAMATION) 1555 #include <stdexcept> 1558 #ifdef JSON_USE_CPPTL 1559 # include <cpptl/conststring.h> 1563 #define JSON_ASSERT_UNREACHABLE assert( false ) 1564 #define JSON_ASSERT( condition ) assert( condition ); // @todo <= change this into an exception throw 1565 #define JSON_FAIL_MESSAGE( message ) throw std::runtime_error( message ); 1566 #define JSON_ASSERT_MESSAGE( condition, message ) if (!( condition )) JSON_FAIL_MESSAGE( message ) 1593 static inline char *
1595 unsigned int length = unknown )
1598 length = (
unsigned int)strlen(value);
1599 char *newString =
static_cast<char *
>( malloc(
length + 1 ) );
1601 memcpy( newString, value,
length );
1626 #if !defined(JSON_IS_AMALGAMATION) 1627 # ifdef JSON_VALUE_USE_INTERNAL_MAP 1628 # include "json_internalarray.inl" 1629 # include "json_internalmap.inl" 1630 # endif // JSON_VALUE_USE_INTERNAL_MAP 1632 # include "json_valueiterator.inl" 1633 #endif // if !defined(JSON_IS_AMALGAMATION) 1677 # ifndef JSON_VALUE_USE_INTERNAL_MAP 1761 #endif // ifndef JSON_VALUE_USE_INTERNAL_MAP 1780 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1798 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1805 value_.array_ = arrayAllocator()->newArray();
1820 #if defined(JSON_HAS_INT64) 1824 # ifdef JSON_VALUE_USE_INTERNAL_MAP 1834 # ifdef JSON_VALUE_USE_INTERNAL_MAP 1841 #endif // if defined(JSON_HAS_INT64) 1847 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1858 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1868 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1879 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1888 const char *endValue )
1892 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1897 (
unsigned int)(endValue - beginValue) );
1905 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1910 (
unsigned int)value.length() );
1918 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1926 # ifdef JSON_USE_CPPTL 1931 # ifdef JSON_VALUE_USE_INTERNAL_MAP 1942 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1953 # ifdef JSON_VALUE_USE_INTERNAL_MAP
1975 #ifndef JSON_VALUE_USE_INTERNAL_MAP 1982 value_.array_ = arrayAllocator()->newArrayCopy( *other.
value_.array_ );
2018 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2025 arrayAllocator()->destructArray(
value_.array_ );
2042 Value temp( other );
2069 if ( *
this < other )
2071 if ( *
this > other )
2082 return typeDelta < 0 ?
true :
false;
2100 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2111 return value_.array_->compare( *(other.
value_.array_) ) < 0;
2124 return !(other < *
this);
2130 return !(*
this < other);
2136 return other < *
this;
2146 int temp = other.
type_;
2147 if (
type_ != temp )
2166 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2173 return value_.array_->compare( *(other.
value_.array_) ) == 0;
2186 return !( *
this == other );
2220 # ifdef JSON_USE_CPPTL 2222 Value::asConstString()
const 2224 return CppTL::ConstString(
asString().c_str() );
2288 # if defined(JSON_HAS_INT64) 2344 # endif // if defined(JSON_HAS_INT64) 2350 #if defined(JSON_NO_INT64) 2361 #if defined(JSON_NO_INT64) 2379 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2381 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2383 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2408 #if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2410 #else // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2412 #endif // if !defined(JSON_USE_INT64_DOUBLE_CONVERSION) 2517 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2521 ObjectValues::const_iterator itLast =
value_.
map_->end();
2523 return (*itLast).first.index()+1;
2545 return size() == 0u;
2565 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2589 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2593 else if ( newSize > oldSize )
2594 (*this)[ newSize - 1 ];
2597 for (
ArrayIndex index = newSize; index < oldSize; ++index )
2601 assert(
size() == newSize );
2604 value_.array_->resize( newSize );
2615 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2617 ObjectValues::iterator it =
value_.
map_->lower_bound( key );
2618 if ( it !=
value_.
map_->end() && (*it).first == key )
2619 return (*it).second;
2621 ObjectValues::value_type defaultValue( key,
null );
2622 it =
value_.
map_->insert( it, defaultValue );
2623 return (*it).second;
2625 return value_.array_->resolveReference( index );
2644 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2646 ObjectValues::const_iterator it =
value_.
map_->find( key );
2649 return (*it).second;
2652 return value ? *value :
null;
2679 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2682 ObjectValues::iterator it =
value_.
map_->lower_bound( actualKey );
2683 if ( it !=
value_.
map_->end() && (*it).first == actualKey )
2684 return (*it).second;
2686 ObjectValues::value_type defaultValue( actualKey,
null );
2687 it =
value_.
map_->insert( it, defaultValue );
2688 Value &value = (*it).second;
2691 return value_.
map_->resolveReference( key, isStatic );
2698 const Value &defaultValue )
const 2700 const Value *value = &((*this)[index]);
2701 return value == &
null ? defaultValue : *value;
2708 return index <
size();
2719 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2721 ObjectValues::const_iterator it =
value_.
map_->find( actualKey );
2724 return (*it).second;
2727 return value ? *value :
null;
2735 return (*
this)[ key.c_str() ];
2742 return (*
this)[ key.c_str() ];
2752 # ifdef JSON_USE_CPPTL 2756 return (*
this)[ key.c_str() ];
2763 return (*
this)[ key.c_str() ];
2771 return (*
this)[
size()] = value;
2777 const Value &defaultValue )
const 2779 const Value *value = &((*this)[key]);
2780 return value == &
null ? defaultValue : *value;
2786 const Value &defaultValue )
const 2788 return get( key.c_str(), defaultValue );
2797 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2799 ObjectValues::iterator it =
value_.
map_->find( actualKey );
2802 Value old(it->second);
2823 # ifdef JSON_USE_CPPTL 2826 const Value &defaultValue )
const 2828 return get( key.c_str(), defaultValue );
2835 const Value *value = &((*this)[key]);
2836 return value != &
null;
2847 # ifdef JSON_USE_CPPTL 2863 #ifndef JSON_VALUE_USE_INTERNAL_MAP 2864 ObjectValues::const_iterator it =
value_.
map_->begin();
2865 ObjectValues::const_iterator itEnd =
value_.
map_->end();
2866 for ( ; it != itEnd; ++it )
2867 members.push_back( std::string( (*it).first.c_str() ) );
2869 ValueInternalMap::IteratorState it;
2870 ValueInternalMap::IteratorState itEnd;
2873 for ( ; !ValueInternalMap::equals( it, itEnd ); ValueInternalMap::increment(it) )
2874 members.push_back( std::string( ValueInternalMap::key( it ) ) );
3014 return writer.
write( *
this );
3023 #ifdef JSON_VALUE_USE_INTERNAL_MAP 3027 ValueInternalArray::IteratorState it;
3028 value_.array_->makeBeginIterator( it );
3035 ValueInternalMap::IteratorState it;
3058 #ifdef JSON_VALUE_USE_INTERNAL_MAP 3062 ValueInternalArray::IteratorState it;
3063 value_.array_->makeEndIterator( it );
3070 ValueInternalMap::IteratorState it;
3094 #ifdef JSON_VALUE_USE_INTERNAL_MAP 3098 ValueInternalArray::IteratorState it;
3099 value_.array_->makeBeginIterator( it );
3106 ValueInternalMap::IteratorState it;
3129 #ifdef JSON_VALUE_USE_INTERNAL_MAP 3133 ValueInternalArray::IteratorState it;
3134 value_.array_->makeEndIterator( it );
3141 ValueInternalMap::IteratorState it;
3184 :
key_( key.c_str() )
3200 in.push_back( &a1 );
3201 in.push_back( &a2 );
3202 in.push_back( &a3 );
3203 in.push_back( &a4 );
3204 in.push_back( &a5 );
3205 makePath( path, in );
3213 const char *current = path.c_str();
3214 const char *end = current + path.length();
3215 InArgs::const_iterator itInArg = in.begin();
3216 while ( current != end )
3218 if ( *current ==
'[' )
3221 if ( *current ==
'%' )
3226 for ( ; current != end && *current >=
'0' && *current <=
'9'; ++current )
3227 index = index * 10 +
ArrayIndex(*current -
'0');
3228 args_.push_back( index );
3230 if ( current == end || *current++ !=
']' )
3231 invalidPath( path,
int(current - path.c_str()) );
3233 else if ( *current ==
'%' )
3238 else if ( *current ==
'.' )
3244 const char *beginName = current;
3245 while ( current != end && !strchr(
"[.", *current ) )
3247 args_.push_back( std::string( beginName, current ) );
3256 InArgs::const_iterator &itInArg,
3259 if ( itInArg == in.end() )
3263 else if ( (*itInArg)->kind_ != kind )
3269 args_.push_back( **itInArg );
3285 const Value *node = &root;
3286 for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it )
3295 node = &((*node)[arg.
index_]);
3303 node = &((*node)[arg.
key_]);
3316 const Value &defaultValue )
const 3318 const Value *node = &root;
3319 for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it )
3325 return defaultValue;
3326 node = &((*node)[arg.
index_]);
3331 return defaultValue;
3332 node = &((*node)[arg.
key_]);
3334 return defaultValue;
3344 Value *node = &root;
3345 for ( Args::const_iterator it = args_.begin(); it != args_.end(); ++it )
3354 node = &((*node)[arg.
index_]);
3362 node = &((*node)[arg.
key_]);
3389 #if !defined(JSON_IS_AMALGAMATION) 3390 # include <json/writer.h> 3391 # include "json_tool.h" 3392 #endif // if !defined(JSON_IS_AMALGAMATION) 3401 #if _MSC_VER >= 1400 // VC++ 8.0 3402 #pragma warning( disable : 4996 ) // disable warning about strdup being deprecated. 3421 char *current = buffer +
sizeof(buffer);
3422 bool isNegative = value < 0;
3428 assert( current >= buffer );
3436 char *current = buffer +
sizeof(buffer);
3438 assert( current >= buffer );
3442 #if defined(JSON_HAS_INT64) 3455 #endif // # if defined(JSON_HAS_INT64) 3461 #if defined(_MSC_VER) && defined(__STDC_SECURE_LIB__) // Use secure version with visual studio 2005 to avoid warning. 3462 sprintf_s(buffer,
sizeof(buffer),
"%#.16g", value);
3464 sprintf(buffer,
"%#.16g", value);
3466 char* ch = buffer + strlen(buffer) - 1;
3467 if (*ch !=
'0')
return buffer;
3468 while(ch > buffer && *ch ==
'0'){
3471 char* last_nonzero = ch;
3472 while(ch >= buffer){
3488 *(last_nonzero+2) =
'\0';
3500 return value ?
"true" :
"false";
3507 return std::string(
"\"") + value +
"\"";
3511 std::string::size_type maxsize = strlen(value)*2 + 3;
3513 result.reserve(maxsize);
3515 for (
const char* c=value; *c != 0; ++c)
3551 std::ostringstream oss;
3552 oss <<
"\\u" << std::hex << std::uppercase << std::setfill('0') << std::setw(4) << static_cast<int>(*c);
3553 result += oss.str();
3577 : yamlCompatiblityEnabled_( false )
3602 switch ( value.
type() )
3625 int size = value.
size();
3626 for (
int index =0; index < size; ++index )
3639 for ( Value::Members::iterator it = members.begin();
3640 it != members.end();
3643 const std::string &name = *it;
3644 if ( it != members.begin() )
3662 : rightMargin_( 74 )
3685 switch ( value.
type() )
3711 if ( members.empty() )
3717 Value::Members::iterator it = members.begin();
3720 const std::string &name = *it;
3721 const Value &childValue = value[name];
3726 if ( ++it == members.end() )
3746 unsigned size = value.
size();
3752 if ( isArrayMultiLine )
3760 const Value &childValue = value[index];
3762 if ( hasChildValue )
3769 if ( ++index == size )
3784 for (
unsigned index =0; index < size; ++index )
3799 int size = value.
size();
3802 for (
int index =0; index < size && !isMultiLine; ++index )
3804 const Value &childValue = value[index];
3805 isMultiLine = isMultiLine ||
3807 childValue.
size() > 0 );
3813 int lineLength = 4 + (size-1)*2;
3814 for (
int index =0; index < size && !isMultiLine; ++index )
3821 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
3913 normalized.reserve( text.length() );
3914 const char *begin = text.c_str();
3915 const char *end = begin + text.length();
3916 const char *current = begin;
3917 while ( current != end )
3919 char c = *current++;
3922 if ( *current ==
'\n' )
3939 , indentation_( indentation )
3961 switch ( value.
type() )
3987 if ( members.empty() )
3993 Value::Members::iterator it = members.begin();
3996 const std::string &name = *it;
3997 const Value &childValue = value[name];
4002 if ( ++it == members.end() )
4022 unsigned size = value.
size();
4028 if ( isArrayMultiLine )
4036 const Value &childValue = value[index];
4038 if ( hasChildValue )
4045 if ( ++index == size )
4060 for (
unsigned index =0; index < size; ++index )
4075 int size = value.
size();
4078 for (
int index =0; index < size && !isMultiLine; ++index )
4080 const Value &childValue = value[index];
4081 isMultiLine = isMultiLine ||
4083 childValue.
size() > 0 );
4089 int lineLength = 4 + (size-1)*2;
4090 for (
int index =0; index < size && !isMultiLine; ++index )
4097 isMultiLine = isMultiLine || lineLength >=
rightMargin_;
4193 normalized.reserve( text.length() );
4194 const char *begin = text.c_str();
4195 const char *end = begin + text.length();
4196 const char *current = begin;
4197 while ( current != end )
4199 char c = *current++;
4202 if ( *current ==
'\n' )
4216 writer.
write(sout, root);
#define JSON_FAIL_MESSAGE(message)
bool operator<=(const Value &other) const
void writeWithIndent(const std::string &value)
bool operator<(const CZString &other) const
Value & operator[](ArrayIndex index)
std::vector< std::string > Members
const_iterator begin() const
Value(ValueType type=nullValue)
Create a default Value of the given type.
bool operator>(const Value &other) const
bool isMultineArray(const Value &value)
std::string JSON_API valueToQuotedString(const char *value)
std::ostream & operator<<(std::ostream &, const Value &root)
Output using the StyledStreamWriter.
const_iterator end() const
bool allowComments_
true if comments are allowed. Default: true.
Writes a Value in JSON format in a human friendly way, to a stream rather than to a string...
Features()
Initialize the configuration like JsonConfig::allFeatures;.
Json::LargestInt LargestInt
Value removeMember(const char *key)
Remove and return the named member.
static const LargestUInt maxLargestUInt
Maximum unsigned integer value that can be stored in a Json::Value.
bool isEqual(const SelfType &other) const
bool decodeNumber(Token &token)
Value get(ArrayIndex index, const Value &defaultValue) const
bool decodeUnicodeEscapeSequence(Token &token, Location ¤t, Location end, unsigned int &unicode)
static const LargestInt minLargestInt
Minimum signed integer value that can be stored in a Json::Value.
void addPathInArg(const std::string &path, const InArgs &in, InArgs::const_iterator &itInArg, PathArgument::Kind kind)
std::string indentString_
bool readObject(Token &token)
Experimental and untested: represents an element of the "path" to access a node.
Json::ArrayIndex ArrayIndex
void getLocationLineAndColumn(Location location, int &line, int &column) const
bool recoverFromError(TokenType skipUntilToken)
void makePath(const std::string &path, const InArgs &in)
virtual std::string write(const Value &root)
Serialize a Value in JSON format.
std::string commentsBefore_
std::vector< const PathArgument * > InArgs
virtual std::string write(const Value &root)
Lightweight wrapper to tag static string.
static const unsigned int unknown
Unknown size marker.
ValueConstIterator const_iterator
bool yamlCompatiblityEnabled_
void pushValue(const std::string &value)
bool readArray(Token &token)
bool parse(const std::string &document, Value &root, bool collectComments=true)
Read a Value from a JSON document.
void writeArrayValue(const Value &value)
static const UInt maxUInt
Maximum unsigned int value that can be stored in a Json::Value.
AllocatedType * allocate()
std::string JSON_API valueToString(Int value)
bool match(Location pattern, int patternLength)
bool operator<(const Value &other) const
void setComment(const char *comment, CommentPlacement placement)
Comments must be //... or /* ... */.
const Value & resolve(const Value &root) const
unsigned int objectsPerPage_
const char * c_str() const
Configuration passed to reader and writer. This configuration object can be used to force the Reader ...
a comment placed on the line before a value
bool operator!=(const Value &other) const
bool isValidIndex(ArrayIndex index) const
Return true if index < size().
static const UInt64 maxUInt64
Maximum unsigned 64 bits int value that can be stored in a Json::Value.
static const Int64 maxInt64
Maximum signed 64 bits int value that can be stored in a Json::Value.
SelfType & operator=(const ValueIteratorBase &other)
bool readCppStyleComment()
void enableYAMLCompatibility()
bool isConvertibleTo(ValueType other) const
#define JSON_ASSERT_MESSAGE(condition, message)
bool isMember(const char *key) const
Return true if the object has a member named key.
const char * memberName() const
Return the member name of the referenced Value. "" if it is not an objectValue.
void writeValue(const Value &value)
static std::string codePointToUTF8(unsigned int cp)
Converts a unicode code-point to UTF-8.
void writeCommentBeforeValue(const Value &root)
static const Int minInt
Minimum signed int value that can be stored in a Json::Value.
void resize(ArrayIndex size)
void swap(CZString &other)
Value & operator=(const Value &other)
TFSIMD_FORCE_INLINE Vector3 normalized() const
bool operator==(const CZString &other) const
void addComment(Location begin, Location end, CommentPlacement placement)
bool isStaticString() const
difference_type computeDistance(const SelfType &other) const
static bool isControlCharacter(char ch)
Returns true if ch is a control character (in range [0,32[).
bool operator>=(const Value &other) const
std::map< CZString, Value > ObjectValues
BatchAllocator(unsigned int objectsPerPage=255)
static const Int64 minInt64
Minimum signed 64 bits int value that can be stored in a Json::Value.
bool decodeString(Token &token)
Reader()
Constructs a Reader allowing all features for parsing.
bool operator==(const Value &other) const
static void uintToString(LargestUInt value, char *¤t)
object value (collection of name/value pairs).
static Features all()
A configuration that allows all features and assumes all strings are UTF-8.
bool readToken(Token &token)
Json::LargestUInt LargestUInt
void writeCommentAfterValueOnSameLine(const Value &root)
bool decodeDouble(Token &token)
char UIntToStringBuffer[uintToStringBufferSize]
UInt index() const
Return the index of the referenced Value. -1 if it is not an arrayValue.
ValueType
Type of the value held by a Value object.
bool hasCommentForValue(const Value &value)
void writeCommentBeforeValue(const Value &root)
bool addError(const std::string &message, Token &token, Location extra=0)
void invalidPath(const std::string &path, int location)
bool isMultineArray(const Value &value)
static BatchInfo * allocateBatch(unsigned int objectsPerPage)
#define JSON_ASSERT(condition)
JSON (JavaScript Object Notation).
a comment just after a value on the same line
static void releaseStringValue(char *value)
static bool containsControlCharacter(const char *str)
std::istream & operator>>(std::istream &, Value &)
Read from 'sin' into 'root'.
CZString(ArrayIndex index)
void writeWithIndent(const std::string &value)
base class for Value iterators.
bool hasComment(CommentPlacement placement) const
CZString & operator=(const CZString &other)
std::string indentString_
#define JSON_ASSERT_UNREACHABLE
std::string getFormattedErrorMessages() const
Returns a user friendly string that list errors in the parsed document.
bool empty() const
Return true if empty array, empty object, or null; otherwise, false.
Value key() const
Return either the index or the member name of the referenced value as a Value.
Path(const std::string &path, const PathArgument &a1=PathArgument(), const PathArgument &a2=PathArgument(), const PathArgument &a3=PathArgument(), const PathArgument &a4=PathArgument(), const PathArgument &a5=PathArgument())
a comment on the line after a value (only make sense for root value)
static std::string normalizeEOL(const std::string &text)
const char * c_str() const
bool decodeUnicodeCodePoint(Token &token, Location ¤t, Location end, unsigned int &unicode)
bool operator!() const
Return isNull()
void copy(const SelfType &other)
std::string asString() const
std::string toStyledString() const
std::string getComment(CommentPlacement placement) const
Include delimiters and embedded newlines.
static bool in(Reader::Char c, Reader::Char c1, Reader::Char c2, Reader::Char c3, Reader::Char c4)
Value & make(Value &root) const
Creates the "path" to access the specified node and returns a reference on the node.
SelfType & operator=(const SelfType &other)
static const Int maxInt
Maximum signed int value that can be stored in a Json::Value.
LargestUInt asLargestUInt() const
void write(std::ostream &out, const Value &root)
Serialize a Value in JSON format.
bool expectToken(TokenType type, Token &token, const char *message)
static Features strictMode()
A configuration that is strictly compatible with the JSON specification.
void release(AllocatedType *object)
Constant that specify the size of the buffer that must be passed to uintToString. ...
union Json::Value::ValueHolder value_
Unserialize a JSON document into a Value.
const char * asCString() const
StyledStreamWriter(std::string indentation="\t")
unsigned long long int UInt64
TFSIMD_FORCE_INLINE tfScalar length(const Quaternion &q)
void writeArrayValue(const Value &value)
void writeValue(const Value &value)
BatchInfo * currentBatch_
static std::string normalizeEOL(const std::string &text)
static const LargestInt maxLargestInt
Maximum signed integer value that can be stored in a Json::Value.
Value & resolveReference(const char *key, bool isStatic)
static bool containsNewLine(Reader::Location begin, Reader::Location end)
static char * duplicateStringValue(const char *value, unsigned int length=unknown)
bool addErrorAndRecover(const std::string &message, Token &token, TokenType skipUntilToken)
Iterator for object and array value.
Members getMemberNames() const
Return a list of the member names.
LargestInt asLargestInt() const
int compare(const Value &other) const
void writeValue(const Value &value)
Writes a Value in JSON format in a human friendly way.
ArrayIndex size() const
Number of values in array or object.
bool hasCommentForValue(const Value &value)
void pushValue(const std::string &value)
bool strictRoot_
true if root must be either an array or an object value. Default: false.
Value & append(const Value &value)
Append value to array at the end.
void writeCommentAfterValueOnSameLine(const Value &root)
const iterator for object and array value.
std::string getFormatedErrorMessages() const
Returns a user friendly string that list errors in the parsed document.
void skipCommentTokens(Token &token)
AllocatedType * freeHead_
Head of a single linked list within the allocated space of freeed object.
Value::ObjectValues::iterator current_
array value (ordered list)