Skip to content

Commit 6cc2dff

Browse files
Merge pull request #1078 from MrAsminaf/titleCasingFix
Fixed title casing for multiple upper case strings #1050
2 parents 4578588 + f2f89e0 commit 6cc2dff

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

src/Humanizer.Tests.Shared/StringHumanizeTests.cs

+1
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ public void CanHumanizeStringWithAcronyms(string input, string expectedValue)
7474
[InlineData("Title_humanization_Honors_ALLCAPS", "Title Humanization Honors ALLCAPS")]
7575
[InlineData("MühldorferStraße23", "Mühldorfer Straße 23")]
7676
[InlineData("mühldorfer_STRAẞE_23", "Mühldorfer STRAẞE 23")]
77+
[InlineData("CAN RETURN TITLE CASE", "Can Return Title Case")]
7778
public void CanHumanizeIntoTitleCase(string input, string expectedResult)
7879
{
7980
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Title));

src/Humanizer/StringHumanizeExtensions.cs

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ private static string FromPascalCase(string input)
3232
? match.Value
3333
: match.Value.ToLower()));
3434

35+
if (result.Replace(" ", "").ToCharArray().All(c => char.IsUpper(c)) &&
36+
result.Contains(" "))
37+
{
38+
result = result.ToLower();
39+
}
40+
3541
return result.Length > 0 ? char.ToUpper(result[0]) +
3642
result.Substring(1, result.Length - 1) : result;
3743
}

0 commit comments

Comments
 (0)