Commit f0c108b5 authored by John Stiles's avatar John Stiles

Remove all switch

parent 6723e329
...@@ -58,6 +58,7 @@ protected: ...@@ -58,6 +58,7 @@ protected:
protected: protected:
enum LookaheadParsingState { enum LookaheadParsingState {
kInit,
kError, kError,
kHasNull, kHasNull,
kHasBool, kHasBool,
...@@ -78,7 +79,7 @@ protected: ...@@ -78,7 +79,7 @@ protected:
static const int parseFlags = kParseDefaultFlags | kParseInsituFlag; static const int parseFlags = kParseDefaultFlags | kParseInsituFlag;
}; };
LookaheadParserHandler::LookaheadParserHandler(char* str) : v_(), ss_(str) { LookaheadParserHandler::LookaheadParserHandler(char* str) : v_(), st_(kInit), r_(), ss_(str) {
r_.IterativeParseInit(); r_.IterativeParseInit();
ParseNext(); ParseNext();
} }
...@@ -145,12 +146,12 @@ const char* LookaheadParser::NextObjectKey() { ...@@ -145,12 +146,12 @@ const char* LookaheadParser::NextObjectKey() {
return result; return result;
} }
if (st_ == kExitingObject) { if (st_ != kExitingObject) {
ParseNext(); st_ = kError;
return 0; return 0;
} }
st_ = kError; ParseNext();
return 0; return 0;
} }
...@@ -180,7 +181,7 @@ int LookaheadParser::GetInt() { ...@@ -180,7 +181,7 @@ int LookaheadParser::GetInt() {
} }
double LookaheadParser::GetDouble() { double LookaheadParser::GetDouble() {
if (st_ != kHasNumber || !v_.IsNumber()) { if (st_ != kHasNumber) {
st_ = kError; st_ = kError;
return 0.; return 0.;
} }
...@@ -223,27 +224,16 @@ const char* LookaheadParser::GetString() { ...@@ -223,27 +224,16 @@ const char* LookaheadParser::GetString() {
void LookaheadParser::SkipOut(int depth) { void LookaheadParser::SkipOut(int depth) {
do { do {
switch (st_) { if (st_ == kEnteringArray || st_ == kEnteringObject) {
case kEnteringArray: ++depth;
case kEnteringObject:
++depth;
break;
case kExitingArray:
case kExitingObject:
--depth;
break;
case kError:
return;
case kHasNull:
case kHasBool:
case kHasNumber:
case kHasString:
case kHasKey:
break;
} }
else if (st_ == kExitingArray || st_ == kExitingObject) {
--depth;
}
else if (st_ == kError) {
return;
}
ParseNext(); ParseNext();
} }
while (depth > 0); while (depth > 0);
...@@ -270,25 +260,19 @@ Value* LookaheadParser::PeekValue() { ...@@ -270,25 +260,19 @@ Value* LookaheadParser::PeekValue() {
} }
int LookaheadParser::PeekType() { int LookaheadParser::PeekType() {
switch (st_) { if (st_ >= kHasNull && st_ <= kHasKey) {
case kHasNull: return v_.GetType();
case kHasBool: }
case kHasNumber:
case kHasString: if (st_ == kEnteringArray) {
case kHasKey: return kArrayType;
return v_.GetType();
case kEnteringArray:
return kArrayType;
case kEnteringObject:
return kObjectType;
case kExitingArray:
case kExitingObject:
case kError:
return -1;
} }
if (st_ == kEnteringObject) {
return kObjectType;
}
return -1;
} }
//------------------------------------------------------------------------- //-------------------------------------------------------------------------
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment