public static int ReplaceFirst(Matcher m,Substitution substitution,TextBuffer dest) { int c=0; if(m.Find()) { if(m.Start>0) m.Group(Matcher.PREFIX,dest); substitution.AppendSubstitution(m,dest); c++; m.SetTarget(m,Matcher.SUFFIX); } m.Group(Matcher.TARGET,dest); return c; }
public static int Replace(Matcher m,Substitution substitution,TextBuffer dest) { bool firstPass=true; int c=0; while(m.Find()) { if(m.End==0 && !firstPass) continue; //allow to Replace at "^" if(m.Start>0) m.Group(Matcher.PREFIX,dest); substitution.AppendSubstitution(m,dest); c++; m.SetTarget(m,Matcher.SUFFIX); firstPass=false; } m.Group(Matcher.TARGET,dest); return c; }