/** * Replace all backreferences in the to pattern with the matched * groups of the source. * @param source the source file name. * @return the translated file name. */ protected String replaceReferences(String source) { List<String> v = reg.getGroups(source, regexpOptions); result.setLength(0); for (int i = 0; i < to.length; i++) { if (to[i] == '\\') { if (++i < to.length) { int value = Character.digit(to[i], DECIMAL); if (value > -1) { result.append(v.get(value)); } else { result.append(to[i]); } } else { // TODO - should throw an exception instead? result.append('\\'); } } else { result.append(to[i]); } } return result.substring(0); }