Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Titleize removing decimal point #1267

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
8 changes: 6 additions & 2 deletions src/Humanizer.Tests.Shared/InflectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,13 @@ public void SingularizeSingleLetter(string input)
[InlineData("some-title: The beginning", "Some Title: The Beginning")]
[InlineData("some_title:_the_beginning", "Some Title: the Beginning")]
[InlineData("some title: The_beginning", "Some Title: The Beginning")]
public void Titleize(string input, string expectedOuput)
[InlineData("thisIs3.5mmLong", "This Is 3.5mm Long")]
[InlineData("thisIs3..5mmLong", "This Is 3.5mm Long")]
[InlineData("this Is 3..5mm Long", "This Is 3.5mm Long")]
[InlineData("this is 3.5mm long", "This Is 3.5mm Long")]
public void Titleize(string input, string expectedOutput)
{
Assert.Equal(expectedOuput, input.Titleize());
Assert.Equal(expectedOutput, input.Titleize());
}

[InlineData("some_title", "some-title")]
Expand Down
3 changes: 2 additions & 1 deletion src/Humanizer/StringHumanizeExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static class StringHumanizeExtensions

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(@"[\p{Lu}]?[\p{Ll}]+|([0-9]*(\.*[0-9]+))[\p{Ll}]*|[\p{Lu}]+(?=[\p{Lu}][\p{Ll}]|[0-9]|\b)|[\p{Lo}]+",
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptionsUtil.Compiled);
FreestandingSpacingCharRegex = new Regex(@"\s[-_]|[-_]\s", RegexOptionsUtil.Compiled);
}
Expand All @@ -32,6 +32,7 @@ private static string FromPascalCase(string input)
? match.Value
: match.Value.ToLower()));

result = Regex.Replace(result, "((?<=[0-9])[\\.]{2,})", ".");
if (result.Replace(" ", "").ToCharArray().All(c => char.IsUpper(c)) &&
result.Contains(" "))
{
Expand Down