int pos = 0;
while (inputMatcher.find()) {
String match2 = inputMatcher.group();
if (pos != inputMatcher.start()) {
throw new PermErrorException("Middle part does not match: "+input.substring(0,pos)+">>"+input.substring(pos, inputMatcher.start())+"<<"+input.substring(inputMatcher.start())+" ["+input+"]");
}
if (match2.length() > 0) {
if (match2.startsWith("%{")) {
macroCell = input.substring(inputMatcher.start() + 2, inputMatcher
.end() - 1);
inputMatcher
.appendReplacement(decodedValue, replaceCell(macroCell, macroData, isExplanation));
} else if (match2.length() == 2 && match2.startsWith("%")) {
// handle the % escaping
inputMatcher.appendReplacement(decodedValue, match2.substring(1));
}
}
pos = inputMatcher.end();
}
if (input.length() != pos) {
throw new PermErrorException("End part does not match: "+input.substring(pos));
}
inputMatcher.appendTail(decodedValue);
return decodedValue.toString();