Ejemplo n.º 1
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: @Override public final boolean incrementToken() throws java.io.IOException
        public override bool incrementToken()
        {
            clearAttributes();
            termAtt.append(resultToken);
            if (resultToken.Length == 0)
            {
                posAtt.PositionIncrement = 1;
            }
            else
            {
                posAtt.PositionIncrement = 0;
            }
            int  length = 0;
            bool added  = false;

            if (endDelimiter)
            {
                termAtt.append(replacement);
                length++;
                endDelimiter = false;
                added        = true;
            }

            while (true)
            {
                int c = input.read();
                if (c >= 0)
                {
                    charsRead++;
                }
                else
                {
                    if (skipped > skip)
                    {
                        length        += resultToken.Length;
                        termAtt.Length = length;
                        offsetAtt.setOffset(correctOffset(startPosition), correctOffset(startPosition + length));
                        if (added)
                        {
                            resultToken.Length = 0;
                            resultToken.Append(termAtt.buffer(), 0, length);
                        }
                        return(added);
                    }
                    else
                    {
                        return(false);
                    }
                }
                if (!added)
                {
                    added = true;
                    skipped++;
                    if (skipped > skip)
                    {
                        termAtt.append(c == delimiter ? replacement : (char)c);
                        length++;
                    }
                    else
                    {
                        startPosition++;
                    }
                }
                else
                {
                    if (c == delimiter)
                    {
                        if (skipped > skip)
                        {
                            endDelimiter = true;
                            break;
                        }
                        skipped++;
                        if (skipped > skip)
                        {
                            termAtt.append(replacement);
                            length++;
                        }
                        else
                        {
                            startPosition++;
                        }
                    }
                    else
                    {
                        if (skipped > skip)
                        {
                            termAtt.append((char)c);
                            length++;
                        }
                        else
                        {
                            startPosition++;
                        }
                    }
                }
            }
            length        += resultToken.Length;
            termAtt.Length = length;
            offsetAtt.setOffset(correctOffset(startPosition), correctOffset(startPosition + length));
            resultToken.Length = 0;
            resultToken.Append(termAtt.buffer(), 0, length);
            return(true);
        }