-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathTextDiff.cs
70 lines (52 loc) · 1.59 KB
/
TextDiff.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
namespace Menees.Diffs
{
#region Using Directives
using System;
using System.Collections.Generic;
#endregion
/// <summary>
/// This class uses the MyersDiff helper class to difference two
/// string lists. It hashes each string in both lists and then
/// differences the resulting integer arrays.
/// </summary>
public sealed class TextDiff
{
#region Private Data Members
private readonly bool supportChangeEditType;
private readonly StringHasher hasher;
#endregion
#region Constructors
public TextDiff(HashType hashType, bool ignoreCase, bool ignoreOuterWhiteSpace)
: this(hashType, ignoreCase, ignoreOuterWhiteSpace, 0, true)
{
}
public TextDiff(HashType hashType, bool ignoreCase, bool ignoreOuterWhiteSpace, int leadingCharactersToIgnore, bool supportChangeEditType)
{
this.hasher = new StringHasher(hashType, ignoreCase, ignoreOuterWhiteSpace, leadingCharactersToIgnore);
this.supportChangeEditType = supportChangeEditType;
}
#endregion
#region Public Methods
public EditScript Execute(IList<string> listA, IList<string> listB)
{
int[] hashA = this.HashStringList(listA);
int[] hashB = this.HashStringList(listB);
MyersDiff<int> diff = new(hashA, hashB, this.supportChangeEditType);
EditScript result = diff.Execute();
return result;
}
#endregion
#region Private Methods
private int[] HashStringList(IList<string> lines)
{
int numLines = lines.Count;
int[] result = new int[numLines];
for (int i = 0; i < numLines; i++)
{
result[i] = this.hasher.GetHashCode(lines[i]);
}
return result;
}
#endregion
}
}