Пример #1
0
        private static void LookupWords(string dictionary, byte[] searchDigits, ref int noDigitsProcessed, ref List <DigitsWords> wordList, bool outputProgess = false)
        {
            if (outputProgess)
            {
                ClearCurrentConsoleLine();
                Console.Write("Searching for {0}\r", string.Join(",", searchDigits));
            }

            var regExpression = GetRegexp(searchDigits);
            var matches       = regExpression.Matches(dictionary);

            if (matches.Count > 0)
            {
                noDigitsProcessed = searchDigits.Length;                 // store the number of digits already processed

                if (outputProgess)
                {
                    ClearCurrentConsoleLine();
                    Console.Write("Found {0}: ", string.Join(",", searchDigits));
                }

                var word = new DigitsWords(searchDigits);
                wordList.Add(word);

                // Parallel.ForEach did not seem to be faster
                foreach (Match match in matches)
                {
                    //Console.WriteLine("{0} found at position {1}", match.Groups[1], match.Index);
                    if (outputProgess)
                    {
                        Console.Write("{0}  ", match.Groups[1].Value);
                    }
                    word.WordCandidates.Add(match.Groups[1].Value);
                }

                if (outputProgess)
                {
                    Console.Write("\n");
                }
            }
            else
            {
                // reduce the number of digits and try again
                int newLength = searchDigits.Count() - 1;
                if (newLength <= 0)
                {
                    return;
                }

                searchDigits = searchDigits.Take(newLength).ToArray();
                LookupWords(dictionary, searchDigits, ref noDigitsProcessed, ref wordList, outputProgess);
            }
        }
Пример #2
0
        private static void LookupWords(string dictionary, byte[] searchDigits, ref int noDigitsProcessed, ref List<DigitsWords> wordList, bool outputProgess = false)
        {
            if (outputProgess) {
                ClearCurrentConsoleLine();
                Console.Write("Searching for {0}\r", string.Join(",", searchDigits));
            }

            var regExpression = GetRegexp(searchDigits);
            var matches = regExpression.Matches(dictionary);
            if (matches.Count > 0) {
                noDigitsProcessed = searchDigits.Length; // store the number of digits already processed

                if (outputProgess) {
                    ClearCurrentConsoleLine();
                    Console.Write("Found {0}: ", string.Join(",", searchDigits));
                }

                var word = new DigitsWords(searchDigits);
                wordList.Add(word);

                // Parallel.ForEach did not seem to be faster
                foreach(Match match in matches)
                {
                    //Console.WriteLine("{0} found at position {1}", match.Groups[1], match.Index);
                    if (outputProgess) Console.Write("{0}  ", match.Groups[1].Value);
                    word.WordCandidates.Add(match.Groups[1].Value);
                }

                if (outputProgess) Console.Write("\n");
            } else {
                // reduce the number of digits and try again
                int newLength = searchDigits.Count() - 1;
                if (newLength <= 0) return;

                searchDigits = searchDigits.Take(newLength).ToArray();
                LookupWords(dictionary, searchDigits, ref noDigitsProcessed, ref wordList, outputProgess);
            }
        }