internal void ReplaceRegexAll(LineToIndexTable layoutlines, Regex regex, string pattern, bool groupReplace) { for (int i = 0; i < layoutlines.Count; i++) { int lineHeadIndex = layoutlines.GetIndexFromLineNumber(i), lineLength = layoutlines.GetLengthFromLineNumber(i); int left = lineHeadIndex, right = lineHeadIndex; string output; output = regex.Replace(layoutlines[i], (m) => { if (groupReplace) { return(m.Result(pattern)); } else { return(pattern); } }); using (this.rwlock.WriterLock()) { //空行は削除する必要はない if (lineHeadIndex < this.buf.Count) { this.buf.RemoveRange(lineHeadIndex, lineLength); } this.buf.InsertRange(lineHeadIndex, output); } this.Update(this, new DocumentUpdateEventArgs(UpdateType.Replace, lineHeadIndex, lineLength, output.Length, i)); } }
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)); } }