blob: 4546e571aaaa03d0ab2042f77c85c81c01cbe65f (
plain) (
blame)
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
|
using System;
namespace IRCStates
{
public static class Casemap
{
public enum CaseMapping
{
Rfc1459,
Ascii
}
private const string AsciiUpperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
private const string AsciiLowerChars = "abcdefghijklmnopqrstuvwxyz";
private const string Rfc1459UpperChars = AsciiUpperChars + @"[]~\";
private const string Rfc1459LowerChars = AsciiLowerChars + @"{}^|";
private static string Replace(string s, string upper, string lower)
{
for (var i = 0; i < upper.Length; ++i) s = s.Replace(upper[i], lower[i]);
return s;
}
public static string CaseFold(CaseMapping mapping, string s)
{
if (s != null)
return mapping switch
{
CaseMapping.Rfc1459 => Replace(s, Rfc1459UpperChars, Rfc1459LowerChars),
CaseMapping.Ascii => Replace(s, AsciiUpperChars, AsciiLowerChars),
_ => throw new ArgumentOutOfRangeException(nameof(mapping), mapping, null)
};
return string.Empty;
}
}
}
|