public static String entityTo (String raw, String[] tc) {
      StringBuffer sb = new StringBuffer ();
      boolean entity = false;
      raw = raw.replace ('+', ' ');
      String tokens = tc == charsHtml ? "%<>" : "%";
      for (StringTokenizer st = new StringTokenizer (raw, tokens, true); st.hasMoreTokens (); ) {
         String token = st.nextToken ();
         if (entity) {
            boolean replaced = false;
            for (int i = 0; i < entities.length; i++) {
               if (token.startsWith (entities[i])) {
                  sb.append (tc[i]);
                  sb.append (token.substring (2));
                  replaced = true;
                  break;
               }
            }
            if (!replaced)
               sb.append (token);

            entity = false;
         } else if (token.equals ("%")) {
            entity = true;
            continue;
         } else if (token.equals ("<")) {
             sb.append ("&lt;");
         } else if (token.equals (">")) {
             sb.append ("&gt;");
         } else {
            sb.append (token);
         }
      }
      return (sb.toString ());
   }