Skip to content

Commit

Permalink
Change Pascalize to remove spaces
Browse files Browse the repository at this point in the history
Fix readme
  • Loading branch information
AKTheKnight committed Mar 5, 2019
1 parent d5b3cf3 commit 1577233
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 11 deletions.
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)
8 changes: 4 additions & 4 deletions src/Humanizer.Tests.Shared/InflectorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand All @@ -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)
{
Expand Down
9 changes: 7 additions & 2 deletions src/Humanizer/InflectorExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,25 @@ 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());

input = Regex.Replace(input, "(?:^|_| )(.)", match => match.Groups[1].Value.ToUpper());

return Regex.Replace(input, @"\s+", "");
}

/// <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

0 comments on commit 1577233

Please sign in to comment.