< prev index next >

src/jdk.dev/share/classes/com/sun/tools/hat/internal/util/Misc.java

Print this page
rev 10947 : 8055723: Replace concat String to append in StringBuilder parameters


  80         }
  81         return result;
  82     }
  83 
  84     public static String encodeHtml(String str) {
  85         final int len = str.length();
  86         StringBuilder sb = new StringBuilder();
  87         for (int i = 0; i < len; i++) {
  88             char ch = str.charAt(i);
  89             if (ch == '<') {
  90                 sb.append("&lt;");
  91             } else if (ch == '>') {
  92                 sb.append("&gt;");
  93             } else if (ch == '"') {
  94                 sb.append("&quot;");
  95             } else if (ch == '\'') {
  96                 sb.append("'");
  97             } else if (ch == '&') {
  98                 sb.append("&amp;");
  99             } else if (ch < ' ') {
 100                 sb.append("&#" + Integer.toString(ch) + ";");
 101             } else {
 102                 int c = (ch & 0xFFFF);
 103                 if (c > 127) {
 104                     sb.append("&#" + Integer.toString(c) + ";");
 105                 } else {
 106                     sb.append(ch);
 107                 }
 108             }
 109         }
 110         return sb.toString();
 111     }
 112 }


  80         }
  81         return result;
  82     }
  83 
  84     public static String encodeHtml(String str) {
  85         final int len = str.length();
  86         StringBuilder sb = new StringBuilder();
  87         for (int i = 0; i < len; i++) {
  88             char ch = str.charAt(i);
  89             if (ch == '<') {
  90                 sb.append("&lt;");
  91             } else if (ch == '>') {
  92                 sb.append("&gt;");
  93             } else if (ch == '"') {
  94                 sb.append("&quot;");
  95             } else if (ch == '\'') {
  96                 sb.append("'");
  97             } else if (ch == '&') {
  98                 sb.append("&amp;");
  99             } else if (ch < ' ') {
 100                 sb.append("&#").append((int)ch).append(';');
 101             } else {
 102                 int c = (ch & 0xFFFF);
 103                 if (c > 127) {
 104                     sb.append("&#").append(c).append(';');
 105                 } else {
 106                     sb.append(ch);
 107                 }
 108             }
 109         }
 110         return sb.toString();
 111     }
 112 }
< prev index next >