forked from JSONAPIdotNET/JSONAPI.NET
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringExtensions.cs
More file actions
29 lines (25 loc) · 848 Bytes
/
StringExtensions.cs
File metadata and controls
29 lines (25 loc) · 848 Bytes
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
using System.Text.RegularExpressions;
namespace JSONAPI.Extensions
{
public static class StringExtensions
{
private static readonly Regex PascalizeRegex = new Regex(@"(?:^|_|\-|\.)(.)");
public static string Pascalize(this string word)
{
return PascalizeRegex.Replace(
word,
match => match.Groups[1].Value.ToUpper());
}
public static string Depascalize(this string word)
{
return Regex.Replace(
Regex.Replace(
Regex.Replace(word, @"([A-Z]+)([A-Z][a-z])", "$1_$2"), @"([a-z\d])([A-Z])",
"$1_$2"), @"[-\s]", "_").ToLower();
}
public static string Dasherize(this string word)
{
return Depascalize(word).Replace('_', '-');
}
}
}