mirror of
https://github.com/pocoproject/poco.git
synced 2025-04-16 23:12:57 +02:00
purely cosmetics
This commit is contained in:
parent
80cf789dcd
commit
8a44e75187
@ -66,12 +66,12 @@ public:
|
|||||||
|
|
||||||
bool start(char c, std::istream& istr)
|
bool start(char c, std::istream& istr)
|
||||||
{
|
{
|
||||||
if ( c == '{'
|
if (c == '{'
|
||||||
|| c == '}'
|
|| c == '}'
|
||||||
|| c == ']'
|
|| c == ']'
|
||||||
|| c == '['
|
|| c == '['
|
||||||
|| c == ','
|
|| c == ','
|
||||||
|| c == ':' )
|
|| c == ':')
|
||||||
{
|
{
|
||||||
_value = c;
|
_value = c;
|
||||||
return true;
|
return true;
|
||||||
@ -109,7 +109,7 @@ public:
|
|||||||
|
|
||||||
bool start(char c, std::istream& istr)
|
bool start(char c, std::istream& istr)
|
||||||
{
|
{
|
||||||
if ( c == '"')
|
if (c == '"')
|
||||||
{
|
{
|
||||||
_value = ""; // We don't need the quote!
|
_value = ""; // We don't need the quote!
|
||||||
return true;
|
return true;
|
||||||
@ -122,7 +122,7 @@ public:
|
|||||||
int c = 0;
|
int c = 0;
|
||||||
while ((c = istr.get()) != -1)
|
while ((c = istr.get()) != -1)
|
||||||
{
|
{
|
||||||
if ( c == 0 )
|
if (c == 0)
|
||||||
{
|
{
|
||||||
throw JSONException("Null byte not allowed");
|
throw JSONException("Null byte not allowed");
|
||||||
}
|
}
|
||||||
@ -132,7 +132,7 @@ public:
|
|||||||
throw JSONException(format("Control character 0x%x not allowed", (unsigned int) c));
|
throw JSONException(format("Control character 0x%x not allowed", (unsigned int) c));
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c == '"' )
|
if (c == '"')
|
||||||
break;
|
break;
|
||||||
|
|
||||||
if(0x80 <= c && c <= 0xFF)
|
if(0x80 <= c && c <= 0xFF)
|
||||||
@ -160,35 +160,19 @@ public:
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c == '\\' ) // Escaped String
|
if (c == '\\') // Escaped String
|
||||||
{
|
{
|
||||||
c = istr.get();
|
c = istr.get();
|
||||||
switch(c)
|
switch(c)
|
||||||
{
|
{
|
||||||
case '"' :
|
case '"' : c = '"'; break;
|
||||||
c = '"';
|
case '\\' : c = '\\'; break;
|
||||||
break;
|
case '/' : c = '/'; break;
|
||||||
case '\\' :
|
case 'b' : c = '\b'; break;
|
||||||
c = '\\';
|
case 'f' : c = '\f'; break;
|
||||||
break;
|
case 'n' : c = '\n'; break;
|
||||||
case '/' :
|
case 'r' : c = '\r'; break;
|
||||||
c = '/';
|
case 't' : c = '\t'; break;
|
||||||
break;
|
|
||||||
case 'b' :
|
|
||||||
c = '\b';
|
|
||||||
break;
|
|
||||||
case 'f' :
|
|
||||||
c = '\f';
|
|
||||||
break;
|
|
||||||
case 'n' :
|
|
||||||
c = '\n';
|
|
||||||
break;
|
|
||||||
case 'r' :
|
|
||||||
c = '\r';
|
|
||||||
break;
|
|
||||||
case 't' :
|
|
||||||
c = '\t';
|
|
||||||
break;
|
|
||||||
case 'u' : // Unicode
|
case 'u' : // Unicode
|
||||||
{
|
{
|
||||||
Poco::Int32 unicode = decodeUnicode(istr);
|
Poco::Int32 unicode = decodeUnicode(istr);
|
||||||
@ -383,7 +367,7 @@ public:
|
|||||||
if ( c == -1 )
|
if ( c == -1 )
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
if ( Ascii::isDigit(c) )
|
if (Ascii::isDigit(c))
|
||||||
{
|
{
|
||||||
if ( c == '0' )
|
if ( c == '0' )
|
||||||
{
|
{
|
||||||
@ -397,14 +381,14 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( c == '-' )
|
if (c == '-')
|
||||||
{
|
{
|
||||||
_value = c;
|
_value = c;
|
||||||
|
|
||||||
int nc = istr.peek();
|
int nc = istr.peek();
|
||||||
if ( Ascii::isDigit(nc) )
|
if (Ascii::isDigit(nc))
|
||||||
{
|
{
|
||||||
if ( nc == '0' )
|
if (nc == '0')
|
||||||
{
|
{
|
||||||
_value += '0';
|
_value += '0';
|
||||||
istr.get();
|
istr.get();
|
||||||
@ -427,7 +411,7 @@ public:
|
|||||||
int c;
|
int c;
|
||||||
while( (c = istr.peek()) != -1)
|
while( (c = istr.peek()) != -1)
|
||||||
{
|
{
|
||||||
if ( Ascii::isDigit(c) )
|
if (Ascii::isDigit(c))
|
||||||
{
|
{
|
||||||
_value += c;
|
_value += c;
|
||||||
istr.get();
|
istr.get();
|
||||||
@ -438,7 +422,7 @@ public:
|
|||||||
{
|
{
|
||||||
case '.': // Float
|
case '.': // Float
|
||||||
{
|
{
|
||||||
if ( _activeClass == Token::FLOAT_LITERAL_TOKEN )
|
if (_activeClass == Token::FLOAT_LITERAL_TOKEN)
|
||||||
{
|
{
|
||||||
throw JSONException("Invalid float value");
|
throw JSONException("Invalid float value");
|
||||||
}
|
}
|
||||||
@ -459,7 +443,7 @@ public:
|
|||||||
case 'E':
|
case 'E':
|
||||||
case 'e':
|
case 'e':
|
||||||
{
|
{
|
||||||
if ( _activeClass == Token::DOUBLE_LITERAL_TOKEN )
|
if (_activeClass == Token::DOUBLE_LITERAL_TOKEN)
|
||||||
{
|
{
|
||||||
throw JSONException("Invalid double value");
|
throw JSONException("Invalid double value");
|
||||||
}
|
}
|
||||||
@ -471,14 +455,14 @@ public:
|
|||||||
|
|
||||||
// When the next char is - or + then read the next char
|
// When the next char is - or + then read the next char
|
||||||
c = istr.peek();
|
c = istr.peek();
|
||||||
if ( c == '-' || c == '+' )
|
if (c == '-' || c == '+')
|
||||||
{
|
{
|
||||||
_value += c;
|
_value += c;
|
||||||
istr.get();
|
istr.get();
|
||||||
c = istr.peek();
|
c = istr.peek();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( ! Ascii::isDigit(c) )
|
if (! Ascii::isDigit(c))
|
||||||
{
|
{
|
||||||
throw JSONException("Invalid double value");
|
throw JSONException("Invalid double value");
|
||||||
}
|
}
|
||||||
@ -520,7 +504,7 @@ Parser::~Parser()
|
|||||||
const Token* Parser::nextToken()
|
const Token* Parser::nextToken()
|
||||||
{
|
{
|
||||||
const Token* token = _tokenizer.next();
|
const Token* token = _tokenizer.next();
|
||||||
if ( token->is(Token::EOF_TOKEN) )
|
if (token->is(Token::EOF_TOKEN))
|
||||||
{
|
{
|
||||||
throw JSONException("Unexpected EOF found");
|
throw JSONException("Unexpected EOF found");
|
||||||
}
|
}
|
||||||
@ -533,14 +517,14 @@ void Parser::parse(std::istream& in)
|
|||||||
_tokenizer.attachToStream(in);
|
_tokenizer.attachToStream(in);
|
||||||
const Token* token = nextToken();
|
const Token* token = nextToken();
|
||||||
|
|
||||||
if ( token->is(Token::SEPARATOR_TOKEN) )
|
if (token->is(Token::SEPARATOR_TOKEN))
|
||||||
{
|
{
|
||||||
// This must be a { or a [
|
// This must be a { or a [
|
||||||
if ( token->asChar() == '{' )
|
if (token->asChar() == '{')
|
||||||
{
|
{
|
||||||
readObject();
|
readObject();
|
||||||
}
|
}
|
||||||
else if ( token->asChar() == '[' )
|
else if (token->asChar() == '[')
|
||||||
{
|
{
|
||||||
readArray();
|
readArray();
|
||||||
}
|
}
|
||||||
@ -549,7 +533,7 @@ void Parser::parse(std::istream& in)
|
|||||||
throw JSONException(format("Invalid separator '%c' found. Expecting { or [", token->asChar()));
|
throw JSONException(format("Invalid separator '%c' found. Expecting { or [", token->asChar()));
|
||||||
}
|
}
|
||||||
token = _tokenizer.next();
|
token = _tokenizer.next();
|
||||||
if ( ! token->is(Token::EOF_TOKEN) )
|
if (! token->is(Token::EOF_TOKEN))
|
||||||
{
|
{
|
||||||
throw JSONException(format("EOF expected but found '%s'", token->asString()));
|
throw JSONException(format("EOF expected but found '%s'", token->asString()));
|
||||||
}
|
}
|
||||||
@ -563,7 +547,7 @@ void Parser::parse(std::istream& in)
|
|||||||
|
|
||||||
void Parser::readObject()
|
void Parser::readObject()
|
||||||
{
|
{
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->startObject();
|
_handler->startObject();
|
||||||
}
|
}
|
||||||
@ -573,7 +557,7 @@ void Parser::readObject()
|
|||||||
while(readRow());
|
while(readRow());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->endObject();
|
_handler->endObject();
|
||||||
}
|
}
|
||||||
@ -584,12 +568,12 @@ bool Parser::readRow(bool firstCall)
|
|||||||
{
|
{
|
||||||
const Token* token = nextToken();
|
const Token* token = nextToken();
|
||||||
|
|
||||||
if ( firstCall && token->tokenClass() == Token::SEPARATOR_TOKEN && token->asChar() == '}' )
|
if (firstCall && token->tokenClass() == Token::SEPARATOR_TOKEN && token->asChar() == '}')
|
||||||
{
|
{
|
||||||
return false; // End of object is possible for an empty object
|
return false; // End of object is possible for an empty object
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( token->tokenClass() == Token::STRING_LITERAL_TOKEN )
|
if (token->tokenClass() == Token::STRING_LITERAL_TOKEN)
|
||||||
{
|
{
|
||||||
std::string propertyName = token->tokenString();
|
std::string propertyName = token->tokenString();
|
||||||
if ( _handler != NULL )
|
if ( _handler != NULL )
|
||||||
@ -599,20 +583,20 @@ bool Parser::readRow(bool firstCall)
|
|||||||
|
|
||||||
token = nextToken();
|
token = nextToken();
|
||||||
|
|
||||||
if ( token->is(Token::SEPARATOR_TOKEN)
|
if ( token->is(Token::SEPARATOR_TOKEN)
|
||||||
&& token->asChar() == ':' )
|
&& token->asChar() == ':')
|
||||||
{
|
{
|
||||||
readValue(nextToken());
|
readValue(nextToken());
|
||||||
|
|
||||||
token = nextToken();
|
token = nextToken();
|
||||||
|
|
||||||
if ( token->is(Token::SEPARATOR_TOKEN) )
|
if (token->is(Token::SEPARATOR_TOKEN))
|
||||||
{
|
{
|
||||||
if ( token->asChar() == ',' )
|
if (token->asChar() == ',')
|
||||||
{
|
{
|
||||||
return true; // Read next row
|
return true; // Read next row
|
||||||
}
|
}
|
||||||
else if ( token->asChar() == '}' )
|
else if (token->asChar() == '}')
|
||||||
{
|
{
|
||||||
return false; // End of object
|
return false; // End of object
|
||||||
}
|
}
|
||||||
@ -649,13 +633,13 @@ void Parser::readValue(const Token* token)
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case Token::INTEGER_LITERAL_TOKEN:
|
case Token::INTEGER_LITERAL_TOKEN:
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
#if defined(POCO_HAVE_INT64)
|
#if defined(POCO_HAVE_INT64)
|
||||||
Int64 value = token->asInteger64();
|
Int64 value = token->asInteger64();
|
||||||
// if number is 32-bit, then handle as such
|
// if number is 32-bit, then handle as such
|
||||||
if ( value > std::numeric_limits<int>::max()
|
if ( value > std::numeric_limits<int>::max()
|
||||||
|| value < std::numeric_limits<int>::min() )
|
|| value < std::numeric_limits<int>::min())
|
||||||
{
|
{
|
||||||
_handler->value(value);
|
_handler->value(value);
|
||||||
}
|
}
|
||||||
@ -671,23 +655,23 @@ void Parser::readValue(const Token* token)
|
|||||||
break;
|
break;
|
||||||
case Token::KEYWORD_TOKEN:
|
case Token::KEYWORD_TOKEN:
|
||||||
{
|
{
|
||||||
if ( token->tokenString().compare("null") == 0 )
|
if (token->tokenString().compare("null") == 0)
|
||||||
{
|
{
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->null();
|
_handler->null();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( token->tokenString().compare("true") == 0 )
|
else if (token->tokenString().compare("true") == 0)
|
||||||
{
|
{
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->value(true);
|
_handler->value(true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if ( token->tokenString().compare("false") == 0 )
|
else if (token->tokenString().compare("false") == 0)
|
||||||
{
|
{
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->value(false);
|
_handler->value(false);
|
||||||
}
|
}
|
||||||
@ -701,24 +685,24 @@ void Parser::readValue(const Token* token)
|
|||||||
case Token::FLOAT_LITERAL_TOKEN:
|
case Token::FLOAT_LITERAL_TOKEN:
|
||||||
// Fall through
|
// Fall through
|
||||||
case Token::DOUBLE_LITERAL_TOKEN:
|
case Token::DOUBLE_LITERAL_TOKEN:
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->value(token->asFloat());
|
_handler->value(token->asFloat());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Token::STRING_LITERAL_TOKEN:
|
case Token::STRING_LITERAL_TOKEN:
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->value(token->tokenString());
|
_handler->value(token->tokenString());
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
case Token::SEPARATOR_TOKEN:
|
case Token::SEPARATOR_TOKEN:
|
||||||
{
|
{
|
||||||
if ( token->asChar() == '{' )
|
if (token->asChar() == '{')
|
||||||
{
|
{
|
||||||
readObject();
|
readObject();
|
||||||
}
|
}
|
||||||
else if ( token->asChar() == '[' )
|
else if (token->asChar() == '[')
|
||||||
{
|
{
|
||||||
readArray();
|
readArray();
|
||||||
}
|
}
|
||||||
@ -732,17 +716,17 @@ void Parser::readValue(const Token* token)
|
|||||||
|
|
||||||
void Parser::readArray()
|
void Parser::readArray()
|
||||||
{
|
{
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->startArray();
|
_handler->startArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( readElements(true) ) // First call is special: check for empty array
|
if (readElements(true)) // First call is special: check for empty array
|
||||||
{
|
{
|
||||||
while(readElements());
|
while(readElements());
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( _handler != NULL )
|
if (_handler != NULL)
|
||||||
{
|
{
|
||||||
_handler->endArray();
|
_handler->endArray();
|
||||||
}
|
}
|
||||||
@ -753,7 +737,7 @@ bool Parser::readElements(bool firstCall)
|
|||||||
{
|
{
|
||||||
const Token* token = nextToken();
|
const Token* token = nextToken();
|
||||||
|
|
||||||
if ( firstCall && token->is(Token::SEPARATOR_TOKEN) && token->asChar() == ']' )
|
if (firstCall && token->is(Token::SEPARATOR_TOKEN) && token->asChar() == ']')
|
||||||
{
|
{
|
||||||
// End of array is possible for an empty array
|
// End of array is possible for an empty array
|
||||||
return false;
|
return false;
|
||||||
@ -765,10 +749,10 @@ bool Parser::readElements(bool firstCall)
|
|||||||
|
|
||||||
if ( token->is(Token::SEPARATOR_TOKEN) )
|
if ( token->is(Token::SEPARATOR_TOKEN) )
|
||||||
{
|
{
|
||||||
if ( token->asChar() == ']' )
|
if (token->asChar() == ']')
|
||||||
return false; // End of array
|
return false; // End of array
|
||||||
|
|
||||||
if ( token->asChar() == ',' )
|
if (token->asChar() == ',')
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
throw JSONException(format("Invalid separator '%c' found. Expecting , or ]", token->asChar()));
|
throw JSONException(format("Invalid separator '%c' found. Expecting , or ]", token->asChar()));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user