Skip to content

Commit

Permalink
Merge pull request #1041 from GatorEcho/fix-1030
Browse files Browse the repository at this point in the history
fixes #1030 and #1040
  • Loading branch information
clairernovotny authored Apr 23, 2021
2 parents 5b70457 + e3fd218 commit daa8781
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -96,3 +96,4 @@ src/Humanizer.Tests/ApiApprover/PublicApiApprovalTest.approve_public_api.receive

.DS_Store
/samples/Humanizer.MvcSample/Humanizer.MvcSample.sln
/src/Humanizer/Properties/launchSettings.json
9 changes: 4 additions & 5 deletions src/Humanizer/Inflections/Vocabularies.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ private static Vocabulary BuildDefault()
_default.AddPlural("(hive)$", "$1s");
_default.AddPlural("([^aeiouy]|qu)y$", "$1ies");
_default.AddPlural("(x|ch|ss|sh)$", "$1es");
_default.AddPlural("(matr|vert|ind|d)ix|ex$", "$1ices");
_default.AddPlural("(matr|vert|ind|d)(ix|ex)$", "$1ices");
_default.AddPlural("(^[m|l])ouse$", "$1ice");
_default.AddPlural("^(ox)$", "$1en");
_default.AddPlural("(quiz)$", "$1zes");
Expand Down Expand Up @@ -83,7 +83,6 @@ private static Vocabulary BuildDefault()
_default.AddIrregular("move", "moves");
_default.AddIrregular("goose", "geese");
_default.AddIrregular("wave", "waves");
_default.AddIrregular("die", "dice");
_default.AddIrregular("foot", "feet");
_default.AddIrregular("tooth", "teeth");
_default.AddIrregular("curriculum", "curricula");
Expand All @@ -95,14 +94,14 @@ private static Vocabulary BuildDefault()

//Fix 975
_default.AddIrregular("ex", "exes", matchEnding: false);

_default.AddIrregular("is", "are", matchEnding: false);
_default.AddIrregular("that", "those", matchEnding: false);
_default.AddIrregular("this", "these", matchEnding: false);
_default.AddIrregular("bus", "buses", matchEnding: false);
_default.AddIrregular("staff", "staff", matchEnding: false);
_default.AddIrregular("training", "training", matchEnding: false);
_default.AddIrregular("die", "dice", matchEnding: false);

_default.AddUncountable("staff");
_default.AddUncountable("training");
_default.AddUncountable("equipment");
_default.AddUncountable("information");
_default.AddUncountable("corn");
Expand Down
7 changes: 6 additions & 1 deletion src/Humanizer/Inflections/Vocabulary.cs
Original file line number Diff line number Diff line change
Expand Up @@ -145,14 +145,19 @@ private string ApplyRules(IList<Rule> rules, string word, bool skipFirstRule)
break;
}
}
return result;
return result != null ? MatchUpperCase(word, result) : result;
}

private bool IsUncountable(string word)
{
return _uncountables.Contains(word.ToLower());
}

private string MatchUpperCase(string word, string replacement)
{
return char.IsUpper(word[0]) && char.IsLower(replacement[0]) ? char.ToUpper(replacement[0]) + replacement.Substring(1) : replacement;
}

private class Rule
{
private readonly Regex _regex;
Expand Down

0 comments on commit daa8781

Please sign in to comment.