MessageParser { public MessageElement next() { StringBuilder str = new StringBuilder(); int i = this.bufferIndex; for (; i < this.buffer.length; ++i) { if (this.buffer[i] == ESCAPE_CHAR) { int nb = countEscaping(i); int iNext = i + nb; if (iNext == this.buffer.length) { i = iNext; break; } else { if (isMessageIndex(iNext) > iNext) { str.append(this.buffer, this.bufferIndex, iNext - 1 - this.bufferIndex); i = iNext; this.bufferIndex = i; if (nb > 1) { this.previousWasDoubleEscaped = true; this.currentMessageElement = new MessageString(str.toString()); return this.currentMessageElement; } } else { i = iNext; } } } else if (this.buffer[i] == ARGUMENT_START) { int iNext = isMessageIndex(i); if (iNext != i) { if (this.bufferIndex == i) { String messageIndexString = String.valueOf(this.buffer, i, iNext - i); int messageIndex; if (this.translations && messageIndexString.length() > 2) { messageIndex = Integer.parseInt(messageIndexString.substring(1, messageIndexString.length() - 1)); } else { messageIndex = this.currentMessageIndex; } ++this.currentMessageIndex; if (this.previousWasDoubleEscaped) { this.currentMessageElement = new MessageIndex("\\" + messageIndexString, messageIndex); } else { this.currentMessageElement = new MessageIndex(messageIndexString, messageIndex); } this.bufferIndex = iNext; return this.currentMessageElement; } else { this.currentMessageElement = new MessageString(String.valueOf(this.buffer, this.bufferIndex, i - this.bufferIndex)); this.bufferIndex = i; return this.currentMessageElement; } } } } if (i == this.bufferIndex) { return null; } this.currentMessageElement = new MessageString(String.valueOf(this.buffer, this.bufferIndex, i - this.bufferIndex)); this.bufferIndex = i; return this.currentMessageElement; } MessageParser(String buffer, boolean translations);  MessageParser(char[] buffer, boolean translations); MessageElement getCurrentMessageElement(); MessageElement next(); static final String ARGUMENT_STR; }
@Test void plain() { MessageParser parser = new MessageParser("plain text", false); assertEquals("plain text", parser.next().getString()); assertNull(parser.next()); parser = new MessageParser("plain text", true); assertEquals("plain text", parser.next().getString()); assertNull(parser.next()); }