private final boolean readTextPrimary(char c) throws XMLStreamException
    {
        int ptr = mInputPtr;
        int start = ptr-1;

        // First: can we heuristically canonicalize ws used for indentation?
        if (c <= CHAR_SPACE) {
            int len = mInputEnd;
            /* Even without indentation removal, it's good idea to
             * 'convert' \r or \r\n into \n (by replacing or skipping first
             * char): this may allow reusing the buffer. 
             * But note that conversion MUST be enabled -- this is toggled
             * by code that includes internal entities, to prevent replacement
             * of CRs from int. general entities, as applicable.
             */
            do {
                // We'll need at least one char, no matter what:
                if (ptr < len && mNormalizeLFs) {
                    if (c == '\r') {
                        c = '\n';
                        if (mInputBuffer[ptr] == c) {
                            // Ok, whatever happens, can 'skip' \r, to point to following \n:
                            ++start;
                            // But if that's buffer end, can't skip that
                            if (++ptr >= len) {
                                break;
                            }
                        } else {
                            mInputBuffer[start] = c;
                        }
                    } else if (c != '\n') {
                        break;
                    }
                    markLF(ptr);
                    if (mCheckIndentation > 0) {
                        ptr = readIndentation(c, ptr);
                        if (ptr < 0) { // success!
                            return true;
                        }
                    }
                    // If we got this far, we skipped a lf, need to read next char
                    c = mInputBuffer[ptr++];
                }
            } while (false);

            // can we figure out indentation?
            mWsStatus = ALL_WS_UNKNOWN;
        } else {
            mWsStatus = ALL_WS_NO;
        }
        
        char[] inputBuf = mInputBuffer;
        int inputLen = mInputEnd;

        // Let's first see if we can just share input buffer:
        while (true) {
            if (c < CHAR_FIRST_PURE_TEXT) {
                if (c == '<') {
                    mInputPtr = --ptr;
                    mTextBuffer.resetWithShared(inputBuf, start, ptr-start);
                    return true;
                }
                if (c < CHAR_SPACE) {
                    if (c == '\n') {
                        markLF(ptr);
                    } else if (c == '\r') {
                        if (ptr >= inputLen) { // can't peek?
                            --ptr;
                            break;
                        }
                        if (mNormalizeLFs) { // can we do in-place Mac replacement?
                            if (inputBuf[ptr] == '\n') { // nope, 2 char lf
                                --ptr;
                                break;
                            }
                            /* This would otherwise be risky (may modify value of
                             * a shared entity value), but since DTDs are cached/accessed
                             * based on properties including lf-normalization there's no
                             * harm in 'fixing' it in place.
                             */
                            inputBuf[ptr-1] = '\n'; // yup
                        } else {
                            // No LF normalization... can we just skip it?
                            if (inputBuf[ptr] == '\n') {
                                ++ptr;
                            }
                        }
                        markLF(ptr);
                    } else if (c != '\t') {
                        // Should consume invalid char, but not include in result
                        mInputPtr = ptr;
                        mTextBuffer.resetWithShared(inputBuf, start, ptr-start-1);
                        /* Let's defer exception, provided we got at least
                         * one valid character (if not, better throw
                         * exception right away)
                         */
                        boolean deferErrors = (ptr - start) > 1;
                        mPendingException = throwInvalidSpace(c, deferErrors);
                        return true;
                    }
                } else if (c == '&') {
                    // Let's push it back and break
                    --ptr;
                   break;
                } else if (c == '>') {
                    // Let's see if we got ']]>'?
                    if ((ptr - start) >= 3) {
                        if (inputBuf[ptr-3] == ']' && inputBuf[ptr-2] == ']') {
                            /* Let's include ']]' in there, not '>' (since that
                             * makes it non-wellformed): but need to consume
                             * that char nonetheless
                             */
                            mInputPtr = ptr;
                            mTextBuffer.resetWithShared(inputBuf, start, ptr-start-1);
                            mPendingException = throwWfcException(ErrorConsts.ERR_BRACKET_IN_TEXT, true);
                            return true; // and we are fully done
                        }
                    }
                }
            } // if (char in lower code range)

            if (ptr >= inputLen) { // end-of-buffer?
                break;
            }
            c = inputBuf[ptr++];
        }
        mInputPtr = ptr;

        /* If we end up here, we either ran out of input, or hit something
         * which would leave 'holes' in buffer... fine, let's return then;
         * we can still update shared buffer copy: would be too early to
         * make a copy since caller may not even be interested in the
         * stuff.
         */
        mTextBuffer.resetWithShared(inputBuf, start, ptr - start);
        return false;
    }
