Skip to content

Commit

Permalink
Use RegexOptions.Compiled if available
Browse files Browse the repository at this point in the history
  • Loading branch information
hazzik authored and MehdiK committed Dec 22, 2014
1 parent d5b6587 commit 0dcca61
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Humanizer/Humanizer.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
<Compile Include="Localisation\Ordinalizers\ItalianOrdinalizer.cs" />
<Compile Include="Localisation\Tense.cs" />
<Compile Include="Localisation\NumberToWords\SpanishNumberToWordsConverter.cs" />
<Compile Include="RegexOptionsUtil.cs" />
<Compile Include="TimeSpanHumanizeExtensions.cs" />
<Compile Include="FluentDate\In.SomeTimeFrom.cs">
<AutoGen>True</AutoGen>
Expand Down
2 changes: 1 addition & 1 deletion src/Humanizer/InflectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private class Rule

public Rule(string pattern, string replacement)
{
_regex = new Regex(pattern, RegexOptions.IgnoreCase);
_regex = new Regex(pattern, RegexOptions.IgnoreCase | RegexOptionsUtil.Compiled);
_replacement = replacement;
}

Expand Down
21 changes: 21 additions & 0 deletions src/Humanizer/RegexOptionsUtil.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using System.Text.RegularExpressions;

namespace Humanizer
{
internal static class RegexOptionsUtil
{
private static readonly RegexOptions _compiled;

static RegexOptionsUtil()
{
RegexOptions compiled;
_compiled = Enum.TryParse("Compiled", out compiled) ? compiled : RegexOptions.None;
}

public static RegexOptions Compiled
{
get { return _compiled; }
}
}
}
2 changes: 1 addition & 1 deletion src/Humanizer/RomanNumeralExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public static class RomanNumeralExtensions
private static readonly Regex ValidRomanNumeral =
new Regex(
"^(?i:(?=[MDCLXVI])((M{0,3})((C[DM])|(D?C{0,3}))?((X[LC])|(L?XX{0,2})|L)?((I[VX])|(V?(II{0,2}))|V)?))$",
RegexOptions.None);
RegexOptionsUtil.Compiled);

/// <summary>
/// Converts Roman numbers into integer
Expand Down
4 changes: 2 additions & 2 deletions src/Humanizer/StringHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ public static class StringHumanizeExtensions
static StringHumanizeExtensions()
{
PascalCaseWordPartsRegex = new Regex(@"[A-Z]?[a-z]+|[0-9]+|[A-Z]+(?=[A-Z][a-z]|[0-9]|\b)",
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture);
FreestandingSpacingCharRegex = new Regex(@"\s[-_]|[-_]\s");
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptionsUtil.Compiled);
FreestandingSpacingCharRegex = new Regex(@"\s[-_]|[-_]\s", RegexOptionsUtil.Compiled);
}

static string FromUnderscoreDashSeparatedWords (string input)
Expand Down

0 comments on commit 0dcca61

Please sign in to comment.