String (@NotNull String referenceText, boolean removeWhitespace) { if (removeWhitespace) { referenceText = removeWhitespace(referenceText); } if (referenceText.indexOf('<') < 0) return referenceText; final StringBuilder buffer = new StringBuilder(referenceText.length()); final char[] chars = referenceText.toCharArray(); int gtPos = 0; int count = 0; for (int i = 0; i < chars.length; i++) { final char aChar = chars[i]; switch (aChar) { case '<': count++; if (count == 1) buffer.append(new String(chars, gtPos, i - gtPos)); break; case '>': count--; gtPos = i + 1; break; } } if (count == 0) { buffer.append(new String(chars, gtPos, chars.length - gtPos)); } return buffer.toString(); }