src/main/java/com/bazaarvoice/jackson/rison/RisonParser.java
private JsonToken parseNumberText2(boolean negative)
            throws IOException, JsonParseException
    {
        char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
        int outPtr = 0;

        // Need to prepend sign?
        if (negative) {
            outBuf[outPtr++] = '-';
        }

        // This is the place to do leading-zero check(s) too:
        int intLen = 0;
        char c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++] : getNextChar("No digit following minus sign");
        if (c == '0') {
            c = _verifyNoLeadingZeroes();
        }
        boolean eof = false;

        // Ok, first the obligatory integer part:
        int_loop:
        while (c >= '0' && c <= '9') {
            ++intLen;
            if (outPtr >= outBuf.length) {
                outBuf = _textBuffer.finishCurrentSegment();
                outPtr = 0;
            }
            outBuf[outPtr++] = c;
            if (_inputPtr >= _inputEnd && !loadMore()) {
                // EOF is legal for main level int values
                c = CHAR_NULL;
                eof = true;
                break int_loop;
            }
            c = _inputBuffer[_inputPtr++];
        }
        // Also, integer part is not optional
        if (intLen == 0) {
            reportInvalidNumber("Missing integer part (next char "+_getCharDesc(c)+")");
        }

        int fractLen = 0;
        // And then see if we get other parts
        if (c == '.') { // yes, fraction
            outBuf[outPtr++] = c;

            fract_loop:
            while (true) {
                if (_inputPtr >= _inputEnd && !loadMore()) {
                    eof = true;
                    break fract_loop;
                }
                c = _inputBuffer[_inputPtr++];
                if (c < INT_0 || c > INT_9) {
                    break fract_loop;
                }
                ++fractLen;
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
            }
            // must be followed by sequence of ints, one minimum
            if (fractLen == 0) {
                reportUnexpectedNumberChar(c, "Decimal point not followed by a digit");
            }
        }

        int expLen = 0;
        if (c == 'e' || c == 'E') { // exponent?
            if (outPtr >= outBuf.length) {
                outBuf = _textBuffer.finishCurrentSegment();
                outPtr = 0;
            }
            outBuf[outPtr++] = c;
            // Not optional, can require that we get one more char
            c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++]
                    : getNextChar("expected a digit for number exponent");
            // Sign indicator?
            if (c == '-' || c == '+') {
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
                // Likewise, non optional:
                c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++]
                        : getNextChar("expected a digit for number exponent");
            }

            exp_loop:
            while (c <= INT_9 && c >= INT_0) {
                ++expLen;
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
                if (_inputPtr >= _inputEnd && !loadMore()) {
                    eof = true;
                    break exp_loop;
                }
                c = _inputBuffer[_inputPtr++];
            }
            // must be followed by sequence of ints, one minimum
            if (expLen == 0) {
                reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit");
            }
        }

        // Ok; unless we hit end-of-input, need to push last char read back
        if (!eof) {
            --_inputPtr;
        }
        _textBuffer.setCurrentLength(outPtr);
        // And there we have it!
        return reset(negative, intLen, fractLen, expLen);
    }
private JsonToken parseNumberText2(boolean negative)
            throws IOException, JsonParseException
    {
        char[] outBuf = _textBuffer.emptyAndGetCurrentSegment();
        int outPtr = 0;

        // Need to prepend sign?
        if (negative) {
            outBuf[outPtr++] = '-';
        }

        // This is the place to do leading-zero check(s) too:
        int intLen = 0;
        char c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++] : getNextChar("No digit following minus sign");
        if (c == '0') {
            c = _verifyNoLeadingZeroes();
        }
        boolean eof = false;

        // Ok, first the obligatory integer part:
        int_loop:
        while (c >= '0' && c <= '9') {
            ++intLen;
            if (outPtr >= outBuf.length) {
                outBuf = _textBuffer.finishCurrentSegment();
                outPtr = 0;
            }
            outBuf[outPtr++] = c;
            if (_inputPtr >= _inputEnd && !loadMore()) {
                // EOF is legal for main level int values
                c = CHAR_NULL;
                eof = true;
                break int_loop;
            }
            c = _inputBuffer[_inputPtr++];
        }
        // Also, integer part is not optional
        if (intLen == 0) {
            reportInvalidNumber("Missing integer part (next char "+_getCharDesc(c)+")");
        }

        int fractLen = 0;
        // And then see if we get other parts
        if (c == '.') { // yes, fraction
            outBuf[outPtr++] = c;

            fract_loop:
            while (true) {
                if (_inputPtr >= _inputEnd && !loadMore()) {
                    eof = true;
                    break fract_loop;
                }
                c = _inputBuffer[_inputPtr++];
                if (c < INT_0 || c > INT_9) {
                    break fract_loop;
                }
                ++fractLen;
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
            }
            // must be followed by sequence of ints, one minimum
            if (fractLen == 0) {
                reportUnexpectedNumberChar(c, "Decimal point not followed by a digit");
            }
        }

        int expLen = 0;
        if (c == 'e' || c == 'E') { // exponent?
            if (outPtr >= outBuf.length) {
                outBuf = _textBuffer.finishCurrentSegment();
                outPtr = 0;
            }
            outBuf[outPtr++] = c;
            // Not optional, can require that we get one more char
            c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++]
                    : getNextChar("expected a digit for number exponent");
            // Sign indicator?
            if (c == '-' || c == '+') {
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
                // Likewise, non optional:
                c = (_inputPtr < _inputEnd) ? _inputBuffer[_inputPtr++]
                        : getNextChar("expected a digit for number exponent");
            }

            exp_loop:
            while (c <= INT_9 && c >= INT_0) {
                ++expLen;
                if (outPtr >= outBuf.length) {
                    outBuf = _textBuffer.finishCurrentSegment();
                    outPtr = 0;
                }
                outBuf[outPtr++] = c;
                if (_inputPtr >= _inputEnd && !loadMore()) {
                    eof = true;
                    break exp_loop;
                }
                c = _inputBuffer[_inputPtr++];
            }
            // must be followed by sequence of ints, one minimum
            if (expLen == 0) {
                reportUnexpectedNumberChar(c, "Exponent indicator not followed by a digit");
            }
        }

        // Ok; unless we hit end-of-input, need to push last char read back
        if (!eof) {
            --_inputPtr;
        }
        _textBuffer.setCurrentLength(outPtr);
        // And there we have it!
        return reset(negative, intLen, fractLen, expLen);
    }
