Skip to content

Commit

Permalink
Merge branch 'regex-complied'
Browse files Browse the repository at this point in the history
  • Loading branch information
MehdiK committed Dec 22, 2014
2 parents d5b6587 + 002cb06 commit 9210e17
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 6 deletions.
5 changes: 3 additions & 2 deletions release_notes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
###In Development

- [#364](https://github.com/MehdiK/Humanizer/pull/364): Adding "campuses" as plural of "campus"
- [#364](https://github.com/MehdiK/Humanizer/pull/364): Added "campuses" as plural of "campus"
- [#363](https://github.com/MehdiK/Humanizer/pull/363): Use RegexOptions.Compiled if available

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.32.0...master)

Expand All @@ -18,7 +19,7 @@

###v1.31.0 - 2014-11-08
- [#340](https://github.com/MehdiK/Humanizer/pull/340): Fixed TimeSpan humanization precision skips units after the largest one when they're zero until it finds a non-zero unit
- [#347](https://github.com/MehdiK/Humanizer/pull/347): Changed één to 1 for dutch language.
- [#347](https://github.com/MehdiK/Humanizer/pull/347): Changed één to 1 for dutch language.

[Commits](https://github.com/MehdiK/Humanizer/compare/v1.30.0...v1.31.0)

Expand Down
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 9210e17

Please sign in to comment.