You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
using System;
-using System.Text.RegularExpressions;
-using System.Threading;
+using System.Text;
+using System.Globalization;
using System.Linq;
using System.Collections.Generic;
using System.Diagnostics;
return this.Lines[row].Index;
}
- internal LineToIndexTableData CreateLineToIndexTableData(int index, int length, bool lineend, SyntaxInfo[] syntax)
- {
- LineToIndexTableData result = new LineToIndexTableData(index, length, lineend,this.IsFrozneDirtyFlag == false, syntax);
- return result;
- }
-
internal void UpdateLineAsReplace(int row,int removedLength, int insertedLength)
{
int deltaLength = insertedLength - removedLength;
//挿入範囲内のドキュメントから行を生成する
SpilitStringEventArgs e = new SpilitStringEventArgs(this.Document, HeadIndex, analyzeLength, startRow);
- IList<LineToIndexTableData> newLines = SpilitString(this, e);
+ IList<LineToIndexTableData> newLines = this.CreateLineList(e.index, e.length, Document.MaximumLineLength);
//消すべき行が複数ある場合は消すが、そうでない場合は最適化のため長さを変えるだけにとどめておく
int removeCount = endRow - startRow + 1;
generator.Update(this.Document, index, insertedLength, removedLength);
}
+ internal IEnumerable<Tuple<int, int>> ForEachLines(int startIndex, int endIndex, int maxCharCount = -1)
+ {
+ int currentLineHeadIndex = startIndex;
+ int currentLineLength = 0;
+
+ for (int i = startIndex; i <= endIndex; i++)
+ {
+ currentLineLength++;
+ char c = this.Document[i];
+ if (c == Document.NewLine ||
+ (maxCharCount != -1 && currentLineLength >= maxCharCount))
+ {
+ UnicodeCategory uc = CharUnicodeInfo.GetUnicodeCategory(c);
+ if (uc != UnicodeCategory.NonSpacingMark &&
+ uc != UnicodeCategory.SpacingCombiningMark &&
+ uc != UnicodeCategory.EnclosingMark &&
+ uc != UnicodeCategory.Surrogate)
+ {
+ yield return new Tuple<int, int>(currentLineHeadIndex, currentLineLength);
+ currentLineHeadIndex += currentLineLength;
+ currentLineLength = 0;
+ }
+ }
+ }
+ if (currentLineLength > 0)
+ yield return new Tuple<int, int>(currentLineHeadIndex, currentLineLength);
+ }
+
+ IList<LineToIndexTableData> CreateLineList(int index, int length, int lineLimitLength = -1)
+ {
+ int startIndex = index;
+ int endIndex = index + length - 1;
+ List<LineToIndexTableData> output = new List<LineToIndexTableData>();
+
+ foreach (Tuple<int, int> range in this.ForEachLines(startIndex, endIndex, lineLimitLength))
+ {
+ int lineHeadIndex = range.Item1;
+ int lineLength = range.Item2;
+ char c = this.Document[lineHeadIndex + lineLength - 1];
+ bool hasNewLine = c == Document.NewLine;
+ LineToIndexTableData result = new LineToIndexTableData(lineHeadIndex, lineLength, hasNewLine, this.IsFrozneDirtyFlag == false, null);
+ output.Add(result);
+ }
+
+ if (output.Count > 0)
+ output.Last().LineEnd = true;
+
+ return output;
+ }
+
void GetRemoveRange(int index,int length,out int startRow,out int endRow)
{
startRow = this.GetLineNumberFromIndex(index);