-
Notifications
You must be signed in to change notification settings - Fork 1
/
ReplacementUpdater.cs
39 lines (36 loc) · 1.22 KB
/
ReplacementUpdater.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
using System.Text.RegularExpressions;
namespace KeyValue3Updater
{
/// <summary>
/// Updater that replaces a block with an changed/new block
/// </summary>
internal abstract class ReplacementUpdater : Updater
{
public override string Process(ref string input)
{
string classname = GetType().Name;
Match match = findRegex.Match(input);
if (match == null || !match.Success)
{
Log($"[{classname}] Found 0 matches and did not update.");
}
while(match != null && match.Success)
{
Log($"[{classname}] Found match.");
input = ProcessMatch(ref input, match);
match = findRegex.Match(input);
}
return input;
}
/// <summary>
/// Process an individual match
/// </summary>
protected virtual string ProcessMatch(ref string input, Capture match)
{
string matchString = match.Value;
var replacement = GetReplacement(ref matchString);
return input.Replace(match.Value, replacement);
}
protected abstract string GetReplacement(ref string input);
}
}