String (@NotNull String content) { final StringBuilder result = new StringBuilder(); boolean nextCharEscaped = false; for (int i = 0; i < content.length(); i++) { final char c = content.charAt(i); if ((nextCharEscaped && c != '\'') || (!nextCharEscaped && c == '"')) { result.append('\\'); } if (c != '\\' || nextCharEscaped) { result.append(c); nextCharEscaped = false; } else { nextCharEscaped = true; } } if (nextCharEscaped) { result.append('\\'); } return result.toString(); }