// ---------------------------------------------------------------- // // Kenny Translator // // Authors: // Kohan Ikin (syneryder@namesuppressed.com) // Klaus Hartke (hartke@users.sourceforge.net) // // Date Created: // 2003-05-10 // // This source file is copyright (c) 2003 by its authors. Free // distribution and modification is permitted, including adding // to the list of authors and copyright holders, as long as this // copyright notice is maintained. // // ---------------------------------------------------------------- [assembly:System.Reflection.AssemblyTitle("Kenny Translator")] [assembly:System.Reflection.AssemblyCopyright("(c) 2003 Kohan Ikin, Klaus Hartke")] [assembly:System.Reflection.AssemblyVersion("0.9.1.0")] namespace Kenny { public class Translator { private static string[] _Kenny = { "Mmm", "Mmp", "Mmf", "Mpm", "Mpp", "Mpf", "Mfm", "Mfp", "Mff", "Pmm", "Pmp", "Pmf", "Ppm", "Ppp", "Ppf", "Pfm", "Pfp", "Pff", "Fmm", "Fmp", "Fmf", "Fpm", "Fpp", "Fpf", "Ffm", "Ffp" }; internal static string NormalToKenny(string input) { char[] buffer = new char[input.Length * 3]; int offset = 0; string s; foreach (char c in input) { if ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z')) { s = _Kenny[char.ToUpper(c) - 'A']; buffer[offset++] = char.IsUpper(c) ? s[0] : char.ToLower(s[0]); buffer[offset++] = s[1]; buffer[offset++] = s[2]; } else { buffer[offset++] = c; } } return new string(buffer, 0, offset); } internal static string KennyToNormal(string input) { char[] buffer = new char[input.Length]; int offset = 0; for (int i = 0; i < input.Length; i++) { if ((input[i] >= 'a' && input[i] <= 'z') || (input[i] >= 'A' && input[i] <= 'Z')) { for (int c = 0; c < _Kenny.Length; c++) { if ((_Kenny[c][0] == char.ToUpper(input[i])) && (_Kenny[c][1] == input[i + 1]) && (_Kenny[c][2] == input[i + 2])) { buffer[offset++] = (char)(char.IsUpper(input[i]) ? (c + 'A') : (c + 'a')); i += 2; break; } } } else { buffer[offset++] = input[i]; } } return new string(buffer, 0, offset); } public static string Translate(string input) { if (input == null) { throw new System.ArgumentNullException(); } foreach (char c in input) { if ((c >= 'a' && c <= 'z' && c != 'm' && c != 'f' && c != 'p') || (c >= 'A' && c <= 'Z' && c != 'M' && c != 'F' && c != 'P')) { return NormalToKenny(input); } } return KennyToNormal(input); } private static void Main(string[] args) { System.Console.WriteLine(Translate((args.Length == 1) ? args[0] : null)); } } }