Here you can find the source of toHtml(String s)
Parameter | Description |
---|---|
s | the string to convert |
public static String toHtml(String s)
//package com.java2s; /*/*from ww w.j a v a 2s .c om*/ This file is part of Subsonic. Subsonic is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. Subsonic is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with Subsonic. If not, see <http://www.gnu.org/licenses/>. Copyright 2009 (C) Sindre Mehus */ public class Main { private static final String[][] HTML_SUBSTITUTIONS = { { "&", "&" }, { "<", "<" }, { ">", ">" }, { "'", "'" }, { "\"", """ }, }; /** * Returns the specified string converted to a format suitable for * HTML. All single-quote, double-quote, greater-than, less-than and * ampersand characters are replaces with their corresponding HTML * Character Entity code. * * @param s the string to convert * @return the converted string */ public static String toHtml(String s) { if (s == null) { return null; } for (String[] substitution : HTML_SUBSTITUTIONS) { if (s.contains(substitution[0])) { s = s.replaceAll(substitution[0], substitution[1]); } } return s; } }