-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathConversion.cs
73 lines (67 loc) · 1.95 KB
/
Conversion.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
71
72
73
using System;
using System.Linq;
using System.Collections.Generic;
namespace patchiron
{
public class Conversion
{
PatchChunk? ChunkWithUsing = null;
int? UsingLine = null;
int DiffsRemaining = 0;
// Add patching logic here.
public void ProcessChunk (PatchChunk chunk, string fileName)
{
List<Range> diffs = chunk.CalculateDiffs ();
// For each range in diff
// If one line, and text is "using System.Runtime.Versioning;" then note
// Else if multiple lines, and the line after it is "partial class" then remove it
// Else keep
// If we removed all bits in diff but the using is gone, also remove it
DiffsRemaining += diffs.Count;
foreach (var range in diffs)
{
bool processed = false;
if (range.High - range.Low == 1) {
switch (chunk.Lines[range.Low].Trim ()) {
case "-using System.Runtime.Versioning;":
if (UsingLine != null) {
throw new InvalidOperationException ("More than one using?");
}
UsingLine = range.Low;
ChunkWithUsing = chunk;
// Flip it now, we'll flip back later if needed
// processed = true;
break;
case "-":
// Remove whitespace diff while we're here
DiffsRemaining -= 1;
processed = true;
break;
}
}
else {
// if multiple lines, and the line after it is "partial class" then remove it
// Else keep
string lineAfterChunk = chunk.Lines [range.High];
if (lineAfterChunk.Contains ("partial") && lineAfterChunk.Contains ("class")) {
DiffsRemaining -= 1;
processed = true;
}
}
if (!processed) {
for (int i = range.Low; i < range.High; ++i) {
chunk.FlipFirstCharacter (i, ' ');
}
}
}
}
public void ProcessPart (PatchPart part)
{
if (DiffsRemaining == 1 && UsingLine != null) {
ChunkWithUsing!.FlipFirstCharacter (UsingLine.Value, '-');
DiffsRemaining -= 1;
}
}
public bool ShouldDrop => DiffsRemaining != 0;
}
}