internal int IndexOf(string target, int start, bool ci = false)
 {
     using (this.rwlock.ReaderLock())
     {
         TextSearch ts           = new TextSearch(target, ci);
         int        patternIndex = ts.IndexOf(this.buf, start, this.buf.Count);
         return(patternIndex);
     }
 }
        internal void ReplaceAll(LineToIndexTable layoutlines, string target, string pattern, bool ci = false)
        {
            TextSearch ts = new TextSearch(target, ci);

            char[] pattern_chars = pattern.ToCharArray();
            for (int i = 0; i < layoutlines.Count; i++)
            {
                int lineHeadIndex = layoutlines.GetIndexFromLineNumber(i), lineLength = layoutlines.GetLengthFromLineNumber(i);
                int left = lineHeadIndex, right = lineHeadIndex;
                int newLineLength = lineLength;
                while ((right = ts.IndexOf(this.buf, left, lineHeadIndex + newLineLength)) != -1)
                {
                    using (this.rwlock.WriterLock())
                    {
                        this.buf.RemoveRange(right, target.Length);
                        this.buf.InsertRange(right, pattern_chars);
                    }
                    left           = right + pattern.Length;
                    newLineLength += pattern.Length - target.Length;
                }

                this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, newLineLength, i));
            }
        }