code: public static String toStringToken(String pValue) {
          // See if any escaping is needed
          if (pValue.indexOf('\"') < 0 &&
                  pValue.indexOf('\\') < 0) {
              return "\"" + pValue + "\"";
          }
  
          // Escaping is needed
          else {
              StringBuffer buf = new StringBuffer();
              buf.append('\"');
              int len = pValue.length();
              for (int i = 0; i < len; i++) {
                  char ch = pValue.charAt(i);
                  if (ch == '\\') {
                      buf.append('\\');
                      buf.append('\\');
                  } else if (ch == '\"') {
                      buf.append('\\');
                      buf.append('\"');
                  } else {
                      buf.append(ch);
                  }
              }
              buf.append('\"');
              return buf.toString();
          }
      }
docs: Converts the specified value to a String token, using " as the
  enclosing quotes and escaping any characters that need escaping.