From 21f1e95fb8e935134a969bc3d729964d8d2aadfa Mon Sep 17 00:00:00 2001 From: Ben Harris Date: Thu, 14 May 2020 23:06:10 -0400 Subject: rename Irc to IRC --- IRCStates/Casemap.cs | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) create mode 100644 IRCStates/Casemap.cs (limited to 'IRCStates/Casemap.cs') diff --git a/IRCStates/Casemap.cs b/IRCStates/Casemap.cs new file mode 100644 index 0000000..4546e57 --- /dev/null +++ b/IRCStates/Casemap.cs @@ -0,0 +1,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; + } + } +} -- cgit 1.4.1