// ReSharper disable IdentifierTypo using System.Text; 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 upperSet, string lowerSet) { StringBuilder sb = new(s); for (var i = 0; i < upperSet.Length; i++) { sb.Replace(upperSet[i], lowerSet[i]); } return sb.ToString(); } public static string CaseFold(CaseMapping mapping, string s) { return s == null ? string.Empty : mapping switch { CaseMapping.Rfc1459 => Replace(s, Rfc1459UpperChars, Rfc1459LowerChars), CaseMapping.Ascii => Replace(s, AsciiUpperChars, AsciiLowerChars), _ => throw new ArgumentOutOfRangeException(nameof(mapping), mapping, null) }; } }