private static void appendQuoted(StringBuilder sb, String s) {
    if (s.isEmpty()) return;

    s = backslashEscapeQuotes(s);
    if (WIN_CARET_SPECIAL.matcher(s).find()) s = quote(s, Q);

    // Can't just concatenate two quoted strings, like ["foo"] and ["bar"],
    // the two quotes inside would be treated as ["] upon unescaping, that is:
    //
    //   ["foo""bar"] -> [foo"bar]  # [""""] -> ["] (oops...)
    //
    int numTrailingBackslashes = removeClosingQuote(sb);
    if (numTrailingBackslashes < 0) {
      // sb was not quoted at its end
      sb.append(s);
    }
    else {
      s = StringUtilRt.unquoteString(s, Q);

      if (WIN_BACKSLASHES_PRECEDING_QUOTE.matcher(s).matches()) {
        // those trailing backslashes left in the buffer (if any) are going to precede a quote, double them
        StringUtil.repeatSymbol(sb, '\\', numTrailingBackslashes);
      }

      sb.append(s).append(Q);
    }
  }
private static void appendQuoted(StringBuilder sb, String s)