Content () { if (!hasnext) { throw new NoSuchElementException("Cannot walk off end of Content"); } if (multitext != null && mtpos + 1 >= mtsize) { // finished this multitext. need to move on. multitext = null; resetMultiText(); } if (pendingmt != null) { // we have a multi-text pending from the last block // this will only be the case when the previous value was non-text. if (mtwasescape != null && fstack.getEscapeOutput() != mtwasescape.booleanValue()) { // we calculated pending with one escape strategy, but it changed... // we need to recalculate it.... mtsize = 0; mtwasescape = fstack.getEscapeOutput(); analyzeMultiText(pendingmt, 0, mtsourcesize); pendingmt.done(); } multitext = pendingmt; pendingmt = null; } if (multitext != null) { // OK, we have text-like content to push back. // and it still has values in it. // advance the cursor mtpos++; final Content ret = mttext[mtpos] == null ? mtdata[mtpos] : null; // we can calculate the hasnext hasnext = mtpos + 1 < mtsize || pending != null; // return null to indicate text content. return ret; } // non-text, increment and return content. final Content ret = pending; pending = content.hasNext() ? content.next() : null; // OK, we are returning some content. // we need to determine the state of the next loop. // cursor at this point has been advanced! if (pending == null) { hasnext = false; } else { // there is some more content. // we need to inspect it to determine whether it is good if (isTextLike(pending)) { // calculate what this next text-like content looks like. pendingmt = buildMultiText(false); analyzeMultiText(pendingmt, 0, mtsourcesize); pendingmt.done(); if (mtsize > 0) { hasnext = true; } else { // all white text... perhaps we need indenting anyway. // buildMultiText has moved on the pending value.... if (pending != null && newlineindent != null) { // yes, we need indenting. // redefine the pending. resetMultiText(); pendingmt = holdingmt; pendingmt.forceAppend(newlineindent); pendingmt.done(); hasnext = true; } else { pendingmt = null; hasnext = pending != null; } } } else { // it is non-text content... we have more content. // but, we just returned non-text content. We may need to indent if (newlineindent != null) { resetMultiText(); pendingmt = holdingmt; pendingmt.forceAppend(newlineindent); pendingmt.done(); } hasnext = true; } } return ret; }