Here you can find the source of unescape(String text)
Parameter | Description |
---|---|
text | The String to escape. If the String is null, then we return null. |
static String unescape(String text)
//package com.java2s; /*/*from w ww. jav a2 s . c om*/ * Copyright (c) 2008, SQL Power Group Inc. * * This file is part of SQL Power Library. * * SQL Power Library 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. * * SQL Power Library 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 this program. If not, see <http://www.gnu.org/licenses/>. */ public class Main { /** * Unescapes the String text according to the format described above in escape(String text) * * @param text The String to escape. If the String is null, then we return null. * @return The unescaped version of the input string. If the string is null, return null */ static String unescape(String text) { if (text == null) return null; StringBuilder unescapedText = new StringBuilder(text.length()); for (int i = 0, n = text.length(); i < n;) { char ch = text.charAt(i); char nextch; if (i == n - 1) { nextch = 0; } else { nextch = text.charAt(i + 1); } if (ch == '\\' && nextch == 'u') { int charVal = Integer.parseInt(text.substring(i + 2, i + 6), 16); char unescapedChar = (char) charVal; unescapedText.append(unescapedChar); i += 6; } else { unescapedText.append(ch); i++; } } return unescapedText.toString(); } }