/** * Returns a matcher for a match result (in a performance-friendly way). * <code>groupId</code> parameter specifies which group is a target. * * @param groupId which group is a target; either positive integer(group id), or one of MatchResult.MATCH,MatchResult.PREFIX,MatchResult.SUFFIX,MatchResult.TARGET. */ public Matcher matcher(MatchResult res, int groupId) { Matcher m = new Matcher(this); if (res instanceof Matcher) { m.setTarget((Matcher) res, groupId); } else { m.setTarget(res.targetChars(), res.start(groupId) + res.targetStart(), res.length(groupId)); } return m; }
/** * Returns a matcher for a match result (in a performance-friendly way). * <code>groupId</code> parameter specifies which group is a target. * * @param groupId which group is a target; either positive integer(group id), or one of MatchResult.MATCH,MatchResult.PREFIX,MatchResult.SUFFIX,MatchResult.TARGET. */ public Matcher matcher(MatchResult res, int groupId) { Matcher m = new Matcher(this); if (res instanceof Matcher) { m.setTarget((Matcher) res, groupId); } else { m.setTarget(res.targetChars(), res.start(groupId) + res.targetStart(), res.length(groupId)); } return m; }
@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); } }