From 1577233165c7d4a5890c26bd4d8999eaddc6e2cb Mon Sep 17 00:00:00 2001 From: aktheknight Date: Tue, 5 Mar 2019 09:45:42 +0000 Subject: [PATCH 1/4] Change Pascalize to remove spaces Fix readme --- readme.md | 10 +++++----- src/Humanizer.Tests.Shared/InflectorTests.cs | 8 ++++---- src/Humanizer/InflectorExtensions.cs | 9 +++++++-- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/readme.md b/readme.md index 135aae71c..40d495102 100644 --- a/readme.md +++ b/readme.md @@ -219,7 +219,7 @@ If passed a fewer number for arguments, it'll throw `String.FormatException` exc You also can specify the culture to use explicitly as the first parameter for the `FormatWith()` method: ```c# -"{0:N2}".FormatWith(new CultureInfo("ru-RU"), 6666.66) => "6 666,66" +"{0:N2}".FormatWith(new CultureInfo("ru-RU"), 6666.66) => "6 666,66" ``` If a culture is not specified, current thread's current culture is used. @@ -639,17 +639,17 @@ Obviously this only applies to some cultures. For others passing gender in or no `Titleize` converts the input words to Title casing; equivalent to `"some title".Humanize(LetterCasing.Title)` #### Pascalize -`Pascalize` converts the input words to UpperCamelCase, also removing underscores: +`Pascalize` converts the input words to UpperCamelCase, also removing underscores and spaces: ```C# -"some_title".Pascalize() => "SomeTitle" +"some_title for something".Pascalize() => "SomeTitleForSomething" ``` #### Camelize `Camelize` behaves identically to `Pascalize`, except that the first character is lower case: ```C# -"some_title".Camelize() => "someTitle" +"some_title for something".Camelize() => "someTitleForSomething" ``` #### Underscore @@ -1256,4 +1256,4 @@ Humanizer.jvm meets all your jvm needs for manipulating and displaying strings, Humanizer is released under the MIT License. See the [bundled LICENSE](https://github.com/Humanizr/Humanizer/blob/master/LICENSE) file for details. ## Icon -Icon created by [Tyrone Rieschiek](https://twitter.com/Inkventive) +Icon created by [Tyrone Rieschiek](https://twitter.com/Inkventive) \ No newline at end of file diff --git a/src/Humanizer.Tests.Shared/InflectorTests.cs b/src/Humanizer.Tests.Shared/InflectorTests.cs index 9788eeb24..e4a8b28cf 100644 --- a/src/Humanizer.Tests.Shared/InflectorTests.cs +++ b/src/Humanizer.Tests.Shared/InflectorTests.cs @@ -100,8 +100,8 @@ public void Hyphenate(string input, string expectedOutput) [InlineData("CUStomer", "CUStomer")] [InlineData("customer_name", "CustomerName")] [InlineData("customer_first_name", "CustomerFirstName")] - [InlineData("customer_first_name_goes_here", "CustomerFirstNameGoesHere")] - [InlineData("customer name", "Customer name")] + [InlineData("customer_first_name goes here", "CustomerFirstNameGoesHere")] + [InlineData("customer name", "CustomerName")] public void Pascalize(string input, string expectedOutput) { Assert.Equal(expectedOutput, input.Pascalize()); @@ -114,8 +114,8 @@ public void Pascalize(string input, string expectedOutput) [InlineData("CUStomer", "cUStomer")] [InlineData("customer_name", "customerName")] [InlineData("customer_first_name", "customerFirstName")] - [InlineData("customer_first_name_goes_here", "customerFirstNameGoesHere")] - [InlineData("customer name", "customer name")] + [InlineData("customer_first_name goes here", "customerFirstNameGoesHere")] + [InlineData("customer name", "customerName")] [InlineData("", "")] public void Camelize(string input, string expectedOutput) { diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index 0f2f0c93c..444755cfb 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -67,20 +67,25 @@ public static string Titleize(this string input) /// By default, pascalize converts strings to UpperCamelCase also removing underscores /// /// + /// "This has a space" -> "ThisHasASpace" if true /// public static string Pascalize(this string input) { - return Regex.Replace(input, "(?:^|_)(.)", match => match.Groups[1].Value.ToUpper()); + + input = Regex.Replace(input, "(?:^|_| )(.)", match => match.Groups[1].Value.ToUpper()); + + return Regex.Replace(input, @"\s+", ""); } /// /// Same as Pascalize except that the first character is lower case /// /// + /// "This has a space" -> "thisHasASpace" if true /// public static string Camelize(this string input) { - var word = Pascalize(input); + var word = input.Pascalize(); return word.Length > 0 ? word.Substring(0, 1).ToLower() + word.Substring(1) : word; } From 374038495a08f91fb6a33e5f7db0d3b25ee54f0b Mon Sep 17 00:00:00 2001 From: aktheknight Date: Tue, 5 Mar 2019 13:02:58 +0000 Subject: [PATCH 2/4] Add test for multiple spaces, remove unneeded regex --- src/Humanizer.Tests.Shared/InflectorTests.cs | 2 ++ src/Humanizer/InflectorExtensions.cs | 4 ++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/Humanizer.Tests.Shared/InflectorTests.cs b/src/Humanizer.Tests.Shared/InflectorTests.cs index 74cffa8b1..6b72f27df 100644 --- a/src/Humanizer.Tests.Shared/InflectorTests.cs +++ b/src/Humanizer.Tests.Shared/InflectorTests.cs @@ -102,6 +102,7 @@ public void Hyphenate(string input, string expectedOutput) [InlineData("customer_first_name", "CustomerFirstName")] [InlineData("customer_first_name goes here", "CustomerFirstNameGoesHere")] [InlineData("customer name", "CustomerName")] + [InlineData("customer name", "CustomerName")] public void Pascalize(string input, string expectedOutput) { Assert.Equal(expectedOutput, input.Pascalize()); @@ -116,6 +117,7 @@ public void Pascalize(string input, string expectedOutput) [InlineData("customer_first_name", "customerFirstName")] [InlineData("customer_first_name goes here", "customerFirstNameGoesHere")] [InlineData("customer name", "customerName")] + [InlineData("customer name", "customerName")] [InlineData("", "")] public void Camelize(string input, string expectedOutput) { diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index 444755cfb..239574761 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -72,9 +72,9 @@ public static string Titleize(this string input) public static string Pascalize(this string input) { - input = Regex.Replace(input, "(?:^|_| )(.)", match => match.Groups[1].Value.ToUpper()); + return Regex.Replace(input, "(?:^|_| )(.)", match => match.Groups[1].Value.ToUpper()); - return Regex.Replace(input, @"\s+", ""); + //return Regex.Replace(input, @"\s+", ""); } /// From 2235a813269a3f43f6b08cad9ebf3bbb234f8f86 Mon Sep 17 00:00:00 2001 From: aktheknight Date: Tue, 5 Mar 2019 15:04:08 +0000 Subject: [PATCH 3/4] Fix multiple spaces test --- src/Humanizer/InflectorExtensions.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index 239574761..061af74cc 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -72,7 +72,7 @@ public static string Titleize(this string input) public static string Pascalize(this string input) { - return Regex.Replace(input, "(?:^|_| )(.)", match => match.Groups[1].Value.ToUpper()); + return Regex.Replace(input, "(?:^|_| +)(.)", match => match.Groups[1].Value.ToUpper()); //return Regex.Replace(input, @"\s+", ""); } From 46e82368ef518061d03b59e823c6a463eddf87e2 Mon Sep 17 00:00:00 2001 From: aktheknight Date: Mon, 11 Mar 2019 15:18:35 +0000 Subject: [PATCH 4/4] Remove comments and excess spaces --- src/Humanizer/InflectorExtensions.cs | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/Humanizer/InflectorExtensions.cs b/src/Humanizer/InflectorExtensions.cs index 061af74cc..90317439c 100644 --- a/src/Humanizer/InflectorExtensions.cs +++ b/src/Humanizer/InflectorExtensions.cs @@ -70,11 +70,8 @@ public static string Titleize(this string input) /// "This has a space" -> "ThisHasASpace" if true /// public static string Pascalize(this string input) - { - + { return Regex.Replace(input, "(?:^|_| +)(.)", match => match.Groups[1].Value.ToUpper()); - - //return Regex.Replace(input, @"\s+", ""); } ///