code: protected String addEscapes(final String str) {
          final StringBuilder sb = new StringBuilder();
          char ch;
          for (int i = 0; i < str.length(); i++) {
              ch = str.charAt(i);
              switch (ch) {
                  case 0 :
                      continue;
                  case '\b':
                      sb.append("\\b");
                      continue;
                  case '\t':
                      sb.append("\\t");
                      continue;
                  case '\n':
                      sb.append("\\n");
                      continue;
                  case '\f':
                      sb.append("\\f");
                      continue;
                  case '\r':
                      sb.append("\\r");
                      continue;
                  case '\"':
                      sb.append("\\\"");
                      continue;
                  case '\'':
                      sb.append("\\\'");
                      continue;
                  case '\\':
                      sb.append("\\\\");
                      continue;
                  default:
                      if (ch < 0x20 || ch > 0x7e) {
                          final String s = "0000" + Integer.toString(ch, 16);
                          sb.append("\\u" + s.substring(s.length() - 4, s.length()));
                      }
                      else {
                          sb.append(ch);
                      }
                      continue;
              }
          }
          return sb.toString();
      }
docs: Escapes some chars in the given string.
  @param str the input
  @return a new string with the escaped values