void (String s) { int pos = 0; while(true) { int bracePos = s.indexOf('{', pos); if (bracePos < 1) break; char prevChar = s.charAt(bracePos-1); if (prevChar >= 'A' && prevChar <= 'Z') { appendText(s.substring(pos, bracePos - 1)); int rbracePos = findMatchingEndBrace(s, bracePos); if (rbracePos < 0) { pos = bracePos + 1; break; } final String inlineMarkupContent = s.substring(bracePos + 1, rbracePos); appendMarkup(prevChar, inlineMarkupContent); pos = rbracePos + 1; } else { appendText(s.substring(pos, bracePos + 1)); pos = bracePos+1; } } appendText(s.substring(pos)); } protected void appendText(String text) { myResult.append(text); } protected void appendMarkup(char markupChar, @NotNull String markupContent) { appendWithMarkup(markupContent); } public String result() { return myResult.toString(); } }