コード例 #1
0
        /// <summary>
        /// Extracts the matches of this pattern from <paramref name="source" />.
        /// </summary>
        /// <param name="filename">The name of the file associated with <paramref name="source" />.</param>
        /// <param name="source">The source string</param>
        /// <returns>
        /// A collection of found matches.
        /// </returns>
        public MatchCollection Extract(string filename, string source)
        {
            MatchCollection resultMatches = new MatchCollection();
            LineCounter     lineCounter   = new LineCounter(source);

            RegexMatch regexMatch = _scanner.Match(source);

            while (regexMatch.Success)
            {
                Match match = new Match();
                match["Path"]       = Path.GetDirectoryName(filename);
                match["File"]       = Path.GetFileName(filename);
                match["LineNumber"] = lineCounter.CountTo(regexMatch.Index).ToString();
                foreach (string groupName in _scanner.GetGroupNames())
                {
                    // ignore default-names like '0', '1' ... as produced
                    // by the Regex class
                    if (Char.IsLetter(groupName[0]) || (groupName[0] == '_'))
                    {
                        match[groupName] = ConcatenateCaptures(regexMatch.Groups[groupName]);
                    }
                }
                resultMatches.Add(match);
                regexMatch = regexMatch.NextMatch();
            }
            return(resultMatches);
        }
コード例 #2
0
ファイル: GrepTask.cs プロジェクト: raulramaya/nantcontrib
        /// <summary>
        /// Performs the regex-search.
        /// </summary>
        protected override void ExecuteTask()
        {
            MatchCollection matches = new MatchCollection();
            Pattern         pattern = new Pattern(Pattern);

            Log(Level.Info, "Writing matches to '{0}'.", OutputFile.FullName);

            foreach (string filename in InputFiles.FileNames)
            {
                using (StreamReader reader = new StreamReader(filename)) {
                    string fileContent = reader.ReadToEnd();
                    matches.Add(pattern.Extract(filename, fileContent));
                }
            }

            WriteMatches(matches);
        }
コード例 #3
0
ファイル: Pattern.cs プロジェクト: vardars/ci-factory
        /// <summary>
        /// Extracts the matches of this pattern from <paramref name="source" />.
        /// </summary>
        /// <param name="filename">The name of the file associated with <paramref name="source" />.</param>
        /// <param name="source">The source string</param>
        /// <returns>
        /// A collection of found matches.
        /// </returns>
        public MatchCollection Extract(string filename, string source)
        {
            MatchCollection resultMatches = new MatchCollection();
            LineCounter lineCounter = new LineCounter(source);

            RegexMatch regexMatch = _scanner.Match(source);
            while (regexMatch.Success) {
                Match match = new Match();
                match["Path"] = Path.GetDirectoryName(filename);
                match["File"] = Path.GetFileName(filename);
                match["LineNumber"] = lineCounter.CountTo(regexMatch.Index).ToString();
                foreach (string groupName in _scanner.GetGroupNames()) {
                    // ignore default-names like '0', '1' ... as produced
                    // by the Regex class
                    if (Char.IsLetter(groupName[0]) || (groupName[0] == '_')) {
                        match[groupName] = ConcatenateCaptures(regexMatch.Groups[groupName]);
                    }
                }
                resultMatches.Add(match);
                regexMatch = regexMatch.NextMatch();
            }
            return resultMatches;
        }
コード例 #4
0
ファイル: GrepTask.cs プロジェクト: kiprainey/nantcontrib
        /// <summary>
        /// Performs the regex-search.
        /// </summary>
        protected override void ExecuteTask() {
            MatchCollection matches = new MatchCollection();
            Pattern pattern = new Pattern(Pattern);

            Log(Level.Info, "Writing matches to '{0}'.", OutputFile.FullName);

            foreach (string filename in InputFiles.FileNames ) {
                using (StreamReader reader = new StreamReader(filename)) {
                    string fileContent = reader.ReadToEnd();
                    matches.Add(pattern.Extract(filename, fileContent));
                }
            }

            WriteMatches(matches);
        }