-/*\r
- * This file is part of NeverNote \r
- * Copyright 2009 Randy Baumgarte\r
- * \r
- * This file may be licensed under the terms of of the\r
- * GNU General Public License Version 2 (the ``GPL'').\r
- *\r
- * Software distributed under the License is distributed\r
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
- * express or implied. See the GPL for the specific language\r
- * governing rights and limitations.\r
- *\r
- * You should have received a copy of the GPL along with this\r
- * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
- * or write to the Free Software Foundation, Inc.,\r
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
- *\r
-*/\r
-\r
-package cx.fbn.nevernote.utilities;\r
-\r
-import java.util.HashMap;\r
-\r
-public class StringUtils {\r
-\r
- private StringUtils() {}\r
- \r
- private static HashMap<String,String> htmlEntities;\r
- static {\r
- htmlEntities = new HashMap<String,String>();\r
- htmlEntities.put("<","<") ; htmlEntities.put(">",">");\r
- htmlEntities.put("&","&") ; htmlEntities.put(""","\"");\r
- htmlEntities.put("à","à"); htmlEntities.put("à","À");\r
- htmlEntities.put("â","â") ; htmlEntities.put("ä","ä");\r
- htmlEntities.put("ä","Ä") ; htmlEntities.put("â","Â");\r
- htmlEntities.put("å","å") ; htmlEntities.put("å","Å");\r
- htmlEntities.put("æ","æ") ; htmlEntities.put("&aElig;","Æ" );\r
- htmlEntities.put("ç","ç"); htmlEntities.put("ç","Ç");\r
- htmlEntities.put("é","é"); htmlEntities.put("é","É" );\r
- htmlEntities.put("è","è"); htmlEntities.put("è","È");\r
- htmlEntities.put("ê","ê") ; htmlEntities.put("ê","Ê");\r
- htmlEntities.put("ë","ë") ; htmlEntities.put("ë","Ë");\r
- htmlEntities.put("ï","ï") ; htmlEntities.put("ï","Ï");\r
- htmlEntities.put("ô","ô") ; htmlEntities.put("ô","Ô");\r
- htmlEntities.put("ö","ö") ; htmlEntities.put("ö","Ö");\r
- htmlEntities.put("ø","ø") ; htmlEntities.put("ø","Ø");\r
- htmlEntities.put("ß","ß") ; htmlEntities.put("ù","ù");\r
- htmlEntities.put("ù","Ù"); htmlEntities.put("û","û");\r
- htmlEntities.put("û","Û") ; htmlEntities.put("ü","ü");\r
- htmlEntities.put("ü","Ü") ; htmlEntities.put(" "," ");\r
- htmlEntities.put("©","\u00a9"); htmlEntities.put("'", "'");\r
- htmlEntities.put("®","\u00ae"); htmlEntities.put("¡", "\u00a1");\r
- htmlEntities.put("€","\u20a0"); htmlEntities.put("¢", "\u00a2");\r
- htmlEntities.put("£", "\u00a3"); htmlEntities.put("&curen;", "\u00a4");\r
- htmlEntities.put("¥", "\u00a5"); htmlEntities.put("¦", "\u00a6");\r
- htmlEntities.put("§", "\u00a7"); htmlEntities.put("¨", "\u00a8");\r
- htmlEntities.put("©", "\u00a9"); htmlEntities.put("ª", "\u00aa");\r
- htmlEntities.put("&laqo;", "\u00ab"); htmlEntities.put("¬", "\u00ac");\r
- htmlEntities.put("®", "\u00ae"); htmlEntities.put("¯", "\u00af");\r
- }\r
-\r
-\r
- \r
- public static final String unescapeHTML(String source, int start){\r
- int i,j;\r
-\r
- i = source.indexOf("&", start);\r
- while (i>-1) {\r
- j = source.indexOf(";" ,i);\r
- if (j > i) {\r
- String entityToLookFor = source.substring(i , j + 1);\r
- String value = htmlEntities.get(entityToLookFor);\r
- if (value != null) {\r
- value = " ";\r
- source = new StringBuffer().append(source.substring(0 , i).toLowerCase())\r
- .append(value)\r
- .append(source.substring(j + 1))\r
- .toString();\r
- i = source.indexOf("&", i+1);\r
- }\r
- }\r
- }\r
- return source;\r
- }\r
-\r
- \r
- public static final String unescapeHTML2(String source, int start){\r
- int i,j;\r
-\r
- i = source.indexOf("&", start);\r
- if (i > -1) {\r
- j = source.indexOf(";" ,i);\r
- if (j > i) {\r
- String entityToLookFor = source.substring(i , j + 1);\r
- String value = htmlEntities.get(entityToLookFor);\r
- if (value != null) {\r
- value = " ";\r
- source = new StringBuffer().append(source.substring(0 , i).toLowerCase())\r
- .append(value)\r
- .append(source.substring(j + 1))\r
- .toString();\r
- return unescapeHTML(source, i + 1); // recursive call\r
- }\r
- }\r
- }\r
- return source;\r
- }\r
-}\r