2 * This file is part of NeverNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\r
8 * Software distributed under the License is distributed
\r
9 * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
\r
10 * express or implied. See the GPL for the specific language
\r
11 * governing rights and limitations.
\r
13 * You should have received a copy of the GPL along with this
\r
14 * program. If not, go to http://www.gnu.org/licenses/gpl.html
\r
15 * or write to the Free Software Foundation, Inc.,
\r
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
\r
20 package cx.fbn.nevernote.utilities;
\r
22 import java.util.HashMap;
\r
24 public class StringUtils {
\r
26 private StringUtils() {}
\r
28 private static HashMap<String,String> htmlEntities;
\r
30 htmlEntities = new HashMap<String,String>();
\r
31 htmlEntities.put("<","<") ; htmlEntities.put(">",">");
\r
32 htmlEntities.put("&","&") ; htmlEntities.put(""","\"");
\r
33 htmlEntities.put("à","à"); htmlEntities.put("à","À");
\r
34 htmlEntities.put("â","â") ; htmlEntities.put("ä","ä");
\r
35 htmlEntities.put("ä","Ä") ; htmlEntities.put("â","Â");
\r
36 htmlEntities.put("å","å") ; htmlEntities.put("å","Å");
\r
37 htmlEntities.put("æ","æ") ; htmlEntities.put("&aElig;","Æ" );
\r
38 htmlEntities.put("ç","ç"); htmlEntities.put("ç","Ç");
\r
39 htmlEntities.put("é","é"); htmlEntities.put("é","É" );
\r
40 htmlEntities.put("è","è"); htmlEntities.put("è","È");
\r
41 htmlEntities.put("ê","ê") ; htmlEntities.put("ê","Ê");
\r
42 htmlEntities.put("ë","ë") ; htmlEntities.put("ë","Ë");
\r
43 htmlEntities.put("ï","ï") ; htmlEntities.put("ï","Ï");
\r
44 htmlEntities.put("ô","ô") ; htmlEntities.put("ô","Ô");
\r
45 htmlEntities.put("ö","ö") ; htmlEntities.put("ö","Ö");
\r
46 htmlEntities.put("ø","ø") ; htmlEntities.put("ø","Ø");
\r
47 htmlEntities.put("ß","ß") ; htmlEntities.put("ù","ù");
\r
48 htmlEntities.put("ù","Ù"); htmlEntities.put("û","û");
\r
49 htmlEntities.put("û","Û") ; htmlEntities.put("ü","ü");
\r
50 htmlEntities.put("ü","Ü") ; htmlEntities.put(" "," ");
\r
51 htmlEntities.put("©","\u00a9"); htmlEntities.put("'", "'");
\r
52 htmlEntities.put("®","\u00ae"); htmlEntities.put("¡", "\u00a1");
\r
53 htmlEntities.put("€","\u20a0"); htmlEntities.put("¢", "\u00a2");
\r
54 htmlEntities.put("£", "\u00a3"); htmlEntities.put("&curen;", "\u00a4");
\r
55 htmlEntities.put("¥", "\u00a5"); htmlEntities.put("¦", "\u00a6");
\r
56 htmlEntities.put("§", "\u00a7"); htmlEntities.put("¨", "\u00a8");
\r
57 htmlEntities.put("©", "\u00a9"); htmlEntities.put("ª", "\u00aa");
\r
58 htmlEntities.put("&laqo;", "\u00ab"); htmlEntities.put("¬", "\u00ac");
\r
59 htmlEntities.put("®", "\u00ae"); htmlEntities.put("¯", "\u00af");
\r
64 public static final String unescapeHTML(String source, int start){
\r
67 i = source.indexOf("&", start);
\r
69 j = source.indexOf(";" ,i);
\r
71 String entityToLookFor = source.substring(i , j + 1);
\r
72 String value = htmlEntities.get(entityToLookFor);
\r
73 if (value != null) {
\r
75 source = new StringBuffer().append(source.substring(0 , i).toLowerCase())
\r
77 .append(source.substring(j + 1))
\r
79 i = source.indexOf("&", i+1);
\r
87 public static final String unescapeHTML2(String source, int start){
\r
90 i = source.indexOf("&", start);
\r
92 j = source.indexOf(";" ,i);
\r
94 String entityToLookFor = source.substring(i , j + 1);
\r
95 String value = htmlEntities.get(entityToLookFor);
\r
96 if (value != null) {
\r
98 source = new StringBuffer().append(source.substring(0 , i).toLowerCase())
\r
100 .append(source.substring(j + 1))
\r
102 return unescapeHTML(source, i + 1); // recursive call
\r