Here you can find the source of htmlEscape(String nonHTMLsrc)
Parameter | Description |
---|---|
nonHTMLsrc | String containing the text to make HTML-safe |
public static final String htmlEscape(String nonHTMLsrc)
//package com.java2s; //License from project: Apache License public class Main { private static String entityMap; private static String[] quickEntities; /**/*from w w w. j ava2s . c om*/ * This method will take the input and escape characters that have * an HTML entity representation. * It uses a quick string -> array mapping to avoid creating thousands of * temporary objects. * @param nonHTMLsrc String containing the text to make HTML-safe * @return String containing new copy of string with ENTITIES escaped */ public static final String htmlEscape(String nonHTMLsrc) { if (nonHTMLsrc == null) return null; StringBuffer res = new StringBuffer(); int l = nonHTMLsrc.length(); int idx; char c; for (int i = 0; i < l; i++) { c = nonHTMLsrc.charAt(i); idx = entityMap.indexOf(c); if (idx == -1) { res.append(c); } else { res.append(quickEntities[idx]); } } return res.toString(); } }