-
Notifications
You must be signed in to change notification settings - Fork 1
/
CharacterTransform.cs
48 lines (39 loc) · 1.57 KB
/
CharacterTransform.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
using System;
using System.Collections.Generic;
using System.Linq;
using static MySQLCLRFunctions.StringTest;
using static MySQLCLRFunctions._SharedConstants;
using static MySQLCLRFunctions.StringReduce;
using static MySQLCLRFunctions.CharacterTest;
namespace MySQLCLRFunctions
{
public static class CharacterTransform
{
public static string ReplaceFirstC(string input, char replacement)
{
if (IsNullOrEmpty(input)) return input;
//if (Char.GetUnicodeCategory(replacement) != System.Globalization.UnicodeCategory.) Warning!
char firstC = input.First();
if (firstC == replacement) return input;
return replacement + LTrimOne(input);
}
public static string ReplaceLastC(string input, char replacement)
{
if (IsNullOrEmpty(input)) return input;
//if (Char.GetUnicodeCategory(replacement) != System.Globalization.UnicodeCategory.) Warning!
char lastC = input.Last();
if (lastC == replacement) return input;
return RTrimOne(input) + replacement;
}
public static char[] ToArray(this char input) // No reason to convert a nullable character
{
if (input.ISNULLORWHITESPACE()) return new char[] { };
return new char[] { (char)input };
}
public static char[] ToArray(this char? input) // No reason to convert a nullable character
{
if (input.ISNULLORWHITESPACE()) return new char[] { };
return new char[] { (char)input };
}
}
}