Welcome to mirror list, hosted at ThFree Co, Russian Federation.

Patch.cs « MonoDevelop.Components.Diff « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: d724de82e9377d6621a8ac30ea32cd817000a484 (plain)
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
/*
 * Patches, a supporting class for Diffs
 */

using System;
using System.Collections;
using System.IO;
using System.Text;
using System.Xml;

namespace MonoDevelop.Components.Diff {
	
	public class Patch : IEnumerable {
		Hunk[] hunks;
		
		internal Patch(Hunk[] hunks) {
			this.hunks = hunks;
		}
		
		public class Hunk {
			object[] rightData;
			int leftstart, leftcount, rightstart, rightcount;
			bool same;
			
			internal Hunk(object[] rightData, int st, int c, int rs, int rc, bool s) {
				this.rightData = rightData;
				leftstart = st;
				leftcount = c;
				rightstart = rs;
				rightcount = rc;
				same = s;
			}
			
			public bool Same { get { return same; } }
			
			public int Start { get { return leftstart; } }
			public int Count { get { return leftcount; } }
			public int End { get { return leftstart+leftcount-1; } }
			
			public IList Right { get { if (same) return null; return new Range(rightData, rightstart, rightcount); } }
		}
		
		IEnumerator IEnumerable.GetEnumerator() {
			return hunks.GetEnumerator();
		}
		
		public IList Apply(IList original) {
			ArrayList right = new ArrayList();
			foreach (Hunk hunk in this) {
				if (hunk.Same)
					right.AddRange(new Range(original, hunk.Start, hunk.Count));
				else
					right.AddRange(hunk.Right);
			}
			return right;
		}
		
	}
}