Here you can find the source of unescape(String str)
Parameter | Description |
---|---|
str | escaped string |
public static String unescape(String str)
//package com.java2s; /*//from www .j a v a 2 s. c o m * Copyright 2015 Nuke Sparrow <nukesparrow@bitmessage.ch>. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ public class Main { /** * Unescapes string, that can be used in .ini file * @param str escaped string * @return Unescaped value */ public static String unescape(String str) { StringBuilder b = new StringBuilder(str.length()); int i = 0; int l = str.length(); while (l > 0) { char c = str.charAt(i); if (c == '+') { b.append(' '); i++; l--; } else { if (l >= 3 && c == '%') { try { b.append((char) Short.parseShort(str.substring(i + 1, i + 3), 16)); i += 3; l -= 3; } catch (NumberFormatException ex) { b.append(c); i++; l--; } } else { b.append(c); i++; l--; } } } b.trimToSize(); return b.toString(); } }