Exemplo n.º 1
0
            /// <summary>
            /// Gets the regex that represents the given filter group
            /// </summary>
            /// <param name="filterGroupName">Filter group name</param>
            /// <returns>Group regex</returns>
            private static Regex GetFilterGroupRegex(string filterGroupName)
            {
                FilterGroup filterGroup = FilterGroups.ParseFilterList(filterGroupName, FilterGroup.None);
                Regex       result;

                if (FilterEntry.filterGroupRegexCache.TryGetValue(filterGroup, out result))
                {
                    return(result);
                }
                else
                {
                    // Get the filter strings for this filter group, and convert them to their regex forms
                    List <string> regexStrings = FilterGroups.GetFilterStrings(filterGroup)
                                                 .Select(filterString =>
                    {
                        if (filterString.StartsWith("[", StringComparison.Ordinal) && filterString.EndsWith("]", StringComparison.Ordinal))
                        {
                            return(filterString.Substring(1, filterString.Length - 2));
                        }
                        else if (filterString.StartsWith("@", StringComparison.Ordinal))
                        {
                            return(Utility.ConvertLiteralToRegExp(filterString.Substring(1)));
                        }
                        else
                        {
                            return(Utility.ConvertGlobbingToRegExp(filterString));
                        }
                    })
                                                 .ToList();

                    string regexString;
                    if (regexStrings.Count == 1)
                    {
                        regexString = regexStrings.Single();
                    }
                    else
                    {
                        // If there are multiple regex strings, then they need to be merged by wrapping each in parenthesis and ORing them together
                        regexString = "(" + string.Join(")|(", regexStrings) + ")";
                    }

                    result = new Regex(regexString, REGEXP_OPTIONS);

                    FilterEntry.filterGroupRegexCache[filterGroup] = result;

                    return(result);
                }
            }
Exemplo n.º 2
0
        private static IEnumerable <string> Expand(string filter)
        {
            if (string.IsNullOrWhiteSpace(filter))
            {
                return(null);
            }

            if (filter.Length < 2 || (filter.StartsWith("[", StringComparison.Ordinal) && filter.EndsWith("]", StringComparison.Ordinal)))
            {
                return(new string[] { filter });
            }

            if (filter.StartsWith("{", StringComparison.Ordinal) && filter.EndsWith("}", StringComparison.Ordinal))
            {
                string      groupName   = filter.Substring(1, filter.Length - 2);
                FilterGroup filterGroup = FilterGroups.ParseFilterList(groupName, FilterGroup.None);
                return((filterGroup == FilterGroup.None) ? null : FilterGroups.GetFilterStrings(filterGroup));
            }

            return(filter.Split(new char[] { System.IO.Path.PathSeparator }, StringSplitOptions.RemoveEmptyEntries));
        }