double () { int p = peeked; if (p == PEEKED_NONE) { p = doPeek(); } if (p == PEEKED_LONG) { peeked = PEEKED_NONE; return (double)peekedLong; } if (p == PEEKED_NUMBER) { int end = position + peekedNumberLength; peekedString = sourceSequence.subSequence(position, end).toString(); position = end; } else if (p == PEEKED_SINGLE_QUOTED || p == PEEKED_DOUBLE_QUOTED) { peekedString = nextQuotedValue(p == PEEKED_SINGLE_QUOTED ? '\'' : '"'); } else if (p == PEEKED_UNQUOTED) { peekedString = nextUnquotedValue(); } else if (p != PEEKED_BUFFERED) { throw createParseError("Expected a double but was " + peek()); } peeked = PEEKED_BUFFERED; double result = Double.parseDouble(peekedString); // don't catch this NumberFormatException. if (!lenient && (Double.isNaN(result) || Double.isInfinite(result))) { throw createParseError("JSON forbids NaN and infinities: " + result); } peekedString = null; peeked = PEEKED_NONE; return result; }