- 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.
This commit is contained in:
Baptiste Lepilleur 2010-02-21 14:08:17 +00:00
parent 7a866553bb
commit 3a1b93be1c
6 changed files with 36 additions and 15 deletions

View File

@ -5,14 +5,19 @@
namespace Json { namespace Json {
// writer.h
class FastWriter; class FastWriter;
class Reader;
class StyledWriter; class StyledWriter;
// reader.h
class Reader;
// features.h // features.h
class Features; class Features;
// value.h // value.h
typedef int Int;
typedef unsigned int UInt;
class StaticString; class StaticString;
class Path; class Path;
class PathArgument; class PathArgument;

View File

@ -117,10 +117,10 @@ namespace Json {
# endif # endif
public: public:
typedef std::vector<std::string> Members; typedef std::vector<std::string> Members;
typedef int Int;
typedef unsigned int UInt;
typedef ValueIterator iterator; typedef ValueIterator iterator;
typedef ValueConstIterator const_iterator; typedef ValueConstIterator const_iterator;
typedef Json::UInt UInt;
typedef Json::Int Int;
typedef UInt ArrayIndex; typedef UInt ArrayIndex;
static const Value null; static const Value null;
@ -186,6 +186,7 @@ namespace Json {
Value( UInt value ); Value( UInt value );
Value( double value ); Value( double value );
Value( const char *value ); Value( const char *value );
Value( const char *beginValue, const char *endValue );
/** \brief Constructs a value from a static string. /** \brief Constructs a value from a static string.
* Like other value string constructor but do not duplicate the string for * Like other value string constructor but do not duplicate the string for
@ -453,7 +454,7 @@ namespace Json {
friend class Path; friend class Path;
PathArgument(); PathArgument();
PathArgument( Value::UInt index ); PathArgument( UInt index );
PathArgument( const char *key ); PathArgument( const char *key );
PathArgument( const std::string &key ); PathArgument( const std::string &key );
@ -465,7 +466,7 @@ namespace Json {
kindKey kindKey
}; };
std::string key_; std::string key_;
Value::UInt index_; UInt index_;
Kind kind_; Kind kind_;
}; };
@ -909,7 +910,7 @@ public: // overridden from ValueArrayAllocator
Value key() const; Value key() const;
/// Return the index of the referenced Value. -1 if it is not an arrayValue. /// Return the index of the referenced Value. -1 if it is not an arrayValue.
Value::UInt index() const; UInt index() const;
/// Return the member name of the referenced Value. "" if it is not an objectValue. /// Return the member name of the referenced Value. "" if it is not an objectValue.
const char *memberName() const; const char *memberName() const;

View File

@ -157,8 +157,8 @@ namespace Json {
bool addChildValues_; bool addChildValues_;
}; };
std::string JSON_API valueToString( Value::Int value ); std::string JSON_API valueToString( Int value );
std::string JSON_API valueToString( Value::UInt value ); std::string JSON_API valueToString( UInt value );
std::string JSON_API valueToString( double value ); std::string JSON_API valueToString( double value );
std::string JSON_API valueToString( bool value ); std::string JSON_API valueToString( bool value );
std::string JSON_API valueToQuotedString( const char *value ); std::string JSON_API valueToQuotedString( const char *value );

View File

@ -20,9 +20,9 @@
namespace Json { namespace Json {
const Value Value::null; const Value Value::null;
const Value::Int Value::minInt = Value::Int( ~(Value::UInt(-1)/2) ); const Int Value::minInt = Int( ~(UInt(-1)/2) );
const Value::Int Value::maxInt = Value::Int( Value::UInt(-1)/2 ); const Int Value::maxInt = Int( UInt(-1)/2 );
const Value::UInt Value::maxUInt = Value::UInt(-1); const UInt Value::maxUInt = UInt(-1);
// A "safe" implementation of strdup. Allow null pointer to be passed. // A "safe" implementation of strdup. Allow null pointer to be passed.
// Also avoid warning on msvc80. // Also avoid warning on msvc80.
@ -351,6 +351,21 @@ Value::Value( const char *value )
value_.string_ = valueAllocator()->duplicateStringValue( value ); value_.string_ = valueAllocator()->duplicateStringValue( value );
} }
Value::Value( const char *beginValue,
const char *endValue )
: type_( stringValue )
, allocated_( true )
, comments_( 0 )
# ifdef JSON_VALUE_USE_INTERNAL_MAP
, itemIsUsed_( 0 )
#endif
{
value_.string_ = valueAllocator()->duplicateStringValue( beginValue,
UInt(endValue - beginValue) );
}
Value::Value( const std::string &value ) Value::Value( const std::string &value )
: type_( stringValue ) : type_( stringValue )
, allocated_( true ) , allocated_( true )

View File

@ -176,7 +176,7 @@ ValueIteratorBase::key() const
} }
Value::UInt UInt
ValueIteratorBase::index() const ValueIteratorBase::index() const
{ {
#ifndef JSON_VALUE_USE_INTERNAL_MAP #ifndef JSON_VALUE_USE_INTERNAL_MAP

View File

@ -39,14 +39,14 @@ static void uintToString( unsigned int value,
while ( value != 0 ); while ( value != 0 );
} }
std::string valueToString( Value::Int value ) std::string valueToString( Int value )
{ {
char buffer[32]; char buffer[32];
char *current = buffer + sizeof(buffer); char *current = buffer + sizeof(buffer);
bool isNegative = value < 0; bool isNegative = value < 0;
if ( isNegative ) if ( isNegative )
value = -value; value = -value;
uintToString( Value::UInt(value), current ); uintToString( UInt(value), current );
if ( isNegative ) if ( isNegative )
*--current = '-'; *--current = '-';
assert( current >= buffer ); assert( current >= buffer );
@ -54,7 +54,7 @@ std::string valueToString( Value::Int value )
} }
std::string valueToString( Value::UInt value ) std::string valueToString( UInt value )
{ {
char buffer[32]; char buffer[32];
char *current = buffer + sizeof(buffer); char *current = buffer + sizeof(buffer);