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

Change Pascalize to remove spaces fix #774 #793

Merged
merged 6 commits into from
Mar 11, 2019
Merged
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
10 changes: 5 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)`

#### <a id="pascalize">Pascalize</a>
`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"
```

#### <a id="camelize">Camelize</a>
`Camelize` behaves identically to `Pascalize`, except that the first character is lower case:

```C#
"some_title".Camelize() => "someTitle"
"some_title for something".Camelize() => "someTitleForSomething"
```

#### <a id="underscore">Underscore</a>
Expand Down Expand Up @@ -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.

## <a id="icon">Icon</a>
Icon created by [Tyrone Rieschiek](https://twitter.com/Inkventive)
Icon created by [Tyrone Rieschiek](https://twitter.com/Inkventive)
10 changes: 6 additions & 4 deletions src/Humanizer.Tests.Shared/InflectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,9 @@ 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")]
[InlineData("customer name", "CustomerName")]
public void Pascalize(string input, string expectedOutput)
{
Assert.Equal(expectedOutput, input.Pascalize());
Expand All @@ -114,8 +115,9 @@ 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("customer name", "customerName")]
[InlineData("", "")]
public void Camelize(string input, string expectedOutput)
{
Expand Down
8 changes: 5 additions & 3 deletions src/Humanizer/InflectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,22 @@ public static string Titleize(this string input)
/// By default, pascalize converts strings to UpperCamelCase also removing underscores
/// </summary>
/// <param name="input"></param>
/// <param name="removeWhiteSpace">"This has a space" -> "ThisHasASpace" if true</param>
/// <returns></returns>
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());
}

/// <summary>
/// Same as Pascalize except that the first character is lower case
/// </summary>
/// <param name="input"></param>
/// <param name="removeWhiteSpace">"This has a space" -> "thisHasASpace" if true</param>
/// <returns></returns>
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;
}

Expand Down