StringBuilder (int length, @NotNull CharSequence str, @Nullable String additionalChars, boolean escapeLineFeeds, boolean escapeBackSlash, @NotNull @NonNls StringBuilder buffer) { for (int idx = 0; idx < length; idx++) { char ch = str.charAt(idx); switch (ch) { case '\b' -> buffer.append("\\b"); case '\t' -> buffer.append("\\t"); case '\f' -> buffer.append("\\f"); case '\\' -> { if (escapeBackSlash) { buffer.append("\\\\"); } else { buffer.append('\\'); } } case '\n' -> { if (escapeLineFeeds) { buffer.append("\\n"); } else { buffer.append('\n'); } } case '\r' -> { if (escapeLineFeeds) { buffer.append("\\r"); } else { buffer.append('\r'); } } default -> { if (additionalChars != null && additionalChars.indexOf(ch) > -1) { buffer.append("\\").append(ch); } else if (Character.isISOControl(ch)) { appendUnicode(buffer, ch); } else { buffer.append(ch); } } } } return buffer; }