public StringMatchCollectionEnumerator(StringMatchCollection collection) { match_collection = collection; index = -1; }
public void ResultMatch() { result = new StringMatchCollection (" (?<Result>tropical)[ \n]", source); Assert.AreEqual(6, result.Count); }
public void Count() { result = new StringMatchCollection ("Gandu, A. W.", source); Assert.AreEqual(2, result.Count); }
public void FullMatch() { full = new StringMatchCollection ("(sub)?tropical", source); Assert.AreEqual(8, full.Count); }
public void ApplyRule(Rule rule) { string result, source = ""; StringMatchCollection matches; switch (rule.Block) { case BlockType.GLOBAL: source = text; break; case BlockType.FRONT: source = front; break; case BlockType.BODY: source = body; break; case BlockType.BACK: source = back; break; } Logger.Info ("Aplicando regla: {0} en bloque {1}", rule.Name, rule.Block); matches = new StringMatchCollection (rule.Regexp, source); if (rule.UniqueMatch) { if (matches.Count == 0) { switch (rule.Sustitution) { case "#{Front}": case "#{Body}": case "#{Back}": Logger.Error ("La regla necesaria {0} no obtuvo resultados", rule.Name); throw new NormalizerException ( "La normalización con el estilo \"" + format + "\" se ha cancelado, verifica la elección del estilo."); default: Logger.Warning ("No se encontraron matches con la regla {0}", rule.Name); break; } return; } else if (matches.Count > 1) { Logger.Warning ("Se encontró mas de un match en la regla {0}, se tomó el primero", rule.Name); } StringMatch match = matches [0]; Logger.Debug ("Match: {0}", match.FullMatch); if (rule.Type == RuleType.STATIC) { result = rule.Sustitution; source = source.Replace (match.FullMatch, result); Logger.Debug ("Result: {0}", result); } else { result = match.ApplyModifiers (rule.Modifiers, rule.Type); switch (rule.Sustitution) { case "#{Front}": front = result; break; case "#{Body}": body = result; break; case "#{Back}": back = result; break; case "#{Result}": source = source.Replace (match.FullMatch, result); break; } Logger.Debug ("Result: {0}", result); } } else { Logger.Info ("Total Matches: {0}", matches.Count ); foreach (StringMatch m in matches) { Logger.Debug ("Match: {0}", m.FullMatch); if (rule.Type == RuleType.STATIC) result = rule.Sustitution; else result = m.ApplyModifiers (rule.Modifiers, rule.Type); source = source.Replace (m.FullMatch, result); Logger.Debug ("Result: {0}", result); } } switch (rule.Block) { case BlockType.GLOBAL: text = source; break; case BlockType.FRONT: front = source; break; case BlockType.BODY: body = source; break; case BlockType.BACK: back = source; break; } }