public static Hashe What(this string a) { Hashe it = Hashe.NONE; List <string> he = Enum.GetNames(typeof(Hashe)).Select(x => x.ToLower()).ToList(); int[] hi = Enum.GetValues(typeof(Hashe)).Cast <int>().ToArray(); a = a.ToLower(); for (int ai = 0; ai < he.Count; ai++) { if (he[ai].StartsWith(a)) { int actionIndex = ai; if (actionIndex >= 0 && Enum.IsDefined(typeof(Hashe), hi[actionIndex])) { it = (Hashe)hi[actionIndex]; } break; } } return(it); }
static void Main(string[] args) { Hashe hx = Hashe.Murmur3; uint seed = 0; List <string> words = new List <string>(); IHash h; OutputWriter o; string infile = "", outfile = ""; foreach (string a in args) { if (a.StartsWith("-")) { string he = (a.Substring(1, a.Length - 1)); if (he.StartsWith("-")) { he = a.Substring(2, a.Length - 2); if (!uint.TryParse(he, out seed)) { hx = he.What(); } } else { string opt = he.Substring(0, 1).ToLower(); string val = he.Substring(1, he.Length - 1); switch (opt) { case "i": infile = val; break; case "o": outfile = val; break; default: break; } } } else { words.Add(a); } } Reader r; if (!string.IsNullOrEmpty(infile)) { r = new TextLineReader(infile); } else if (words.Count > 0) { r = new ListReader(words); } else { r = new ConsoleReader(); if (args.Length < 1 && !((ConsoleReader)r).isPiped) { Console.WriteLine(Res.Get("help")); return; } } string lin; switch (hx) { case Hashe.Murmur3: h = new MurmurHasher(seed); break; case Hashe.MD5: h = new MD5Hasher(); break; case Hashe.CRC32: h = new CRC32Hasher(); break; case Hashe.xxHash: h = new xxHasher(seed); break; default: h = new MurmurHasher(seed); break; } if (string.IsNullOrEmpty(outfile)) { if (words.Count > 0) { o = new ConsoleWriter(); } else { o = new ConsoleLine(); } } else { o = new BinaryDataWriter(outfile); } while ((lin = r.Next()) != null) { byte[] b = Encoding.UTF8.GetBytes(lin); o.Tell(h.Has(b)); } o.Dispose(); r.Dispose(); }