コード例 #1
0
            private static Predicate <string> CreateMatcher(SearchDirectory options, string matchString)
            {
                const string tmpString = "__SHAZAM,,";

                if (options.SubstringMatch)
                {
                    if (matchString.Contains('*'))
                    {
                        Regex re = new Regex("^.*" + Regex.Escape(matchString.Replace("*", tmpString)).Replace(tmpString, ".*") + ".*$", RegexOptions.IgnoreCase);
                        return(s => re.IsMatch(s));
                    }
                    else
                    {
                        return(s => - 1 != s.IndexOf(matchString, StringComparison.OrdinalIgnoreCase));
                    }
                }
                else
                {
                    if (matchString.Contains('*'))
                    {
                        Regex re = new Regex("^" + Regex.Escape(matchString.Replace("*", tmpString)).Replace(tmpString, ".*") + ".*$", RegexOptions.IgnoreCase);
                        return(s => re.IsMatch(s));
                    }
                    else
                    {
                        return(s => s.StartsWith(matchString, StringComparison.OrdinalIgnoreCase));
                    }
                }
            }
コード例 #2
0
            private PartQuery(SearchDirectory options, IEnumerable <string> parts, int depth)
            {
                string matchString = parts.First();

                this.QueryString = matchString;
                this.Matches     = CreateMatcher(options, matchString);

                if (parts.Count() > 1)
                {
                    this.Next = new PartQuery(options, parts.Skip(1), depth + 1);
                }

                this.Depth = depth;
            }
コード例 #3
0
 public PartQuery(SearchDirectory options)
     : this(options, options.Pattern.Split('\\'), 0)
 {
 }