String (@NotNull String text, boolean escapeApostrophes, boolean escapeSpaces, boolean escapeLineEnds) { StringBuilder buffer = null; for (int i = 0; i < text.length(); i++) { char ch = text.charAt(i); String quotation = escapeChar(ch, escapeApostrophes, escapeSpaces, escapeLineEnds); buffer = XmlStringUtil.appendEscapedSymbol(text, buffer, i, quotation, ch); } // If there were any entities, return the escaped characters // that we put in the StringBuffer. Otherwise, just return // the unmodified input string. return buffer == null ? text : buffer.toString(); }