Java String Unescape unescape(final String[] inval, final Character escapeChar)

Here you can find the source of unescape(final String[] inval, final Character escapeChar)

Description

Unescape an array of Strings.

License

Open Source License

Parameter

Parameter Description
inval the array of Strings to unescape
escapeChar the escape character

Return

the array of Strings, unescaped.

Declaration

public static String[] unescape(final String[] inval, final Character escapeChar) 

Method Source Code

//package com.java2s;
/*//from ww w .  ja v a2s .  com
 * Copyright (C) 2007-2009 Institute for Computational Biomedicine,
 *               Weill Medical College of Cornell University
 *
 *  This program 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.
 *
 *  This program 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 {
    /**
     * Unescape an array of Strings.
     * @param inval the array of Strings to unescape
     * @param escapeChar the escape character
     * @return the array of Strings, unescaped.
     */
    public static String[] unescape(final String[] inval, final Character escapeChar) {
        // if nothing was passed in, just pass back the same thing
        if (inval != null && escapeChar != null && inval.length != 0) {
            for (int i = 0; i < inval.length; i++) {
                inval[i] = unescape(inval[i], escapeChar);
            }
        }
        return inval;
    }

    /**
     * Unescape a String. Essentially, this just means that if the escape
     * character is in a String it will be removed. If the escape
     * character was '\', the string "ab\\cd\efg" would become
     * "ab\cdefg".
     * @param inval the array of strings to unescape
     * @param escapeChar the escape character
     * @return the string, unescaped
     */
    public static String unescape(final String inval, final Character escapeChar) {
        if (inval == null || escapeChar == null || inval.length() == 0) {
            // Nothing to do
            return inval;
        }

        final int length = inval.length();
        final StringBuilder curSplit = new StringBuilder();
        boolean inEscape = false;
        for (int i = 0; i < length; i++) {
            final char curChar = inval.charAt(i);
            if (!inEscape && curChar == escapeChar) {
                // Going into escape. Don't save the
                // current (escape) character.
                inEscape = true;
                continue;
            }
            if (inEscape) {
                inEscape = false;
            }
            curSplit.append(curChar);
        }

        return curSplit.toString();
    }
}

Related

  1. unescape(final String s)
  2. unescape(final String source)
  3. unescape(final String str, final char escapeChar)
  4. unescape(final String string, final char quoteChar)
  5. unescape(final String text)
  6. unescape(String aString)
  7. unescape(String aValue)
  8. unescape(String data)
  9. unescape(String elt)