Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Humanizer.Tests.Shared/StringHumanizeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ public void CanHumanizeIntoLowerCase(string input, string expectedResult)
[InlineData("CanReturnSentenceCase", "Can return sentence case")]
[InlineData("", "")]
[InlineData("égoïste", "Égoïste")]
[InlineData("Normal; Normal and PascalCase", "Normal; normal and pascal case")]
[InlineData("I,and No One else", "I, and no one else")]
public void CanHumanizeIntoSentenceCase(string input, string expectedResult)
{
Assert.Equal(expectedResult, input.Humanize(LetterCasing.Sentence));
Expand Down
9 changes: 8 additions & 1 deletion src/Humanizer/StringHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,16 @@ public static class StringHumanizeExtensions
private static readonly Regex PascalCaseWordPartsRegex;
private static readonly Regex FreestandingSpacingCharRegex;

private const string OptionallyCapitalizedWord = @"\p{Lu}?\p{Ll}+";
private const string IntegerAndOptionalLowercaseLetters = @"[0-9]+\p{Ll}*";
private const string Acronym = @"\p{Lu}+(?=\p{Lu}|[0-9]|\b)";
private const string SequenceOfOtherLetters = @"\p{Lo}+";
private const string MidSentencePunctuation = "[,;]?";

static StringHumanizeExtensions()
{
PascalCaseWordPartsRegex = new Regex(@"[\p{Lu}]?[\p{Ll}]+|[0-9]+[\p{Ll}]*|[\p{Lu}]+(?=[\p{Lu}][\p{Ll}]|[0-9]|\b)|[\p{Lo}]+",
PascalCaseWordPartsRegex = new Regex(
$"({OptionallyCapitalizedWord}|{IntegerAndOptionalLowercaseLetters}|{Acronym}|{SequenceOfOtherLetters}){MidSentencePunctuation}",
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptionsUtil.Compiled);
FreestandingSpacingCharRegex = new Regex(@"\s[-_]|[-_]\s", RegexOptionsUtil.Compiled);
}
Expand Down