in johnzon-core/src/main/java/org/apache/johnzon/core/JsonStreamParserImpl.java [760:865]
private void readNumber() {
char c = buffer[bufferPos];
//start can change on any read() if we cross buffer boundary
startOfValueInBuffer = bufferPos;
endOfValueInBuffer = -1;
char y = EOF;
//sum up the digit values
int cumulatedDigitValue = 0;
while (isAsciiDigit(y = readNextChar())) {
if (c == ZERO) {
throw uexc("Leading zeros not allowed");
}
if (c == MINUS && cumulatedDigitValue == 48) {
throw uexc("Leading zeros after minus not allowed");
}
cumulatedDigitValue += y;
}
if (c == MINUS && cumulatedDigitValue == 0) {
throw uexc("Unexpected premature end of number");
}
if (y == DOT) {
isCurrentNumberIntegral = false;
cumulatedDigitValue = 0;
while (isAsciiDigit(y = readNextChar())) {
cumulatedDigitValue++;
}
if (cumulatedDigitValue == 0) {
throw uexc("Unexpected premature end of number");
}
}
if (y == EXP_LOWERCASE || y == EXP_UPPERCASE) {
isCurrentNumberIntegral = false;
y = readNextChar(); //+ or - or digit
if (!isAsciiDigit(y) && y != MINUS && y != PLUS) {
throw uexc("Expected DIGIT or + or -");
}
if (y == MINUS || y == PLUS) {
y = readNextChar();
if (!isAsciiDigit(y)) {
throw uexc("Unexpected premature end of number");
}
}
while (isAsciiDigit(y = readNextChar())) {
//no-op
}
}
endOfValueInBuffer = y == EOF && endOfValueInBuffer < 0 ? -1 : bufferPos;
if (y == COMMA_CHAR || y == END_ARRAY_CHAR || y == END_OBJECT_CHAR || y == EOL || y == SPACE || y == TAB || y == CR || y == EOF) {
unreadChar();//unread one char
//['-', DIGIT]
if (isCurrentNumberIntegral && c == MINUS && cumulatedDigitValue >= 48 && cumulatedDigitValue <= 57) {
currentIntegralNumber = -(cumulatedDigitValue - 48); //optimize -0 till -9
return;
}
//[DIGIT]
if (isCurrentNumberIntegral && c != MINUS && cumulatedDigitValue == 0) {
currentIntegralNumber = (c - 48); //optimize 0 till 9
return;
}
if (fallBackCopyBufferLength > 0) {
//we crossed a buffer boundary, use value buffer
copyCurrentValue();
} else {
if ((endOfValueInBuffer - startOfValueInBuffer) >= maxValueLength) {
throw tmc();
}
}
return;
}
throw uexc("Unexpected premature end of number");
}