String (@NotNull String value, char delimiter, @NotNull PropertyKeyValueFormat valueFormat) { if (valueFormat == PropertyKeyValueFormat.FILE) return value; StringBuilder buffer = new StringBuilder(); for (int i = 0; i < value.length(); i++) { char c = value.charAt(i); if (c == '\n' || c == '\r') { buffer.append(ESCAPE_SYMBOL); if (valueFormat == PropertyKeyValueFormat.MEMORY) { buffer.append(c == '\n' ? 'n' : 'r'); } else { buffer.append(c); } } else if ((i == 0 && (c == ' ' || c == '\t')) // Leading white space || (delimiter == ' ' && (c == '=' || c == ':' /* special symbol */))) { buffer.append(ESCAPE_SYMBOL); buffer.append(c); } else if (c == ESCAPE_SYMBOL) { if (i + 1 >= value.length() || !isEscapedChar(value.charAt(i + 1)) || valueFormat == PropertyKeyValueFormat.MEMORY) { buffer.append(ESCAPE_SYMBOL); } buffer.append(c); } else { buffer.append(c); } } return buffer.toString(); }