예제 #1
0
        /// <summary>
        ///     Similar to <see cref="IsMatch" /> but also provides the match groups for the glob parts
        /// </summary>
        /// <param name="stringToMatch"></param>
        /// <returns></returns>
        public MatchInfoResult MatchInfo(string stringToMatch)
        {
            ErrorUtilities.VerifyThrowArgumentNull(stringToMatch, nameof(stringToMatch));

            if (FileUtilities.PathIsInvalid(stringToMatch) ||
                !IsLegal)
            {
                return(MatchInfoResult.Empty);
            }

            var normalizedInput = NormalizeMatchInput(stringToMatch);

            bool   isMatch;
            string fixedDirectoryPart, wildcardDirectoryPart, filenamePart;

            FileMatcher.GetRegexMatchInfo(
                normalizedInput,
                _state.Value.Regex,
                out isMatch,
                out fixedDirectoryPart,
                out wildcardDirectoryPart,
                out filenamePart);

            return(new MatchInfoResult(isMatch, fixedDirectoryPart, wildcardDirectoryPart, filenamePart));
        }
예제 #2
0
        /// <summary>
        ///     Similar to <see cref="IsMatch" /> but also provides the match groups for the glob parts
        /// </summary>
        /// <param name="stringToMatch"></param>
        /// <returns></returns>
        public MatchInfoResult MatchInfo(string stringToMatch)
        {
            ErrorUtilities.VerifyThrowArgumentNull(stringToMatch, nameof(stringToMatch));

            if (FileUtilities.PathIsInvalid(stringToMatch) || !IsLegal)
            {
                return(MatchInfoResult.Empty);
            }

            string normalizedInput = NormalizeMatchInput(stringToMatch);

            FileMatcher.GetRegexMatchInfo(
                normalizedInput,
                _state.Value.Regex,
                out bool isMatch,
                out string wildcardDirectoryPart,
                out string filenamePart);

            // We don't capture the fixed directory part in the regex but we can infer it from the other two.
            int    fixedDirectoryPartLength = normalizedInput.Length - wildcardDirectoryPart.Length - filenamePart.Length;
            string fixedDirectoryPart       = normalizedInput.Substring(0, fixedDirectoryPartLength);

            return(new MatchInfoResult(isMatch, fixedDirectoryPart, wildcardDirectoryPart, filenamePart));
        }