Here you can find the source of unescape(String str)
Parameter | Description |
---|---|
str | The source string. |
public static String unescape(String str)
//package com.java2s; // are made available under the terms of the Eclipse Public License v1.0 public class Main { /**// w ww . j av a 2s .c om * XML Escape characters. */ public final static String XML_AMP = "&"; public final static String XML_APOS = "'"; public final static String XML_CR = " "; public final static String XML_GT = ">"; public final static String XML_LT = "<"; public final static String XML_LF = " "; public final static String XML_QUOT = """; /** * Unescapes the given XML string. * * @param str * The source string. * @return The escaped string. */ public static String unescape(String str) { if (str == null || str.length() == 0) return ""; //$NON-NLS-1$ StringBuffer sb = new StringBuffer(); int len = str.length(); for (int i = 0; i < len; i++) { char ch = str.charAt(i); switch (ch) { case '&': if (str.startsWith(XML_LT, i)) { sb.append('<'); i += 3; } else if (str.startsWith(XML_GT, i)) { sb.append('>'); i += 3; } else if (str.startsWith(XML_AMP, i)) { sb.append('&'); i += 4; } else if (str.startsWith(XML_QUOT, i)) { sb.append('"'); i += 5; } else if (str.startsWith(XML_APOS, i)) { sb.append("\'"); //$NON-NLS-1$ i += 5; } else if (str.startsWith(XML_CR, i)) { sb.append('\r'); i += 4; } else if (str.startsWith(XML_LF, i)) { sb.append('\n'); i += 4; } else { sb.append(ch); } break; default: sb.append(ch); break; } } return sb.toString(); } }