String (@NotNull String s) { StringBuilder sb = new StringBuilder(s.length()); for (int i = 0; i < s.length(); i++) { char ch = s.charAt(i); char escape = switch (ch) { case '\n' -> 'n'; case '\r' -> 'r'; case '\'', '|', '[', ']' -> ch; default -> 0; }; if (escape != 0) { sb.append('|').append(escape); } else if (ch < 0x20 /* space */ || ch >= 0x7f /* DEL */) { sb.append(String.format("0x%04x", (short)ch)); } else { sb.append(ch); } } return sb.toString(); }