Esempio n. 1
0
        /// <summary>
        /// Matches the given path against a pattern.
        /// </summary>
        /// <param name="pattern">A <see cref="string"/> containing a wildcard.</param>
        /// <param name="path">The <see cref="string"/> to be matched.</param>
        /// <param name="flags">Additional flags.</param>
        /// <returns><c>true</c> if the <paramref name="path"/> matches with the given
        /// wildcard <paramref name="pattern"/>.</returns>
        public static bool fnmatch(string /*!*/ pattern, string /*!*/ path, FnMatchOptions flags = FnMatchOptions.None)
        {
            if (pattern.Length == 0)
            {
                return(path.Length == 0);
            }

            bool   pathName     = ((flags & FnMatchOptions.PathName) != 0);
            bool   noEscape     = ((flags & FnMatchOptions.NoEscape) != 0);
            string regexPattern = PatternToRegex(pattern, pathName, noEscape);

            if (regexPattern.Length == 0)
            {
                return(false);
            }

            if (((flags & FnMatchOptions.Period) == 0) && path.Length > 0 && path[0] == '.')
            {
                // Starting dot requires an explicit dot in the pattern
                if (regexPattern.Length < 4 || regexPattern[2] != '[' || regexPattern[3] != '.')
                {
                    return(false);
                }
            }

            var options = System.Text.RegularExpressions.RegexOptions.None;

            if ((flags & FnMatchOptions.CaseFold) != 0)
            {
                options |= System.Text.RegularExpressions.RegexOptions.IgnoreCase;
            }
            var match = System.Text.RegularExpressions.Regex.Match(path, regexPattern, options);

            return(match != null && match.Success && (match.Length == path.Length));
        }
Esempio n. 2
0
            public GlobMatcher(string /*!*/ pattern, GlobOptions flags)
            {
                _pattern = CanonizePattern(pattern);
                _flags   = flags;
                _result  = new List <string>();
                _dirOnly = _pattern.LastCharacter() == '/' || (flags & GlobOptions.OnlyDir) != 0;

                _fnMatchFlags = NoEscapes ? FnMatchOptions.NoEscape : FnMatchOptions.None;
            }
Esempio n. 3
0
            public GlobMatcher(Context ctx, string /*!*/ pattern, GlobOptions flags)
            {
                Debug.Assert(ctx != null);

                _ctx     = ctx;
                _pattern = CanonizePattern(pattern);
                _flags   = flags;
                _result  = new List <string>();
                _dirOnly = _pattern.LastCharacter() == '/' || (flags & GlobOptions.OnlyDir) != 0;

                _fnMatchFlags = NoEscapes ? FnMatchOptions.NoEscape : FnMatchOptions.None;
            }
Esempio n. 4
0
        public static bool FnMatch(string/*!*/ pattern, string/*!*/ path, FnMatchOptions flags)
        {
            if (pattern.Length == 0)
            {
                return path.Length == 0;
            }

            bool pathName = ((flags & FnMatchOptions.PathName) != 0);
            bool noEscape = ((flags & FnMatchOptions.NoEscape) != 0);
            string regexPattern = PatternToRegex(pattern, pathName, noEscape);
            if (regexPattern.Length == 0)
            {
                return false;
            }

            if (((flags & FnMatchOptions.Period) == 0) && path.Length > 0 && path[0] == '.')
            {
                // Starting dot requires an explicit dot in the pattern
                if (regexPattern.Length < 4 || regexPattern[2] != '[' || regexPattern[3] != '.')
                {
                    return false;
                }
            }

            RegexOptions options = RegexOptions.None;
            if ((flags & FnMatchOptions.CaseFold) != 0)
            {
                options |= RegexOptions.IgnoreCase;
            }
            Match match = Regex.Match(path, regexPattern, options);
            return match != null && match.Success && (match.Length == path.Length);
        }
Esempio n. 5
0
            public GlobMatcher(string/*!*/ pattern, GlobOptions flags)
            {
                _pattern = FileSystemUtils.CanonicalizePath(pattern);
                _flags = flags;
                _result = new List<string>();
                _dirOnly = _pattern.LastCharacter() == '/' || (flags & GlobOptions.OnlyDir) != 0;

                _fnMatchFlags = NoEscapes ? FnMatchOptions.NoEscape : FnMatchOptions.None;
            }