public static @NlsSafe String unescapeString(String s) {
    final int length = s.length();
    @NlsSafe StringBuilder buffer = new StringBuilder(length);
    boolean escaped = false;
    for (int idx = 0; idx < length; idx++) {
      char ch = s.charAt(idx);
      if (!escaped) {
        if (ch == '\\') {
          escaped = true;
        }
        else {
          buffer.append(ch);
        }
      }
      else {
        switch (ch) {
          case 'n' -> buffer.append('\n');
          case 'r' -> buffer.append('\r');
          case 'b' -> buffer.append('\b');
          case 't' -> buffer.append('\t');
          case 'f' -> buffer.append('\f');
          case '$' -> buffer.append('$');
          case '\'' -> buffer.append('\'');
          case '\"' -> buffer.append('\"');
          case '\\' -> buffer.append('\\');
          case '\n' -> {}
          //do nothing
          case 'u' -> {
            if (idx + 4 < length) {
              try {
                int code = Integer.valueOf(s.substring(idx + 1, idx + 5), 16).intValue();
                idx += 4;
                buffer.append((char)code);
              }
              catch (NumberFormatException e) {
                buffer.append("\\u");
              }
            }
            else {
              buffer.append("\\u");
            }
          }
          default -> {
            buffer.append('\\');
            buffer.append(ch);
          }
        }
        escaped = false;
      }
    }

    return buffer.toString();
  }
public static @NlsSafe String unescapeString(String s)