Here you can find the source of unescape(StringBuilder escapedText, int index)
Parameter | Description |
---|---|
escapedText | the working text |
index | the beginning index |
public static void unescape(StringBuilder escapedText, int index)
//package com.java2s; //License from project: Open Source License public class Main { /**// www .j av a 2 s .c o m * Table conversion between escaped/unescaped HTML symbols */ private static final String[][] HTML_ESCAPE_TABLE = { { "<", "<" }, { ">", ">" }, { "&", "&" }, { """, "\"" }, { "à", "\u00e0" }, { "À", "\u00c0" }, { "â", "\u00e2" }, { "ä", "\u00e4" }, { "Ä", "\u00c4" }, { "Â", "\u00c2" }, { "å", "\u00e5" }, { "Å", "\u00c5" }, { "æ", "\u00e6" }, { "Æ", "\u00c6" }, { "ç", "\u00e7" }, { "Ç", "\u00c7" }, { "é", "\u00e9" }, { "É", "\u00c9" }, { "è", "\u00e8" }, { "È", "\u00c8" }, { "ê", "\u00ea" }, { "Ê", "\u00ca" }, { "ë", "\u00eb" }, { "Ë", "\u00cb" }, { "ï", "\u00ef" }, { "Ï", "\u00cf" }, { "ô", "\u00f4" }, { "Ô", "\u00d4" }, { "ö", "\u00f6" }, { "Ö", "\u00d6" }, { "ø", "\u00f8" }, { "Ø", "\u00d8" }, { "ß", "\u00df" }, { "ù", "\u00f9" }, { "Ù", "\u00d9" }, { "û", "\u00fb" }, { "Û", "\u00db" }, { "ü", "\u00fc" }, { "Ü", "\u00dc" }, { " ", " " }, { "®", "\u00a9" }, { "©", "\u00ae" }, { "€", "\u20a0" } }; /** * Unescape html * * This method modify the {@link StringBuilder} in place. * * @param escapedText * the working text * @param index * the beginning index */ public static void unescape(StringBuilder escapedText, int index) { int start, end, table_index; start = escapedText.indexOf("&", index); if (start > -1) { end = escapedText.indexOf(";", start); // we don't start from the beginning // the next time, to handle the case of // the & index = start + 1; if (end > start) { String temp = escapedText.substring(start, end + 1); // search in HTML_ESCAPE_TABLE[][] if temp is there table_index = 0; while (table_index < HTML_ESCAPE_TABLE.length) { if (HTML_ESCAPE_TABLE[table_index][0].equals(temp)) { break; } else { table_index++; } } if (table_index < HTML_ESCAPE_TABLE.length) { escapedText.replace(start, end + 1, HTML_ESCAPE_TABLE[table_index][1]); unescape(escapedText, index); // recursive call } } } return; } }