private final boolean readTextPrimary ( char c ) throws XMLStreamException { int ptr = mInputPtr ; int start = ptr - 1 ; if ( c <= CHAR_SPACE ) { int len = mInputEnd ; do { if ( ptr < len && mNormalizeLFs ) { if ( c == '\r' ) { c = '\n' ; if ( mInputBuffer [ ptr ] == c ) { ++ start ; if ( ++ ptr >= len ) { break ; } } else { mInputBuffer [ start ] = c ; } } else if ( c != '\n' ) { break ; } markLF ( ptr ) ; if ( mCheckIndentation > 0 ) { ptr = readIndentation ( c , ptr ) ; if ( ptr < 0 ) { return true ; } } c = mInputBuffer [ ptr ++ ] ; } } while ( false ) ; mWsStatus = ALL_WS_UNKNOWN ; } else { mWsStatus = ALL_WS_NO ; } char [ ] inputBuf = mInputBuffer ; int inputLen = mInputEnd ; while ( true ) { if ( c < CHAR_FIRST_PURE_TEXT ) { if ( c == '<' ) { mInputPtr = -- ptr ; mTextBuffer . resetWithShared ( inputBuf , start , ptr - start ) ; return true ; } if ( c < CHAR_SPACE ) { if ( c == '\n' ) { markLF ( ptr ) ; } else if ( c == '\r' ) { if ( ptr >= inputLen ) { -- ptr ; break ; } if ( mNormalizeLFs ) { if ( inputBuf [ ptr ] == '\n' ) { -- ptr ; break ; } inputBuf [ ptr - 1 ] = '\n' ; } else { if ( inputBuf [ ptr ] == '\n' ) { ++ ptr ; } } markLF ( ptr ) ; } else if ( c != '\t' ) { mInputPtr = ptr ; mTextBuffer . resetWithShared ( inputBuf , start , ptr - start - 1 ) ; boolean deferErrors = ( ptr - start ) > 1 ; mPendingException = throwInvalidSpace ( c , deferErrors ) ; return true ; } } else if ( c == '&' ) { -- ptr ; break ; } else if ( c == '>' ) { if ( ( ptr - start ) >= 3 ) { if ( inputBuf [ ptr - 3 ] == ']' && inputBuf [ ptr - 2 ] == ']' ) { mInputPtr = ptr ; mTextBuffer . resetWithShared ( inputBuf , start , ptr - start - 1 ) ; mPendingException = throwWfcException ( ErrorConsts . ERR_BRACKET_IN_TEXT , true ) ; return true ; } } } } if ( ptr >= inputLen ) { break ; } c = inputBuf [ ptr ++ ] ; } mInputPtr = ptr ; mTextBuffer . resetWithShared ( inputBuf , start , ptr - start ) ; return false ; }
Method called to read in consecutive beginning parts of a text
segment, up to either end of the segment (lt char) or until
first 'hole' in text (buffer end, 2-char lf to convert, entity).
<p>
When the method is called, it's expected that the first character
has been read as is in the current input buffer just before current
pointer

@param c First character of the text segment

@return True if the whole text segment was completely read; this
happens only if lt-char is hit; false if it's possible that
it wasn't read (ie. end-of-buffer or entity encountered).