PlainText extends TemplateUnit { static public String unescape(String s) { StringBuilder sb = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char c1 = s.charAt(i); if (c1 == '@' && (i+1) < s.length()) { char c2 = s.charAt(i+1); if (c2 == '@') { sb.append("@"); i++; continue; } else if (c2 == '}') { sb.append("}"); i++; continue; } else if (c2 == '{') { sb.append("{"); i++; continue; } } else if (c1 == '\r' && (i+1) < s.length()) { char c2 = s.charAt(i+1); if (c2 == '\n') { sb.append("\n"); i++; continue; } } sb.append(c1); } return sb.toString(); } PlainText(SourceRef sourceRef, String text); String getText(); PlainText combineAdjacent(PlainText other); boolean isWhitespace(); void trim(); int trailingWhitespaceLengthToStartOfLine(); int leadingWhitespaceLengthToEndOfLine(); int chompTrailingWhitespaceToStartOfLine(); void chompTrailingLength(int length); int chompLeadingWhitespaceToEndOfLine(); void chompLeadingLength(int length); SourcePosition findSourcePositionOfNonWhitespace(); static String unescape(String s);  }
@Test public void unescape() throws Exception { Assert.assertEquals("@", PlainText.unescape("@@")); Assert.assertEquals("}", PlainText.unescape("@}")); Assert.assertEquals("{", PlainText.unescape("@{")); Assert.assertEquals("@}", PlainText.unescape("@@@}")); Assert.assertEquals("h@}t", PlainText.unescape("h@@@}t")); Assert.assertEquals("@{", PlainText.unescape("@@@{")); Assert.assertEquals("h@{t", PlainText.unescape("h@@@{t")); Assert.assertEquals("h\nt", PlainText.unescape("h\r\nt")); Assert.assertEquals("h\nt", PlainText.unescape("h\nt")); Assert.assertEquals("@\n@\n}{\r", PlainText.unescape("@@\r\n@\n@}@{\r")); }