private JsonToken parseNumberText2 ( boolean negative ) throws IOException , JsonParseException { char [ ] outBuf = _textBuffer . emptyAndGetCurrentSegment ( ) ; int outPtr = 0 ; // Need to prepend sign? if ( negative ) { outBuf [ outPtr ++ ] = ' ' ; } // This is the place to do leading-zero check(s) too: int intLen = 0 ; char c = ( _inputPtr < _inputEnd ) ? _inputBuffer [ _inputPtr ++ ] : getNextChar ( "No digit following minus sign" ) ; if ( c == ' ' ) { c = _verifyNoLeadingZeroes ( ) ; } boolean eof = false ; // Ok, first the obligatory integer part: int_loop : while ( c >= ' ' && c <= ' ' ) { ++ intLen ; if ( outPtr >= outBuf . length ) { outBuf = _textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outBuf [ outPtr ++ ] = c ; if ( _inputPtr >= _inputEnd && ! loadMore ( ) ) { // EOF is legal for main level int values c = CHAR_NULL ; eof = true ; break int_loop ; } c = _inputBuffer [ _inputPtr ++ ] ; } // Also, integer part is not optional if ( intLen == 0 ) { reportInvalidNumber ( "Missing integer part (next char " + _getCharDesc ( c ) + ")" ) ; } int fractLen = 0 ; // And then see if we get other parts if ( c == ' ' ) { // yes, fraction outBuf [ outPtr ++ ] = c ; fract_loop : while ( true ) { if ( _inputPtr >= _inputEnd && ! loadMore ( ) ) { eof = true ; break fract_loop ; } c = _inputBuffer [ _inputPtr ++ ] ; if ( c < INT_0 || c > INT_9 ) { break fract_loop ; } ++ fractLen ; if ( outPtr >= outBuf . length ) { outBuf = _textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outBuf [ outPtr ++ ] = c ; } // must be followed by sequence of ints, one minimum if ( fractLen == 0 ) { reportUnexpectedNumberChar ( c , "Decimal point not followed by a digit" ) ; } } int expLen = 0 ; if ( c == ' ' || c == ' ' ) { // exponent? if ( outPtr >= outBuf . length ) { outBuf = _textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outBuf [ outPtr ++ ] = c ; // Not optional, can require that we get one more char c = ( _inputPtr < _inputEnd ) ? _inputBuffer [ _inputPtr ++ ] : getNextChar ( "expected a digit for number exponent" ) ; // Sign indicator? if ( c == ' ' || c == ' ' ) { if ( outPtr >= outBuf . length ) { outBuf = _textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outBuf [ outPtr ++ ] = c ; // Likewise, non optional: c = ( _inputPtr < _inputEnd ) ? _inputBuffer [ _inputPtr ++ ] : getNextChar ( "expected a digit for number exponent" ) ; } exp_loop : while ( c <= INT_9 && c >= INT_0 ) { ++ expLen ; if ( outPtr >= outBuf . length ) { outBuf = _textBuffer . finishCurrentSegment ( ) ; outPtr = 0 ; } outBuf [ outPtr ++ ] = c ; if ( _inputPtr >= _inputEnd && ! loadMore ( ) ) { eof = true ; break exp_loop ; } c = _inputBuffer [ _inputPtr ++ ] ; } // must be followed by sequence of ints, one minimum if ( expLen == 0 ) { reportUnexpectedNumberChar ( c , "Exponent indicator not followed by a digit" ) ; } } // Ok; unless we hit end-of-input, need to push last char read back if ( ! eof ) { -- _inputPtr ; } _textBuffer . setCurrentLength ( outPtr ) ; // And there we have it! return reset ( negative , intLen , fractLen , expLen ) ; }
Method called to parse a number, when the primary parse
method has failed to parse it, due to it being split on
buffer boundary. As a result code is very similar, except
that it has to explicitly copy contents to the text buffer
instead of just sharing the main input buffer.
Method called to parse a number when the primary parse method has failed to parse it due to it being split on buffer boundary . As a result code is very similar except that it has to explicitly copy contents to the text buffer instead of just sharing the main input buffer .