2020-04-22 20:28:51 +00:00
|
|
|
|
using System;
|
2024-04-19 23:34:36 +00:00
|
|
|
|
// ReSharper disable IdentifierTypo
|
2020-04-22 20:28:51 +00:00
|
|
|
|
|
2020-05-15 03:06:10 +00:00
|
|
|
|
namespace IRCStates
|
2020-04-22 20:28:51 +00:00
|
|
|
|
{
|
|
|
|
|
public static class Casemap
|
|
|
|
|
{
|
|
|
|
|
public enum CaseMapping
|
|
|
|
|
{
|
|
|
|
|
Rfc1459,
|
|
|
|
|
Ascii
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private const string AsciiUpperChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
|
|
|
|
|
private const string AsciiLowerChars = "abcdefghijklmnopqrstuvwxyz";
|
|
|
|
|
private const string Rfc1459UpperChars = AsciiUpperChars + @"[]~\";
|
2023-11-07 22:54:58 +00:00
|
|
|
|
private const string Rfc1459LowerChars = AsciiLowerChars + "{}^|";
|
2020-04-22 20:28:51 +00:00
|
|
|
|
|
|
|
|
|
private static string Replace(string s, string upper, string lower)
|
|
|
|
|
{
|
2020-04-28 04:35:52 +00:00
|
|
|
|
for (var i = 0; i < upper.Length; ++i) s = s.Replace(upper[i], lower[i]);
|
2020-04-22 20:28:51 +00:00
|
|
|
|
|
|
|
|
|
return s;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static string CaseFold(CaseMapping mapping, string s)
|
|
|
|
|
{
|
|
|
|
|
if (s != null)
|
|
|
|
|
return mapping switch
|
|
|
|
|
{
|
|
|
|
|
CaseMapping.Rfc1459 => Replace(s, Rfc1459UpperChars, Rfc1459LowerChars),
|
2020-04-28 04:35:52 +00:00
|
|
|
|
CaseMapping.Ascii => Replace(s, AsciiUpperChars, AsciiLowerChars),
|
|
|
|
|
_ => throw new ArgumentOutOfRangeException(nameof(mapping), mapping, null)
|
2020-04-22 20:28:51 +00:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
return string.Empty;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|