Hi everybody,

I need to escape utf-8 to their html format.

I use the function below and the gwt compiler to JS doesn't like it:
it says "duplicate case" for all cases starting with and after the
à

a) Can somebody tell me what I am doing wrong ?

b) Is there any better way (using official GWT code) to do it ?

thanks
didier

public static final String escapeHTML(String s){
                   StringBuffer sb = new StringBuffer();
                   int n = s.length();
                   for (int i = 0; i < n; i++) {
                      char c = s.charAt(i);
                      switch (c) {
                         case '<':
                                 sb.append("&lt;");
                                 break;
                         case '>':
                                 sb.append("&gt;");
                                 break;
                         case '&':
                                 sb.append("&amp;");
                                 break;
                         case '"':
                                 sb.append("&quot;");
                                 break;
                         case 'à':
                                 sb.append("&agrave;");
                                 break;
                         case 'À':
                                 sb.append("&Agrave;");
                                 break;
                         case 'â':
                                 sb.append("&acirc;");
                                 break;
                         case 'Â':
                                 sb.append("&Acirc;");
                                 break;
                         case 'ä':
                                 sb.append("&auml;");
                                 break;
                         case 'Ä':
                                 sb.append("&Auml;");
                                 break;
                         case 'å':
                                 sb.append("&aring;");
                                 break;
                         case 'Å':
                                 sb.append("&Aring;");
                                 break;
                         case 'æ':
                                 sb.append("&aelig;");
                                 break;
                         case 'Æ':
                                 sb.append("&AElig;");
                                 break;
                         case 'ç':
                                 sb.append("&ccedil;");
                                 break;
                         case 'Ç':
                                 sb.append("&Ccedil;");
                                 break;
                         case 'é':
                                 sb.append("&eacute;");
                                 break;
                         case 'É':
                                 sb.append("&Eacute;");
                                 break;
                         case 'è':
                                 sb.append("&egrave;");
                                 break;
                         case 'È':
                                 sb.append("&Egrave;");
                                 break;
                         case 'ê':
                                 sb.append("&ecirc;");
                                 break;
                         case 'Ê':
                                 sb.append("&Ecirc;");
                                 break;
                         case 'ë':
                                 sb.append("&euml;");
                                 break;
                         case 'Ë':
                                 sb.append("&Euml;");
                                 break;
                         case 'ï':
                                 sb.append("&iuml;");
                                 break;
                         case 'Ï':
                                 sb.append("&Iuml;");
                                 break;
                         case 'ô':
                                 sb.append("&ocirc;");
                                 break;
                         case 'Ô':
                                 sb.append("&Ocirc;");
                                 break;
                         case 'ö':
                                 sb.append("&ouml;");
                                 break;
                         case 'Ö':
                                 sb.append("&Ouml;");
                                 break;
                         case 'ø':
                                 sb.append("&oslash;");
                                 break;
                         case 'Ø':
                                 sb.append("&Oslash;");
                                 break;
                         case 'ß':
                                 sb.append("&szlig;");
                                 break;
                         case 'ù':
                                 sb.append("&ugrave;");
                                 break;
                         case 'Ù':
                                 sb.append("&Ugrave;");
                                 break;
                         case 'û':
                                 sb.append("&ucirc;");
                                 break;
                         case 'Û':
                                 sb.append("&Ucirc;");
                                 break;
                         case 'ü':
                                 sb.append("&uuml;");
                                 break;
                         case 'Ü':
                                 sb.append("&Uuml;");
                                 break;
                         case '®':
                                 sb.append("&reg;");
                                 break;
                         case '©':
                                 sb.append("&copy;");
                                 break;
                         case '€':
                                 sb.append("&euro;");
                                 break;
                         case ' ':
                                 sb.append("&nbsp;");
                                 break;
                         default:
                                 sb.append(c);
                                 break;
                      }
                   }
                   return sb.toString();
        }

-- 
You received this message because you are subscribed to the Google Groups 
"Google Web Toolkit" group.
To post to this group, send email to google-web-tool...@googlegroups.com.
To unsubscribe from this group, send email to 
google-web-toolkit+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/google-web-toolkit?hl=en.

Reply via email to