Skip to content

Commit

Permalink
Merge pull request #1078 from MrAsminaf/titleCasingFix
Browse files Browse the repository at this point in the history
Fixed title casing for multiple upper case strings #1050
  • Loading branch information
clairernovotny authored Jun 7, 2021
2 parents 4578588 + f2f89e0 commit 6cc2dff
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/Humanizer.Tests.Shared/StringHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ public void CanHumanizeStringWithAcronyms(string input, string expectedValue)
[InlineData("Title_humanization_Honors_ALLCAPS", "Title Humanization Honors ALLCAPS")]
[InlineData("MühldorferStraße23", "Mühldorfer Straße 23")]
[InlineData("mühldorfer_STRAẞE_23", "Mühldorfer STRAẞE 23")]
[InlineData("CAN RETURN TITLE CASE", "Can Return Title Case")]
public void CanHumanizeIntoTitleCase(string input, string expectedResult)
{
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Title));
Expand Down
6 changes: 6 additions & 0 deletions src/Humanizer/StringHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,12 @@ private static string FromPascalCase(string input)
? match.Value
: match.Value.ToLower()));

if (result.Replace(" ", "").ToCharArray().All(c => char.IsUpper(c)) &&
result.Contains(" "))
{
result = result.ToLower();
}

return result.Length > 0 ? char.ToUpper(result[0]) +
result.Substring(1, result.Length - 1) : result;
}
Expand Down

0 comments on commit 6cc2dff

Please sign in to comment.