Skip to content

Commit 3a1b93b

Browse files
committed
- added Int/UInt typedef in Json namespace. Modified Value::Int and Value::UInt to be typedef on those. Modified code to use Json::Int instead of Value::Int.
- added Value constructor taking begin/end pointer to initialize the Value with a non-zero terminated string.
1 parent 7a86655 commit 3a1b93b

6 files changed

Lines changed: 36 additions & 15 deletions

File tree

include/json/forwards.h

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55

66
namespace Json {
77

8+
// writer.h
89
class FastWriter;
9-
class Reader;
1010
class StyledWriter;
1111

12+
// reader.h
13+
class Reader;
14+
1215
// features.h
1316
class Features;
1417

1518
// value.h
19+
typedef int Int;
20+
typedef unsigned int UInt;
1621
class StaticString;
1722
class Path;
1823
class PathArgument;

include/json/value.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,10 +117,10 @@ namespace Json {
117117
# endif
118118
public:
119119
typedef std::vector<std::string> Members;
120-
typedef int Int;
121-
typedef unsigned int UInt;
122120
typedef ValueIterator iterator;
123121
typedef ValueConstIterator const_iterator;
122+
typedef Json::UInt UInt;
123+
typedef Json::Int Int;
124124
typedef UInt ArrayIndex;
125125

126126
static const Value null;
@@ -186,6 +186,7 @@ namespace Json {
186186
Value( UInt value );
187187
Value( double value );
188188
Value( const char *value );
189+
Value( const char *beginValue, const char *endValue );
189190
/** \brief Constructs a value from a static string.
190191
191192
* Like other value string constructor but do not duplicate the string for
@@ -453,7 +454,7 @@ namespace Json {
453454
friend class Path;
454455

455456
PathArgument();
456-
PathArgument( Value::UInt index );
457+
PathArgument( UInt index );
457458
PathArgument( const char *key );
458459
PathArgument( const std::string &key );
459460

@@ -465,7 +466,7 @@ namespace Json {
465466
kindKey
466467
};
467468
std::string key_;
468-
Value::UInt index_;
469+
UInt index_;
469470
Kind kind_;
470471
};
471472

@@ -909,7 +910,7 @@ class DefaultValueArrayAllocator : public ValueArrayAllocator
909910
Value key() const;
910911

911912
/// Return the index of the referenced Value. -1 if it is not an arrayValue.
912-
Value::UInt index() const;
913+
UInt index() const;
913914

914915
/// Return the member name of the referenced Value. "" if it is not an objectValue.
915916
const char *memberName() const;

include/json/writer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,8 @@ namespace Json {
157157
bool addChildValues_;
158158
};
159159

160-
std::string JSON_API valueToString( Value::Int value );
161-
std::string JSON_API valueToString( Value::UInt value );
160+
std::string JSON_API valueToString( Int value );
161+
std::string JSON_API valueToString( UInt value );
162162
std::string JSON_API valueToString( double value );
163163
std::string JSON_API valueToString( bool value );
164164
std::string JSON_API valueToQuotedString( const char *value );

src/lib_json/json_value.cpp

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@
2020
namespace Json {
2121

2222
const Value Value::null;
23-
const Value::Int Value::minInt = Value::Int( ~(Value::UInt(-1)/2) );
24-
const Value::Int Value::maxInt = Value::Int( Value::UInt(-1)/2 );
25-
const Value::UInt Value::maxUInt = Value::UInt(-1);
23+
const Int Value::minInt = Int( ~(UInt(-1)/2) );
24+
const Int Value::maxInt = Int( UInt(-1)/2 );
25+
const UInt Value::maxUInt = UInt(-1);
2626

2727
// A "safe" implementation of strdup. Allow null pointer to be passed.
2828
// Also avoid warning on msvc80.
@@ -351,6 +351,21 @@ Value::Value( const char *value )
351351
value_.string_ = valueAllocator()->duplicateStringValue( value );
352352
}
353353

354+
355+
Value::Value( const char *beginValue,
356+
const char *endValue )
357+
: type_( stringValue )
358+
, allocated_( true )
359+
, comments_( 0 )
360+
# ifdef JSON_VALUE_USE_INTERNAL_MAP
361+
, itemIsUsed_( 0 )
362+
#endif
363+
{
364+
value_.string_ = valueAllocator()->duplicateStringValue( beginValue,
365+
UInt(endValue - beginValue) );
366+
}
367+
368+
354369
Value::Value( const std::string &value )
355370
: type_( stringValue )
356371
, allocated_( true )

src/lib_json/json_valueiterator.inl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ ValueIteratorBase::key() const
176176
}
177177

178178

179-
Value::UInt
179+
UInt
180180
ValueIteratorBase::index() const
181181
{
182182
#ifndef JSON_VALUE_USE_INTERNAL_MAP

src/lib_json/json_writer.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,22 @@ static void uintToString( unsigned int value,
3939
while ( value != 0 );
4040
}
4141

42-
std::string valueToString( Value::Int value )
42+
std::string valueToString( Int value )
4343
{
4444
char buffer[32];
4545
char *current = buffer + sizeof(buffer);
4646
bool isNegative = value < 0;
4747
if ( isNegative )
4848
value = -value;
49-
uintToString( Value::UInt(value), current );
49+
uintToString( UInt(value), current );
5050
if ( isNegative )
5151
*--current = '-';
5252
assert( current >= buffer );
5353
return current;
5454
}
5555

5656

57-
std::string valueToString( Value::UInt value )
57+
std::string valueToString( UInt value )
5858
{
5959
char buffer[32];
6060
char *current = buffer + sizeof(buffer);

0 commit comments

Comments
 (0)