Skip to content

Commit

Permalink
tabs to 4 spaces (following 0dbcc1c)
Browse files Browse the repository at this point in the history
  • Loading branch information
pah committed Aug 11, 2014
1 parent d84c051 commit 453eda5
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 108 deletions.
78 changes: 40 additions & 38 deletions include/rapidjson/reader.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,25 +121,27 @@ concept Handler {

//! Default implementation of Handler.
/*! This can be used as base class of any reader handler.
\note implements Handler concept
\note implements Handler concept
*/
template<typename Encoding = UTF8<>, typename Derived = void>
struct BaseReaderHandler {
typedef typename Encoding::Ch Ch;

bool Default() { return true; }
bool Null() { return static_cast<Override&>(*this).Default(); }
bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
bool Int(int) { return static_cast<Override&>(*this).Default(); }
bool Uint(unsigned) { return static_cast<Override&>(*this).Default(); }
bool Int64(int64_t) { return static_cast<Override&>(*this).Default(); }
bool Uint64(uint64_t) { return static_cast<Override&>(*this).Default(); }
bool Double(double) { return static_cast<Override&>(*this).Default(); }
bool String(const Ch*, SizeType, bool) { return static_cast<Override&>(*this).Default(); }
bool StartObject() { return static_cast<Override&>(*this).Default(); }
bool EndObject(SizeType) { return static_cast<Override&>(*this).Default(); }
bool StartArray() { return static_cast<Override&>(*this).Default(); }
bool EndArray(SizeType) { return static_cast<Override&>(*this).Default(); }
typedef typename Encoding::Ch Ch;

typedef typename internal::SelectIf<internal::IsSame<Derived, void>, BaseReaderHandler, Derived>::Type Override;

bool Default() { return true; }
bool Null() { return static_cast<Override&>(*this).Default(); }
bool Bool(bool) { return static_cast<Override&>(*this).Default(); }
bool Int(int) { return static_cast<Override&>(*this).Default(); }
bool Uint(unsigned) { return static_cast<Override&>(*this).Default(); }
bool Int64(int64_t) { return static_cast<Override&>(*this).Default(); }
bool Uint64(uint64_t) { return static_cast<Override&>(*this).Default(); }
bool Double(double) { return static_cast<Override&>(*this).Default(); }
bool String(const Ch*, SizeType, bool) { return static_cast<Override&>(*this).Default(); }
bool StartObject() { return static_cast<Override&>(*this).Default(); }
bool EndObject(SizeType) { return static_cast<Override&>(*this).Default(); }
bool StartArray() { return static_cast<Override&>(*this).Default(); }
bool EndArray(SizeType) { return static_cast<Override&>(*this).Default(); }
};

///////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -382,7 +384,7 @@ class GenericReader {
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);
}
else {
ParseValue<parseFlags>(is, handler);
ParseValue<parseFlags>(is, handler);
RAPIDJSON_PARSE_ERROR_EARLY_RETURN(parseResult_);

if (!(parseFlags & kParseStopWhenDoneFlag)) {
Expand Down Expand Up @@ -904,8 +906,8 @@ class GenericReader {
IterativeParsingElementDelimiterState,
IterativeParsingArrayFinishState,

// Single value state
IterativeParsingValueState,
// Single value state
IterativeParsingValueState,

cIterativeParsingStateCount
};
Expand Down Expand Up @@ -965,11 +967,11 @@ class GenericReader {
IterativeParsingErrorState, // Right curly bracket
IterativeParsingErrorState, // Comma
IterativeParsingErrorState, // Colon
IterativeParsingValueState, // String
IterativeParsingValueState, // False
IterativeParsingValueState, // True
IterativeParsingValueState, // Null
IterativeParsingValueState // Number
IterativeParsingValueState, // String
IterativeParsingValueState, // False
IterativeParsingValueState, // True
IterativeParsingValueState, // Null
IterativeParsingValueState // Number
},
// Finish(sink state)
{
Expand Down Expand Up @@ -1106,12 +1108,12 @@ class GenericReader {
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
},
// Single Value (sink state)
{
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState, IterativeParsingErrorState,
IterativeParsingErrorState
}
}; // End of G

Expand Down Expand Up @@ -1248,13 +1250,13 @@ class GenericReader {
}
}

case IterativeParsingValueState:
// Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
ParseValue<parseFlags>(is, handler);
if (HasParseError()) {
return IterativeParsingErrorState;
}
return IterativeParsingFinishState;
case IterativeParsingValueState:
// Must be non-compound value. Or it would be ObjectInitial or ArrayInitial state.
ParseValue<parseFlags>(is, handler);
if (HasParseError()) {
return IterativeParsingErrorState;
}
return IterativeParsingFinishState;

default:
RAPIDJSON_ASSERT(false);
Expand All @@ -1270,7 +1272,7 @@ class GenericReader {
}

switch (src) {
case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell());
case IterativeParsingStartState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentEmpty, is.Tell());
case IterativeParsingFinishState: RAPIDJSON_PARSE_ERROR(kParseErrorDocumentRootNotSingular, is.Tell());
case IterativeParsingObjectInitialState:
case IterativeParsingMemberDelimiterState: RAPIDJSON_PARSE_ERROR(kParseErrorObjectMissName, is.Tell());
Expand Down
20 changes: 10 additions & 10 deletions test/unittest/jsoncheckertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ TEST(JsonChecker, Reader) {

// jsonchecker/failXX.json
for (int i = 1; i <= 33; i++) {
if (i == 1) // fail1.json is valid in rapidjson, which has no limitation on type of root element (RFC 7159).
continue;
if (i == 1) // fail1.json is valid in rapidjson, which has no limitation on type of root element (RFC 7159).
continue;
if (i == 18) // fail18.json is valid in rapidjson, which has no limitation on depth of nesting.
continue;

Expand All @@ -59,17 +59,17 @@ TEST(JsonChecker, Reader) {
json = ReadFile(filename, length);
if (!json) {
printf("jsonchecker file %s not found", filename);
ADD_FAILURE();
ADD_FAILURE();
continue;
}
}

GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse((const char*)json);
EXPECT_TRUE(document.HasParseError());
document.Parse((const char*)json);
EXPECT_TRUE(document.HasParseError());

document.Parse<kParseIterativeFlag>((const char*)json);
EXPECT_TRUE(document.HasParseError());
document.Parse<kParseIterativeFlag>((const char*)json);
EXPECT_TRUE(document.HasParseError());

free(json);
}
Expand All @@ -90,10 +90,10 @@ TEST(JsonChecker, Reader) {

GenericDocument<UTF8<>, CrtAllocator> document; // Use Crt allocator to check exception-safety (no memory leak)
document.Parse((const char*)json);
EXPECT_FALSE(document.HasParseError());
EXPECT_FALSE(document.HasParseError());

document.Parse<kParseIterativeFlag>((const char*)json);
EXPECT_FALSE(document.HasParseError());
document.Parse<kParseIterativeFlag>((const char*)json);
EXPECT_FALSE(document.HasParseError());

free(json);
}
Expand Down
52 changes: 26 additions & 26 deletions test/unittest/readertest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,15 @@ TEST(Reader, ParseTrue) {
StringStream s("true");
ParseBoolHandler<true> h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(1u, h.step_);
}

TEST(Reader, ParseFalse) {
StringStream s("false");
ParseBoolHandler<false> h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(1u, h.step_);
}

Expand Down Expand Up @@ -108,7 +108,7 @@ TEST(Reader, ParseNumberHandler) {
StringStream s(str); \
Handler h; \
Reader reader; \
reader.Parse(s, h); \
reader.Parse(s, h); \
EXPECT_EQ(1u, h.step_); \
EXPECT_EQ(double(x), h.actual_); \
}
Expand All @@ -118,7 +118,7 @@ TEST(Reader, ParseNumberHandler) {
StringStream s(str); \
ParseDoubleHandler h; \
Reader reader; \
reader.Parse(s, h); \
reader.Parse(s, h); \
EXPECT_EQ(1u, h.step_); \
EXPECT_DOUBLE_EQ(x, h.actual_); \
}
Expand Down Expand Up @@ -178,11 +178,11 @@ TEST(Reader, ParseNumber_Error) {
#define TEST_NUMBER_ERROR(errorCode, str) \
{ \
char buffer[1001]; \
sprintf(buffer, "%s", str); \
sprintf(buffer, "%s", str); \
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
Reader reader; \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
}

Expand Down Expand Up @@ -242,14 +242,14 @@ TEST(Reader, ParseString) {
GenericInsituStringStream<Encoding> is(buffer); \
ParseStringHandler<Encoding> h; \
GenericReader<Encoding, Encoding> reader; \
reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
reader.Parse<kParseInsituFlag | kParseValidateEncodingFlag>(is, h); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h.str_)); \
EXPECT_EQ(StrLen(e), h.length_); \
free(buffer); \
GenericStringStream<Encoding> s(x); \
ParseStringHandler<Encoding> h2; \
GenericReader<Encoding, Encoding> reader2; \
reader2.Parse(s, h2); \
reader2.Parse(s, h2); \
EXPECT_EQ(0, StrCmp<Encoding::Ch>(e, h2.str_)); \
EXPECT_EQ(StrLen(e), h2.length_); \
}
Expand Down Expand Up @@ -314,7 +314,7 @@ TEST(Reader, ParseString) {
const char e[] = "Hello\0World";
ParseStringHandler<UTF8<> > h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(0, memcmp(e, h.str_, h.length_ + 1));
EXPECT_EQ(11u, h.length_);
}
Expand All @@ -326,7 +326,7 @@ TEST(Reader, ParseString_Transcoding) {
GenericStringStream<UTF8<> > is(x);
GenericReader<UTF8<>, UTF16<> > reader;
ParseStringHandler<UTF16<> > h;
reader.Parse(is, h);
reader.Parse(is, h);
EXPECT_EQ(0, StrCmp<UTF16<>::Ch>(e, h.str_));
EXPECT_EQ(StrLen(e), h.length_);
}
Expand All @@ -335,7 +335,7 @@ TEST(Reader, ParseString_NonDestructive) {
StringStream s("\"Hello\\nWorld\"");
ParseStringHandler<UTF8<> > h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(0, StrCmp("Hello\nWorld", h.str_));
EXPECT_EQ(11u, h.length_);
}
Expand Down Expand Up @@ -447,7 +447,7 @@ TEST(Reader, ParseEmptyArray) {
InsituStringStream s(json);
ParseArrayHandler<0> h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(2u, h.step_);
free(json);
}
Expand All @@ -457,7 +457,7 @@ TEST(Reader, ParseArray) {
InsituStringStream s(json);
ParseArrayHandler<4> h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(6u, h.step_);
free(json);
}
Expand All @@ -470,7 +470,7 @@ TEST(Reader, ParseArray_Error) {
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
GenericReader<UTF8<>, UTF8<>, CrtAllocator> reader; \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
}

