public boolean getGroup(int group, StringBuilder sb) { return getGroup(group, sb, 0); } public boolean getGroup(int group, StringBuilder sb, int modes) {
public boolean getGroup(String name, TextBuffer tb) { return getGroup(name, tb, 0); } public boolean getGroup(String name, TextBuffer tb, int modes) {
public boolean getGroup(String name, StringBuilder sb) { return getGroup(name, sb, 0); } public boolean getGroup(String name, StringBuilder sb, int modes) {
public boolean getGroup(int group, TextBuffer tb) { return getGroup(group, tb, 0); } public boolean getGroup(int group, TextBuffer tb, int modes) {
public boolean getGroup(String name, StringBuilder sb) { return getGroup(name, sb, 0); } public boolean getGroup(String name, StringBuilder sb, int modes) {
public boolean getGroup(int group, TextBuffer tb) { return getGroup(group, tb, 0); } public boolean getGroup(int group, TextBuffer tb, int modes) {
public boolean getGroup(String name, TextBuffer tb) { return getGroup(name, tb, 0); } public boolean getGroup(String name, TextBuffer tb, int modes) {
public boolean getGroup(int group, StringBuilder sb) { return getGroup(group, sb, 0); } public boolean getGroup(int group, StringBuilder sb, int modes) {
public boolean getGroup(String name, TextBuffer tb, int modes) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("unknown group: \"" + name + "\""); return getGroup(id, tb); }
public boolean getGroup(String name, TextBuffer tb, int modes) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("unknown group: \"" + name + "\""); return getGroup(id, tb); }
public boolean getGroup(String name, StringBuilder sb, int modes) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("unknown group: \"" + name + "\""); return getGroup(id, sb); }
public boolean getGroup(String name, StringBuilder sb, int modes) { Integer id = re.groupId(name); if (id == null) throw new IllegalArgumentException("unknown group: \"" + name + "\""); return getGroup(id, sb); }
public StringBuffer appendTail(StringBuffer sb) { matcher.getGroup(regexodus.MatchResult.TARGET, Replacer.wrap(sb)); return sb; }
/** * Implements a terminal append-and-replace step. * * <p> This method reads characters from the input sequence, starting at * the append position, and appends them to the given string buffer. It is * intended to be invoked after one or more invocations of the {@link * #appendReplacement appendReplacement} method in order to copy the * remainder of the input sequence. </p> * * @param sb * The target string buffer * * @return The target string buffer */ public StringBuffer appendTail(StringBuffer sb) { matcher.getGroup(regexodus.MatchResult.TARGET, Replacer.wrap(sb)); return sb; }
/** * Replaces all occurrences of a matcher's pattern in a matcher's target * by a given substitution appending the result to a buffer.<br> * The substitution starts from current matcher's position, current match * not included. */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0; while (m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces all occurrences of a matcher's pattern in a matcher's target * by a given substitution appending the result to a buffer.<br> * The substitution starts from current matcher's position, current match * not included. */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0; while (m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces the first n occurrences of a matcher's pattern, where n is equal to count, * in a matcher's target by a given substitution, appending the result to a buffer. * <br> * The substitution starts from current matcher's position, current match not included. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @param count the number of replacements to attempt * @return the number of replacements performed */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest, int count) { boolean firstPass = true; int c = 0; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
/** * Replaces the first n occurrences of a matcher's pattern, where n is equal to count, * in a matcher's target by a given substitution, appending the result to a buffer. * <br> * The substitution starts from current matcher's position, current match not included. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @param count the number of replacements to attempt * @return the number of replacements performed */ public static int replace(Matcher m, Substitution substitution, TextBuffer dest, int count) { boolean firstPass = true; int c = 0; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } m.getGroup(MatchResult.TARGET, dest); return c; }
@Override public void appendSubstitution(MatchResult match, TextBuffer dest) { if(match instanceof Matcher) { wordMatcher.setTarget((Matcher)match, 1); } else { wordMatcher.setTarget(match.targetChars(), match.start(1) + match.targetStart(), match.length(1)); } while (wordMatcher.find()) { wordMatcher.getGroup(MatchResult.PREFIX, dest); dest.append(lookup(wordMatcher.group())); wordMatcher.setTarget(wordMatcher, MatchResult.SUFFIX); } wordMatcher.getGroup(MatchResult.TARGET, dest); } }
/** * Replaces the next occurrence of a matcher's pattern in a matcher's target by a given substitution, appending the * result to a buffer but not writing the remainder of m's match to the end of dest. * <br> * The substitution starts from current matcher's position, current match not included. * <br> * You typically want to call {@code m.getGroup(MatchResult.TARGET, dest);} after you have called replaceStep() * until it returns false, which will fill in the remainder of the matching text into dest. * @param m a Matcher * @param substitution a Substitution, typically a PerlSubstitution * @param dest the TextBuffer this will write to; see Replacer.wrap() * @return the number of replacements performed */ public static boolean replaceStep(Matcher m, Substitution substitution, TextBuffer dest) { boolean firstPass = true; int c = 0, count = 1; while (c < count && m.find()) { if (m.end() == 0 && !firstPass) continue; //allow to replace at "^" if (m.start() > 0) m.getGroup(MatchResult.PREFIX, dest); substitution.appendSubstitution(m, dest); c++; m.setTarget(m, MatchResult.SUFFIX); firstPass = false; } return c > 0; }