Example #1
0
        public static Searcher GetSearcher(List <string> findStrs, List <Coder.CodePage> codePages, bool matchCase)
        {
            var data = new List <Tuple <byte[], bool> >();

            foreach (var findStr in findStrs)
            {
                foreach (var codePage in codePages)
                {
                    var bytes = Coder.TryStringToBytes(findStr, codePage);
                    if (bytes != null)
                    {
                        data.Add(Tuple.Create(bytes, (!Coder.IsStr(codePage)) || (matchCase) || (Coder.AlwaysCaseSensitive(codePage))));
                    }
                }
            }
            data = data.Distinct(tuple => $"{Coder.BytesToString(tuple.Item1, Coder.CodePage.Hex)}-{tuple.Item2}").ToList();
            return(new Searcher(data));
        }
        void Command_Edit_Find_Binary(EditFindBinaryDialog.Result result)
        {
            var findStrs = result.CodePages
                           .Select(codePage => Tuple.Create(Coder.TryStringToBytes(result.Text, codePage), (!Coder.IsStr(codePage)) || (result.MatchCase) || (Coder.AlwaysCaseSensitive(codePage))))
                           .NonNull(tuple => tuple.Item1)
                           .Select(tuple => Tuple.Create(Coder.TryBytesToString(tuple.Item1, CodePage), tuple.Item2))
                           .NonNullOrEmpty(tuple => tuple.Item1)
                           .GroupBy(tuple => $"{tuple.Item1}-{tuple.Item2}")
                           .Select(group => group.First())
                           .ToList();
            var searcher   = new Searcher(findStrs);
            var selections = result.SelectionOnly ? Selections.ToList() : new List <Range> {
                FullRange
            };
            var ranges = selections.AsParallel().AsOrdered().SelectMany(selection => Data.StringMatches(searcher, selection.Start, selection.Length)).Select(tuple => Range.FromIndex(tuple.Item1, tuple.Item2)).ToList();

            ViewValuesFindValue = result.Text;
            SetSelections(ranges);
        }