-
Notifications
You must be signed in to change notification settings - Fork 938
/
To.cs
90 lines (84 loc) · 2.74 KB
/
To.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
using System.Globalization;
using System.Linq;
namespace Humanizer
{
/// <summary>
/// A portal to string transformation using IStringTransformer
/// </summary>
public static class To
{
/// <summary>
/// Transforms a string using the provided transformers. Transformations are applied in the provided order.
/// </summary>
/// <param name="input"></param>
/// <param name="transformers"></param>
/// <returns></returns>
public static string Transform(this string input, params IStringTransformer[] transformers)
{
return transformers.Aggregate(input, (current, stringTransformer) => stringTransformer.Transform(current));
}
/// <summary>
/// Transforms a string using the provided transformers. Transformations are applied in the provided order.
/// </summary>
/// <param name="input"></param>
/// <param name="culture"></param>
/// <param name="transformers"></param>
/// <returns></returns>
public static string Transform(this string input, CultureInfo culture, params ICulturedStringTransformer[] transformers)
{
return transformers.Aggregate(input, (current, stringTransformer) => stringTransformer.Transform(current, culture));
}
/// <summary>
/// Changes string to title case
/// </summary>
/// <example>
/// "INvalid caSEs arE corrected" -> "Invalid Cases Are Corrected"
/// </example>
public static ICulturedStringTransformer TitleCase
{
get
{
return new ToTitleCase();
}
}
/// <summary>
/// Changes the string to lower case
/// </summary>
/// <example>
/// "Sentence casing" -> "sentence casing"
/// </example>
public static ICulturedStringTransformer LowerCase
{
get
{
return new ToLowerCase();
}
}
/// <summary>
/// Changes the string to upper case
/// </summary>
/// <example>
/// "lower case statement" -> "LOWER CASE STATEMENT"
/// </example>
public static ICulturedStringTransformer UpperCase
{
get
{
return new ToUpperCase();
}
}
/// <summary>
/// Changes the string to sentence case
/// </summary>
/// <example>
/// "lower case statement" -> "Lower case statement"
/// </example>
public static ICulturedStringTransformer SentenceCase
{
get
{
return new ToSentenceCase();
}
}
}
}