Lucene.Net.Analysis.Cjk.CJKBigramFilter.Refill C# (CSharp) Method

Refill() private method

refills buffers with new data from the current token.
private Refill ( ) : void
return void
        private void Refill()
        {
            // compact buffers to keep them smallish if they become large
            // just a safety check, but technically we only need the last codepoint
            if (bufferLen > 64)
            {
                int last = bufferLen - 1;
                buffer[0] = buffer[last];
                startOffset[0] = startOffset[last];
                endOffset[0] = endOffset[last];
                bufferLen = 1;
                index -= last;
            }

            char[] termBuffer = termAtt.Buffer();
            int len = termAtt.Length;
            int start = offsetAtt.StartOffset();
            int end = offsetAtt.EndOffset();

            int newSize = bufferLen + len;
            buffer = ArrayUtil.Grow(buffer, newSize);
            startOffset = ArrayUtil.Grow(startOffset, newSize);
            endOffset = ArrayUtil.Grow(endOffset, newSize);
            lastEndOffset = end;

            if (end - start != len)
            {
                // crazy offsets (modified by synonym or charfilter): just preserve
                for (int i = 0, cp = 0; i < len; i += Character.CharCount(cp))
                {
                    cp = buffer[bufferLen] = Character.CodePointAt(termBuffer, i, len);
                    startOffset[bufferLen] = start;
                    endOffset[bufferLen] = end;
                    bufferLen++;
                }
            }
            else
            {
                // normal offsets
                for (int i = 0, cp = 0, cpLen = 0; i < len; i += cpLen)
                {
                    cp = buffer[bufferLen] = Character.CodePointAt(termBuffer, i, len);
                    cpLen = Character.CharCount(cp);
                    startOffset[bufferLen] = start;
                    start = endOffset[bufferLen] = start + cpLen;
                    bufferLen++;
                }
            }
        }