String (String template) { myTemplate = template; resetState(); while (myCursor < myTemplate.length()) { char nextChar = myTemplate.charAt(myCursor++); if (nextChar == '\\') { processEscapedChar(); } else if (nextChar == '$') { processGroupValue(); } else { myReplacement.append(nextChar); } } return generateResult(); }