private static IList <Scope> GetCapturedMatches(Match regexMatch, CompiledMacro macro, IList <Scope> capturedMatches, Regex regex) { for (int i = 0; i < regexMatch.Groups.Count; i++) { if (regex.GroupNameFromNumber(i) != i.ToString()) { continue; } Group regexGroup = regexMatch.Groups[i]; string capture = macro.Captures[i]; if (regexGroup.Captures.Count == 0 || String.IsNullOrEmpty(capture)) { continue; } foreach (Capture regexCapture in regexGroup.Captures) { AppendCapturedMatchesForRegexCapture(regexCapture, capture, capturedMatches); } } return(capturedMatches); }
private static void Parse(string wikiContent, IMacro macro, CompiledMacro compiledMacro, IScopeAugmenter augmenter, Action <IList <Scope> > parseHandler) { Match regexMatch = compiledMacro.Regex.Match(wikiContent); if (!regexMatch.Success) { return; } IList <Scope> capturedScopes = new List <Scope>(); while (regexMatch.Success) { string matchedContent = wikiContent.Substring(regexMatch.Index, regexMatch.Length); if (!string.IsNullOrEmpty(matchedContent)) { capturedScopes = GetCapturedMatches(regexMatch, compiledMacro, capturedScopes, compiledMacro.Regex); } regexMatch = regexMatch.NextMatch(); } if (augmenter != null && capturedScopes.Count > 0) { capturedScopes = augmenter.Augment(macro, capturedScopes, wikiContent); } if (capturedScopes.Count > 0) { parseHandler(capturedScopes); } }