docs: private static String quote(String text, char quoteChar) {
      if (text == null || text.isEmpty()) return emptyQuoted(quoteChar);
  
      int nbMatch = 0;
      int start = -1;
      do {
        start = text.indexOf(quoteChar, start + 1);
        if (start != -1) ++nbMatch;
      } while (start != -1);
  
      // no quotes found that need to be escaped, simply surround in quotes and return.
      if (nbMatch == 0) return quoteChar + text + quoteChar;
  
      // 2 for beginning and end quotes.
      // length for original text
      // nbMatch for escape characters to add to quotes to be escaped.
      int newLength = 2 + text.length() + nbMatch;
      char[] result = new char[newLength];
      result[0] = quoteChar;
      result[newLength - 1] = quoteChar;
      int newIdx = 1;
      for (int i = 0; i < text.length(); i++) {
        char c = text.charAt(i);
        if (c == quoteChar) {
          // escape quote with another occurrence.
          result[newIdx++] = c;
          result[newIdx++] = c;
        } else {
          result[newIdx++] = c;
        }
      }
      return new String(result);
    }