@Test public void testUnescapePrintf() { assertThat(unescapePrintf("")).isEqualTo(""); assertThat(unescapePrintf("Hello World")).isEqualTo("Hello World"); assertThat(unescapePrintf("Hello %% World")).isEqualTo("Hello % World"); assertThat(unescapePrintf("Hello %%%% World")).isEqualTo("Hello %% World"); assertThat(unescapePrintf("%% 'Hello {%%}{%%} World' %%")) .isEqualTo("% 'Hello {%}{%} World' %"); }
static void unescapePrintf(StringBuilder out, String message, int start, int end) { int pos = start; while (pos < end) { if (message.charAt(pos++) != '%') { continue; } if (pos == end) { break; } char chr = message.charAt(pos); if (chr == '%') { out.append(message, start, pos); } else if (chr == 'n') { out.append(message, start, pos - 1); out.append(SYSTEM_NEWLINE); } else { continue; } start = ++pos; } if (start < end) { out.append(message, start, end); } }
PrintfMessageParser extends MessageParser { static void unescapePrintf(StringBuilder out, String message, int start, int end) { int pos = start; while (pos < end) { if (message.charAt(pos++) != '%') { continue; } if (pos == end) { break; } char chr = message.charAt(pos); if (chr == '%') { out.append(message, start, pos); } else if (chr == 'n') { out.append(message, start, pos - 1); out.append(SYSTEM_NEWLINE); } else { continue; } start = ++pos; } if (start < end) { out.append(message, start, end); } } }
PrintfMessageParser extends MessageParser { static void unescapePrintf(StringBuilder out, String message, int start, int end) { int pos = start; while (pos < end) { if (message.charAt(pos++) != '%') { continue; } if (pos == end) { break; } char chr = message.charAt(pos); if (chr == '%') { out.append(message, start, pos); } else if (chr == 'n') { out.append(message, start, pos - 1); out.append(SYSTEM_NEWLINE); } else { continue; } start = ++pos; } if (start < end) { out.append(message, start, end); } }  }
PrintfMessageParser extends MessageParser { static void unescapePrintf(StringBuilder out, String message, int start, int end) { int pos = start; while (pos < end) { if (message.charAt(pos++) != '%') { continue; } if (pos == end) { break; } char chr = message.charAt(pos); if (chr == '%') { out.append(message, start, pos); } else if (chr == 'n') { out.append(message, start, pos - 1); out.append(SYSTEM_NEWLINE); } else { continue; } start = ++pos; } if (start < end) { out.append(message, start, end); } }  @Override final void unescape(StringBuilder out, String message, int start, int end); }
PrintfMessageParser extends MessageParser { static void unescapePrintf(StringBuilder out, String message, int start, int end) { int pos = start; while (pos < end) { if (message.charAt(pos++) != '%') { continue; } if (pos == end) { break; } char chr = message.charAt(pos); if (chr == '%') { out.append(message, start, pos); } else if (chr == 'n') { out.append(message, start, pos - 1); out.append(SYSTEM_NEWLINE); } else { continue; } start = ++pos; } if (start < end) { out.append(message, start, end); } }  @Override final void unescape(StringBuilder out, String message, int start, int end);  }