@Test public void missingClosingCurlyBracket() { assertThat(format("{ Hello", "tinylog")).isEqualTo("{ Hello"); assertThat(format("Hello {", "tinylog")).isEqualTo("Hello {"); }
@Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder buffer = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder current = builder; int argumentIndex = 0; int openingTickIndex = -1; int openingCurlyBrackets = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (escape && character == '\'' && index + 1 < length && openingCurlyBrackets == 0) { if (message.charAt(index + 1) == '\'') { current.append('\''); index += 1; } else { openingTickIndex = openingTickIndex < 0 ? index : -1; } } else if (character == '{' && index + 1 < length && argumentIndex < arguments.length && openingTickIndex < 0) { if (openingCurlyBrackets++ == 0) { current = buffer; } else { current.append(character); } } else if (character == '}' && openingCurlyBrackets > 0 && openingTickIndex < 0) { if (--openingCurlyBrackets == 0) { Object argument = resolve(arguments[argumentIndex++]); if (buffer.length() == 0) { builder.append(argument); } else { builder.append(format(buffer.toString(), argument)); buffer.setLength(0); } buffer.setLength(0); current = builder; } else { current.append(character); } } else { current.append(character); } } if (buffer.length() > 0) { builder.append('{'); builder.append(buffer); } if (openingTickIndex >= 0) { builder.insert(openingTickIndex, '\''); } return builder.toString(); }
AdvancedMessageFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder buffer = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder current = builder; int argumentIndex = 0; int openingTickIndex = -1; int openingCurlyBrackets = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (escape && character == '\'' && index + 1 < length && openingCurlyBrackets == 0) { if (message.charAt(index + 1) == '\'') { current.append('\''); index += 1; } else { openingTickIndex = openingTickIndex < 0 ? index : -1; } } else if (character == '{' && index + 1 < length && argumentIndex < arguments.length && openingTickIndex < 0) { if (openingCurlyBrackets++ == 0) { current = buffer; } else { current.append(character); } } else if (character == '}' && openingCurlyBrackets > 0 && openingTickIndex < 0) { if (--openingCurlyBrackets == 0) { Object argument = resolve(arguments[argumentIndex++]); if (buffer.length() == 0) { builder.append(argument); } else { builder.append(format(buffer.toString(), argument)); buffer.setLength(0); } buffer.setLength(0); current = builder; } else { current.append(character); } } else { current.append(character); } } if (buffer.length() > 0) { builder.append('{'); builder.append(buffer); } if (openingTickIndex >= 0) { builder.insert(openingTickIndex, '\''); } return builder.toString(); } }
AdvancedMessageFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder buffer = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder current = builder; int argumentIndex = 0; int openingTickIndex = -1; int openingCurlyBrackets = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (escape && character == '\'' && index + 1 < length && openingCurlyBrackets == 0) { if (message.charAt(index + 1) == '\'') { current.append('\''); index += 1; } else { openingTickIndex = openingTickIndex < 0 ? index : -1; } } else if (character == '{' && index + 1 < length && argumentIndex < arguments.length && openingTickIndex < 0) { if (openingCurlyBrackets++ == 0) { current = buffer; } else { current.append(character); } } else if (character == '}' && openingCurlyBrackets > 0 && openingTickIndex < 0) { if (--openingCurlyBrackets == 0) { Object argument = resolve(arguments[argumentIndex++]); if (buffer.length() == 0) { builder.append(argument); } else { builder.append(format(buffer.toString(), argument)); buffer.setLength(0); } buffer.setLength(0); current = builder; } else { current.append(character); } } else { current.append(character); } } if (buffer.length() > 0) { builder.append('{'); builder.append(buffer); } if (openingTickIndex >= 0) { builder.insert(openingTickIndex, '\''); } return builder.toString(); } AdvancedMessageFormatter(final Locale locale, final boolean escape); }
AdvancedMessageFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder buffer = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder current = builder; int argumentIndex = 0; int openingTickIndex = -1; int openingCurlyBrackets = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (escape && character == '\'' && index + 1 < length && openingCurlyBrackets == 0) { if (message.charAt(index + 1) == '\'') { current.append('\''); index += 1; } else { openingTickIndex = openingTickIndex < 0 ? index : -1; } } else if (character == '{' && index + 1 < length && argumentIndex < arguments.length && openingTickIndex < 0) { if (openingCurlyBrackets++ == 0) { current = buffer; } else { current.append(character); } } else if (character == '}' && openingCurlyBrackets > 0 && openingTickIndex < 0) { if (--openingCurlyBrackets == 0) { Object argument = resolve(arguments[argumentIndex++]); if (buffer.length() == 0) { builder.append(argument); } else { builder.append(format(buffer.toString(), argument)); buffer.setLength(0); } buffer.setLength(0); current = builder; } else { current.append(character); } } else { current.append(character); } } if (buffer.length() > 0) { builder.append('{'); builder.append(buffer); } if (openingTickIndex >= 0) { builder.insert(openingTickIndex, '\''); } return builder.toString(); } AdvancedMessageFormatter(final Locale locale, final boolean escape); @Override String format(final String message, final Object[] arguments); }
AdvancedMessageFormatter extends AbstractMessageFormatter { @Override public String format(final String message, final Object[] arguments) { int length = message.length(); StringBuilder builder = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder buffer = new StringBuilder(length + ADDITIONAL_STRING_BUILDER_CAPACITY); StringBuilder current = builder; int argumentIndex = 0; int openingTickIndex = -1; int openingCurlyBrackets = 0; for (int index = 0; index < length; ++index) { char character = message.charAt(index); if (escape && character == '\'' && index + 1 < length && openingCurlyBrackets == 0) { if (message.charAt(index + 1) == '\'') { current.append('\''); index += 1; } else { openingTickIndex = openingTickIndex < 0 ? index : -1; } } else if (character == '{' && index + 1 < length && argumentIndex < arguments.length && openingTickIndex < 0) { if (openingCurlyBrackets++ == 0) { current = buffer; } else { current.append(character); } } else if (character == '}' && openingCurlyBrackets > 0 && openingTickIndex < 0) { if (--openingCurlyBrackets == 0) { Object argument = resolve(arguments[argumentIndex++]); if (buffer.length() == 0) { builder.append(argument); } else { builder.append(format(buffer.toString(), argument)); buffer.setLength(0); } buffer.setLength(0); current = builder; } else { current.append(character); } } else { current.append(character); } } if (buffer.length() > 0) { builder.append('{'); builder.append(buffer); } if (openingTickIndex >= 0) { builder.insert(openingTickIndex, '\''); } return builder.toString(); } AdvancedMessageFormatter(final Locale locale, final boolean escape); @Override String format(final String message, final Object[] arguments);  }