From e3fd2184cbdfd828fc84384995a6b37ab661f596 Mon Sep 17 00:00:00 2001 From: Ronald Marcus Davenport Date: Sun, 14 Mar 2021 14:20:14 -0500 Subject: [PATCH] fixes #1030 and #1040 --- .gitignore | 1 + src/Humanizer/Inflections/Vocabularies.cs | 9 ++++----- src/Humanizer/Inflections/Vocabulary.cs | 7 ++++++- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/.gitignore b/.gitignore index 771f57f1f..bc00272fc 100644 --- a/.gitignore +++ b/.gitignore @@ -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 diff --git a/src/Humanizer/Inflections/Vocabularies.cs b/src/Humanizer/Inflections/Vocabularies.cs index 1cb90c0f7..f546aa7de 100644 --- a/src/Humanizer/Inflections/Vocabularies.cs +++ b/src/Humanizer/Inflections/Vocabularies.cs @@ -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"); @@ -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"); @@ -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"); diff --git a/src/Humanizer/Inflections/Vocabulary.cs b/src/Humanizer/Inflections/Vocabulary.cs index 084204cc4..e78ea5c71 100644 --- a/src/Humanizer/Inflections/Vocabulary.cs +++ b/src/Humanizer/Inflections/Vocabulary.cs @@ -145,7 +145,7 @@ private string ApplyRules(IList rules, string word, bool skipFirstRule) break; } } - return result; + return result != null ? MatchUpperCase(word, result) : result; } private bool IsUncountable(string word) @@ -153,6 +153,11 @@ 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;