Expand All @@ -485,7 +485,7 @@ TEST(Reader, ParseArray_Error) {
struct ParseObjectHandler : BaseReaderHandler<UTF8<>, ParseObjectHandler> {
ParseObjectHandler() : step_(0) {}

bool Default() { ADD_FAILURE(); return false; }
bool Default() { ADD_FAILURE(); return false; }
bool Null() { EXPECT_EQ(8u, step_); step_++; return true; }
bool Bool(bool b) {
switch(step_) {
Expand Down Expand Up @@ -535,7 +535,7 @@ TEST(Reader, ParseObject) {
InsituStringStream s(json2);
ParseObjectHandler h;
Reader reader;
reader.Parse<kParseInsituFlag>(s, h);
reader.Parse<kParseInsituFlag>(s, h);
EXPECT_EQ(20u, h.step_);
free(json2);
}
Expand All @@ -545,7 +545,7 @@ TEST(Reader, ParseObject) {
StringStream s(json);
ParseObjectHandler h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(20u, h.step_);
}
}
Expand All @@ -564,7 +564,7 @@ TEST(Reader, Parse_EmptyObject) {
StringStream s("{ } ");
ParseEmptyObjectHandler h;
Reader reader;
reader.Parse(s, h);
reader.Parse(s, h);
EXPECT_EQ(2u, h.step_);
}

Expand Down Expand Up @@ -631,7 +631,7 @@ TEST(Reader, ParseInsituIterative_MultipleRoot) {
InsituStringStream s(buffer); \
BaseReaderHandler<> h; \
Reader reader; \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_FALSE(reader.Parse(s, h)); \
EXPECT_EQ(errorCode, reader.GetParseErrorCode());\
}

Expand All @@ -644,17 +644,17 @@ TEST(Reader, ParseDocument_Error) {
// The document root must not follow by other values.
TEST_ERROR(kParseErrorDocumentRootNotSingular, "[] 0");
TEST_ERROR(kParseErrorDocumentRootNotSingular, "{} 0");
TEST_ERROR(kParseErrorDocumentRootNotSingular, "null []");
TEST_ERROR(kParseErrorDocumentRootNotSingular, "0 {}");
TEST_ERROR(kParseErrorDocumentRootNotSingular, "null []");
TEST_ERROR(kParseErrorDocumentRootNotSingular, "0 {}");
}

TEST(Reader, ParseValue_Error) {
// Invalid value.
TEST_ERROR(kParseErrorValueInvalid, "nulL");
TEST_ERROR(kParseErrorValueInvalid, "truE");
TEST_ERROR(kParseErrorValueInvalid, "falsE");
TEST_ERROR(kParseErrorValueInvalid, "a]");
TEST_ERROR(kParseErrorValueInvalid, ".1");
TEST_ERROR(kParseErrorValueInvalid, "nulL");
TEST_ERROR(kParseErrorValueInvalid, "truE");
TEST_ERROR(kParseErrorValueInvalid, "falsE");
TEST_ERROR(kParseErrorValueInvalid, "a]");
TEST_ERROR(kParseErrorValueInvalid, ".1");
}

TEST(Reader, ParseObject_Error) {
Expand Down
Loading

0 comments on commit 453eda5

Please sign in to comment.