A generic sequence matching library, with an additional IL-tailored sublibrary.
$ dotnet add package ShrikeA generic sequence matching library, with an additional Harmony-IL-tailored sublibrary.
Reference the Nanoray.Shrike NuGet package in your project.
The NuGet package is compatible with .NET 5+, with some small API changes when using with .NET 7+.
ElementMatch<string> uppercase = new("uppercase", e => e.ToUpper() == e);
ElementMatch<string> lowercase = new("lowercase", e => e.ToLower() == e);
IEnumerable<string> newElements = new SequenceBlockMatcher<string>(
"lorem ipsum dolor sit amet",
"THE QUICK BROWN FOX JUMPS OVER THE LAZY DOG",
"oak is strong and also gives shade",
"CATS AND DOGS EACH HATE THE OTHER",
"the pipe began to rust while new"
)
.Find(uppercase, lowercase, uppercase)
.Remove()
.AllElements();
IEnumerable<string> newElements = new SequenceBlockMatcher<string>(
"a", "b", "c", "d", "e", "f"
)
.Find(new ElementMatch<string>("c"))
.PointerMatcher(SequenceMatcherRelativeElement.First)
.Advance(2)
.Replace("1", "2")
.AllElements();
IEnumerable<string> newElements = new SequenceBlockMatcher<string>(
"a", "bb", "ccc", "dd", "e", "ff", "ggg", "hhhh", "iiiii", "jjjj", "kkk", "ll", "m", "nn", "ooo", "pp", "q"
).AsGuidAnchorable()
.Find(
new ElementMatch<string>("1-long", e => e.Length == 1),
new ElementMatch<string>("2-long", e => e.Length == 2),
new ElementMatch<string>("3-long", e => e.Length == 3).WithAutoAnchor(out Guid anchor),
new ElementMatch<string>("4-long", e => e.Length == 4),
new ElementMatch<string>("5-long", e => e.Length == 5)
)
.PointerMatcher(anchor)
.Encompass(SequenceMatcherEncompassDirection.Both, 1)
.Remove()
.AllElements();