Skip to content

Commit 97bdbb0

Browse files
committed
Changed PascalCaseWordPartsRegex to account for decimal point and added logic to remove more than one decimal points if it occurs in a double
1 parent 1bdd7a1 commit 97bdbb0

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

src/Humanizer.Tests.Shared/InflectorTests.cs

+6-2
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,13 @@ public void SingularizeSingleLetter(string input)
9292
[InlineData("some-title: The beginning", "Some Title: The Beginning")]
9393
[InlineData("some_title:_the_beginning", "Some Title: the Beginning")]
9494
[InlineData("some title: The_beginning", "Some Title: The Beginning")]
95-
public void Titleize(string input, string expectedOuput)
95+
[InlineData("thisIs3.5mmLong", "This Is 3.5mm Long")]
96+
[InlineData("thisIs3..5mmLong", "This Is 3.5mm Long")]
97+
[InlineData("this Is 3..5mm Long", "This Is 3.5mm Long")]
98+
[InlineData("this is 3.5mm long", "This Is 3.5mm Long")]
99+
public void Titleize(string input, string expectedOutput)
96100
{
97-
Assert.Equal(expectedOuput, input.Titleize());
101+
Assert.Equal(expectedOutput, input.Titleize());
98102
}
99103

100104
[InlineData("some_title", "some-title")]

src/Humanizer/StringHumanizeExtensions.cs

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public static class StringHumanizeExtensions
1313

1414
static StringHumanizeExtensions()
1515
{
16-
PascalCaseWordPartsRegex = new Regex(@"[\p{Lu}]?[\p{Ll}]+|[0-9]+[\p{Ll}]*|[\p{Lu}]+(?=[\p{Lu}][\p{Ll}]|[0-9]|\b)|[\p{Lo}]+",
16+
PascalCaseWordPartsRegex = new Regex(@"[\p{Lu}]?[\p{Ll}]+|([0-9]*(\.*[0-9]+))[\p{Ll}]*|[\p{Lu}]+(?=[\p{Lu}][\p{Ll}]|[0-9]|\b)|[\p{Lo}]+",
1717
RegexOptions.IgnorePatternWhitespace | RegexOptions.ExplicitCapture | RegexOptionsUtil.Compiled);
1818
FreestandingSpacingCharRegex = new Regex(@"\s[-_]|[-_]\s", RegexOptionsUtil.Compiled);
1919
}
@@ -32,6 +32,7 @@ private static string FromPascalCase(string input)
3232
? match.Value
3333
: match.Value.ToLower()));
3434

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

0 commit comments

Comments
 (0)