Here you can find the source of unescapeString(String string, String escapeChars, char escapeSymbol)
Parameter | Description |
---|---|
string | the string to process. |
escapeChars | the characters that are to be unescaped. If null, all characters preceded by the escape symbol will be escaped. If empty, no escape characters are unescaped. |
escapeSymbol | the symbol that appears before escaped characters. |
public static String unescapeString(String string, String escapeChars, char escapeSymbol)
//package com.java2s; /*//from w w w . j a v a 2 s. c om * TextUtilities.java (Class: com.madphysicist.tools.util.TextUtilities) * * Mad Physicist JTools Project (General Purpose Utilities) * * The MIT License (MIT) * * Copyright (c) 2012 by Joseph Fox-Rabinovitz * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN * THE SOFTWARE. */ public class Main { /** * Removes occurrences of an escape character from a string. If a list of * escape characters is specified, only the characters in that list are * regarded as escape sequences when preceded by an escape symbol. * * @param string the string to process. * @param escapeChars the characters that are to be unescaped. If null, all * characters preceded by the escape symbol will be escaped. If empty, no * escape characters are unescaped. * @param escapeSymbol the symbol that appears before escaped characters. * @return the string with all escape sequences eliminated. * @since 1.0.0 */ public static String unescapeString(String string, String escapeChars, char escapeSymbol) { if (string == null || string.isEmpty() || (escapeChars != null && escapeChars.isEmpty())) { return string; } StringBuilder sb = new StringBuilder(string.length()); for (int i = 0; i < string.length(); i++) { char c = string.charAt(i); if (c == escapeSymbol && i < string.length() - 1) { char c2 = string.charAt(i + 1); if (escapeChars == null || escapeChars.indexOf(c2) >= 0) { c = c2; i++; } } sb.append(c); } string = sb.toString(); return sb.toString(); } }