Skip to content

Commit 62ab94d

Browse files
committed
Merge pull request open-source-parsers#117 from datadiode/integration
Simplify Reader::decodeNumber() / Remove unused functions
2 parents 8f3aa22 + 09d352a commit 62ab94d

File tree

2 files changed

+2
-35
lines changed

2 files changed

+2
-35
lines changed

include/json/reader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ class JSON_API Reader {
187187

188188
typedef std::deque<ErrorInfo> Errors;
189189

190-
bool expectToken(TokenType type, Token& token, const char* message);
191190
bool readToken(Token& token);
192191
void skipSpaces();
193192
bool match(Location pattern, int patternLength);

src/lib_json/json_reader.cpp

Lines changed: 2 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -47,23 +47,6 @@ Features Features::strictMode() {
4747
// Implementation of class Reader
4848
// ////////////////////////////////
4949

50-
static inline bool in(Reader::Char c,
51-
Reader::Char c1,
52-
Reader::Char c2,
53-
Reader::Char c3,
54-
Reader::Char c4) {
55-
return c == c1 || c == c2 || c == c3 || c == c4;
56-
}
57-
58-
static inline bool in(Reader::Char c,
59-
Reader::Char c1,
60-
Reader::Char c2,
61-
Reader::Char c3,
62-
Reader::Char c4,
63-
Reader::Char c5) {
64-
return c == c1 || c == c2 || c == c3 || c == c4 || c == c5;
65-
}
66-
6750
static bool containsNewLine(Reader::Location begin, Reader::Location end) {
6851
for (; begin < end; ++begin)
6952
if (*begin == '\n' || *begin == '\r')
@@ -229,13 +212,6 @@ void Reader::skipCommentTokens(Token& token) {
229212
}
230213
}
231214

232-
bool Reader::expectToken(TokenType type, Token& token, const char* message) {
233-
readToken(token);
234-
if (token.type_ != type)
235-
return addError(message, token);
236-
return true;
237-
}
238-
239215
bool Reader::readToken(Token& token) {
240216
skipSpaces();
241217
token.start_ = current_;
@@ -517,20 +493,14 @@ bool Reader::decodeNumber(Token& token) {
517493
}
518494

519495
bool Reader::decodeNumber(Token& token, Value& decoded) {
520-
bool isDouble = false;
521-
for (Location inspect = token.start_; inspect != token.end_; ++inspect) {
522-
isDouble = isDouble || in(*inspect, '.', 'e', 'E', '+') ||
523-
(*inspect == '-' && inspect != token.start_);
524-
}
525-
if (isDouble)
526-
return decodeDouble(token, decoded);
527496
// Attempts to parse the number as an integer. If the number is
528497
// larger than the maximum supported value of an integer then
529498
// we decode the number as a double.
530499
Location current = token.start_;
531500
bool isNegative = *current == '-';
532501
if (isNegative)
533502
++current;
503+
// TODO: Help the compiler do the div and mod at compile time or get rid of them.
534504
Value::LargestUInt maxIntegerValue =
535505
isNegative ? Value::LargestUInt(-Value::minLargestInt)
536506
: Value::maxLargestUInt;
@@ -539,9 +509,7 @@ bool Reader::decodeNumber(Token& token, Value& decoded) {
539509
while (current < token.end_) {
540510
Char c = *current++;
541511
if (c < '0' || c > '9')
542-
return addError("'" + std::string(token.start_, token.end_) +
543-
"' is not a number.",
544-
token);
512+
return decodeDouble(token, decoded);
545513
Value::UInt digit(c - '0');
546514
if (value >= threshold) {
547515
// We've hit or exceeded the max value divided by 10 (rounded down). If

0 commit comments

Comments
 (0)