Skip to content

Commit

Permalink
Add Flags + Pattern Constructor to Regex
Browse files Browse the repository at this point in the history
This allows creating patterns with a custom set of flags, whitout
having to manage the setate of an `Options` instance. This is useful
because `Options` is `IDisposable` and needs a bit of taking care of.

Fixes #11
  • Loading branch information
iwillspeak committed Dec 17, 2017
1 parent 7d627a8 commit f901696
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
7 changes: 7 additions & 0 deletions src/IronRure/Regex.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ public Regex(string pattern, Options opts)
: this(pattern, opts.Raw, (uint)DefaultFlags)
{}

/// <summary>
/// Create a new regex instance from the given pattern and flags.
/// </summary>
public Regex(string pattern, RureFlags flags)
: this(pattern, IntPtr.Zero, (uint)flags)
{}

/// <summary>
/// Create a new regex instance from the given pattern, with the given
/// options applied and with the given flags enabled.
Expand Down
9 changes: 9 additions & 0 deletions test/IronRureTests/RegexTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public void Regex_CreateWithFlags_Succeeds()
}
}

[Fact]
public void Regex_CreateWithFlagsOnly_Succeeds()
{
using (var reg = new Regex(@"Δ", RureFlags.Unicode | RureFlags.Casei))
{
Assert.True(reg.IsMatch("δ"));
}
}

[Fact]
public void Regex_CreateWithInvalidPattern_ThrowsException()
{
Expand Down

0 comments on commit f901696

Please sign in to comment.