Skip to content

Commit

Permalink
Changed PascalCaseWordPartsRegex to account for decimal point and add…
Browse files Browse the repository at this point in the history
…ed logic to remove more than one decimal points if it occurs in a double
  • Loading branch information
Ltwo3five committed Feb 20, 2024
1 parent 1bdd7a1 commit 97bdbb0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Humanizer.Tests.Shared/InflectorTests.cs
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
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

0 comments on commit 97bdbb0

Please sign in to comment.