-
Notifications
You must be signed in to change notification settings - Fork 965
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Transform with Culture via ICulturedStringTransformer
- Loading branch information
Showing
6 changed files
with
81 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using System.Globalization; | ||
|
||
namespace Humanizer | ||
{ | ||
/// <summary> | ||
/// Can transform a string with the given culture | ||
/// </summary> | ||
public interface ICulturedStringTransformer : IStringTransformer | ||
{ | ||
/// <summary> | ||
/// Transform the input | ||
/// </summary> | ||
/// <param name="input">String to be transformed</param> | ||
/// <param name="culture">The culture</param> | ||
/// <returns></returns> | ||
string Transform(string input, CultureInfo culture); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,24 @@ | ||
using System.Globalization; | ||
|
||
namespace Humanizer | ||
{ | ||
internal class ToSentenceCase : IStringTransformer | ||
internal class ToSentenceCase : ICulturedStringTransformer | ||
{ | ||
public string Transform(string input) | ||
{ | ||
return Transform(input, null); | ||
} | ||
|
||
public string Transform(string input, CultureInfo culture) | ||
{ | ||
culture ??= CultureInfo.CurrentCulture; | ||
|
||
if (input.Length >= 1) | ||
{ | ||
return string.Concat(input.Substring(0, 1).ToUpper(), input.Substring(1)); | ||
return culture.TextInfo.ToUpper(input[0]) + input.Substring(1); | ||
} | ||
|
||
return input.ToUpper(); | ||
return culture.TextInfo.ToUpper(input); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,19 @@ | ||
using System.Globalization; | ||
|
||
namespace Humanizer | ||
{ | ||
internal class ToUpperCase : IStringTransformer | ||
internal class ToUpperCase : ICulturedStringTransformer | ||
{ | ||
public string Transform(string input) | ||
{ | ||
return input.ToUpper(); | ||
return Transform(input, null); | ||
} | ||
|
||
public string Transform(string input, CultureInfo culture) | ||
{ | ||
culture ??= CultureInfo.CurrentCulture; | ||
|
||
return culture.TextInfo.ToUpper(input); | ||
} | ||
} | ||
} |