BraceStyleMessageParser extends MessageParser { static void unescapeBraceFormat(StringBuilder out, String message, int start, int end) { int pos = start; boolean isQuoted = false; while (pos < end) { char c = message.charAt(pos++); if (c != '\\' && c != '\'') { continue; } int quoteStart = pos - 1; if (c == '\\') { c = message.charAt(pos++); if (c != '\'') { continue; } } out.append(message, start, quoteStart); start = pos; if (pos == end) { break; } if (isQuoted) { isQuoted = false; } else if (message.charAt(pos) != '\'') { isQuoted = true; } else { pos++; } } if (start < end) { out.append(message, start, end); } }  @Override final void unescape(StringBuilder out, String message, int start, int end);  }
@Test public void testUnescapeBraceFormat() { assertThat(unescapeBraceFormat("")).isEqualTo(""); assertThat(unescapeBraceFormat("Hello World")).isEqualTo("Hello World"); assertThat(unescapeBraceFormat("Hello '{}' World")).isEqualTo("Hello {} World"); assertThat(unescapeBraceFormat("Hello \'{}\' World")).isEqualTo("Hello {} World"); assertThat(unescapeBraceFormat("Hello \'{}' World")).isEqualTo("Hello {} World"); assertThat(unescapeBraceFormat("Hello '' World")).isEqualTo("Hello ' World"); assertThat(unescapeBraceFormat("Hello \'\' World")).isEqualTo("Hello ' World"); assertThat(unescapeBraceFormat("Hello '\' World")).isEqualTo("Hello ' World"); assertThat(unescapeBraceFormat("He'llo'' ''Wor'ld")).isEqualTo("Hello World"); assertThat(unescapeBraceFormat("He'llo'\' \''Wor\'ld")).isEqualTo("Hello World"); }
@Test public void testUnescapeBraceFormatIgnoresErrors() { assertThat(unescapeBraceFormat("Hello '")).isEqualTo("Hello "); assertThat(unescapeBraceFormat("Hello \\'")).isEqualTo("Hello "); }