Skip to content

A generic sequence matching library, with an additional Harmony-IL-tailored sublibrary.

License

Notifications You must be signed in to change notification settings

Nanoray-pl/Shrike

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

63 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shrike

A generic sequence matching library, with an additional Harmony-IL-tailored sublibrary.

Installation

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+.

Usage examples

Finding a sequence of uppercase-only, then lowercase-only, then uppercase-only strings in a row, then removing that sequence

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();

Finding a specific element, then replacing the element two places after it with two other elements

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();

Finding a sequence of 1-, 2-, 3-, 4-, 5-long strings, anchoring the 3-long element, then removing it and its neighbors

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();

See also

About

A generic sequence matching library, with an additional Harmony-IL-tailored sublibrary.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages