public static SplitString ( string s ) : List |
||
s | string | |
return | List |
public static List<Word> SplitString(string s)
{
List<Word> lst = new List<Word>();
int pos = 0;
int len = s.Length;
while (pos < len)
{
char ch = s[pos];
int i = pos;
// first group has three different opportunities:
if (IsSpace(ch))
{
// one or more whitespace characters
while (i < len && IsSpace(s[i])) i++;
}
else if (IsText(ch))
{
// one or more text characters
while (i < len && IsText(s[i])) i++;
}
else
{
// one character, no matter what it is
i++;
}
string wordBody = s.Substring(pos, i - pos);
pos = i;
// second group: any whitespace character
while (i < len && IsSpace(s[i]))
{
i++;
}
string trail = s.Substring(pos, i - pos);
lst.Add(new Word(wordBody, trail));
pos = i;
}
return lst;
}
private void LineChanged(int leftLine, int rightLine) { // some kind of glitch with the diff engine if (LeftLines[leftLine] == RightLines[rightLine]) { ContextLine(rightLine); return; } StringBuilder left = new StringBuilder(); StringBuilder right = new StringBuilder(); List <Word> leftList = Word.SplitString(LeftLines[leftLine]); List <Word> rightList = Word.SplitString(RightLines[rightLine]); diff = new Diff(leftList, rightList, Word.Comparer); foreach (Diff.Hunk h in diff) { if (h.Same) { for (int i = 0; i < h.Left.Count; i++) { WhitespaceDiff(left, rightList[h.Right.Start + i], leftList[h.Left.Start + i]); WhitespaceDiff(right, leftList[h.Left.Start + i], rightList[h.Right.Start + i]); } } else { WordDiff(left, h.Left, h.Right, leftList, rightList); WordDiff(right, h.Right, h.Left, rightList, leftList); } } Result.AppendFormat(@"<tr onclick='window.external.GoTo({1})' ondblclick='window.external.UndoChange({0},{1})'> <td>-</td> <td class='diff-deletedline'>", leftLine, rightLine); Result.Append(left); Result.Append(@" </td> <td>+</td> <td class='diff-addedline'>"); Result.Append(right); Result.Append(@" </td> </tr>"); }