-
-
Notifications
You must be signed in to change notification settings - Fork 103
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
7 changed files
with
93 additions
and
23 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
14 changes: 14 additions & 0 deletions
14
..._Shared/HandyControls/Tools/Extension/Internals/Transformer/ICulturedStringTransformer.cs
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,14 @@ | ||
using System.Globalization; | ||
namespace HandyControl.Tools.Extension | ||
{ | ||
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
17 changes: 13 additions & 4 deletions
17
...HandyControl_Shared/HandyControls/Tools/Extension/Internals/Transformer/ToSentenceCase.cs
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 @@ | ||
namespace HandyControl.Tools.Extension | ||
using System.Globalization; | ||
|
||
namespace HandyControl.Tools.Extension | ||
{ | ||
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
15 changes: 12 additions & 3 deletions
15
...ed/HandyControl_Shared/HandyControls/Tools/Extension/Internals/Transformer/ToUpperCase.cs
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 @@ | ||
namespace HandyControl.Tools.Extension | ||
using System.Globalization; | ||
|
||
namespace HandyControl.Tools.Extension | ||
{ | ||
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); | ||
} | ||
} | ||
} |