public override bool IncrementToken()
{
while (true)
{
if (!hasSavedState)
{
// process a new input word
if (!input.IncrementToken())
{
return false;
}
int termLength = termAttribute.Length();
char[] termBuffer = termAttribute.buffer();
accumPosInc += posIncAttribute.PositionIncrement;
iterator.setText(termBuffer, termLength);
iterator.next();
// word of no delimiters, or protected word: just return it
if ((iterator.current == 0 && iterator.end == termLength) || (protWords != null && protWords.contains(termBuffer, 0, termLength)))
{
posIncAttribute.PositionIncrement = accumPosInc;
accumPosInc = 0;
return true;
}
// word of simply delimiters
if (iterator.end == WordDelimiterIterator.DONE && !has(PRESERVE_ORIGINAL))
{
// if the posInc is 1, simply ignore it in the accumulation
if (posIncAttribute.PositionIncrement == 1)
{
accumPosInc--;
}
continue;
}
saveState();
hasOutputToken = false;
hasOutputFollowingOriginal = !has(PRESERVE_ORIGINAL);
lastConcatCount = 0;
if (has(PRESERVE_ORIGINAL))
{
posIncAttribute.PositionIncrement = accumPosInc;
accumPosInc = 0;
return true;
}
}
// at the end of the string, output any concatenations
if (iterator.end == WordDelimiterIterator.DONE)
{
if (!concat.Empty)
{
if (flushConcatenation(concat))
{
return true;
}
}
if (!concatAll.Empty)
{
// only if we haven't output this same combo above!
if (concatAll.subwordCount > lastConcatCount)
{
concatAll.writeAndClear();
return true;
}
concatAll.clear();
}
// no saved concatenations, on to the next input word
hasSavedState = false;
continue;
}
// word surrounded by delimiters: always output
if (iterator.SingleWord)
{
generatePart(true);
iterator.next();
return true;
}
int wordType = iterator.type();
// do we already have queued up incompatible concatenations?
if (!concat.Empty && (concat.type & wordType) == 0)
{
if (flushConcatenation(concat))
{
hasOutputToken = false;
return true;
}
hasOutputToken = false;
}
// add subwords depending upon options
if (shouldConcatenate(wordType))
{
if (concat.Empty)
{
concat.type = wordType;
}
concatenate(concat);
}
// add all subwords (catenateAll)
if (has(CATENATE_ALL))
{
concatenate(concatAll);
}
// if we should output the word or number part
if (shouldGenerateParts(wordType))
{
generatePart(false);
iterator.next();
return true;
}
iterator.next();
}
}