diff --git a/src/Humanizer.Tests.Shared/InflectorTests.cs b/src/Humanizer.Tests.Shared/InflectorTests.cs index 3c688613c..b56bb0c0a 100644 --- a/src/Humanizer.Tests.Shared/InflectorTests.cs +++ b/src/Humanizer.Tests.Shared/InflectorTests.cs @@ -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")] diff --git a/src/Humanizer/StringHumanizeExtensions.cs b/src/Humanizer/StringHumanizeExtensions.cs index 163eeef04..486c106cb 100644 --- a/src/Humanizer/StringHumanizeExtensions.cs +++ b/src/Humanizer/StringHumanizeExtensions.cs @@ -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); } @@ -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(" ")) {