code: private static String quote(final String s) {
      final String escQ = "\\Q";
      final String escE = "\\E";
  
      int slashEIndex = s.indexOf(escE);
      if (slashEIndex == -1) {
        return escQ + s + escE;
      }
  
      final StringBuffer sb = new StringBuffer(s.length() * 2);
      sb.append(escQ);
      slashEIndex = 0;
      int current = 0;
      while ((slashEIndex = s.indexOf(escE, current)) != -1) {
        sb.append(s.substring(current, slashEIndex));
        current = slashEIndex + 2;
        sb.append(escE);
        sb.append("\\");
        sb.append(escE);
        sb.append(escQ);
      }
      sb.append(s.substring(current, s.length()));
      sb.append(escE);
      return sb.toString();
    }
docs: /* for jdk 1.4