Java String Unescape unescape(String value)

Here you can find the source of unescape(String value)

Description

Unescape string

License

Apache License

Parameter

Parameter Description
value a parameter

Declaration

public static String unescape(String value) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**//from   www  .jav a 2 s. co  m
     * Unescape string
     *
     * @param value
     * @return
     */
    public static String unescape(String value) {
        if (value == null || value.length() == 0) {
            return value;
        }

        StringBuffer buffer = new StringBuffer();

        int pos = 0, max = value.length();

        while (pos < max) {
            Character current = value.charAt(pos);

            if (current == '\\' && (pos + 1) < max) {
                switch (value.charAt(pos + 1)) {
                case '\"':
                    buffer.append('\"');
                    pos += 2;
                    break;
                case '\'':
                    buffer.append('\'');
                    pos += 2;
                    break;
                case '\\':
                    buffer.append('\\');
                    pos += 2;
                    break;
                case '\n':
                    buffer.append('\n');
                    pos += 2;
                    break;
                case '\t':
                    buffer.append('\t');
                    pos += 2;
                    break;
                default:
                    buffer.append(current);
                    pos++;
                    break;
                }
            } else {
                buffer.append(current);
                pos++;
            }
        }

        return buffer.toString();
    }
}

Related

  1. unEscape(String value)
  2. unescape(String value)
  3. unescape(String value)
  4. unescape(String value)
  5. unescape(String value)
  6. unescape(String x)
  7. unescape(StringBuilder escapedText, int index)
  8. unEscapeString(final String src)
  9. unescapeString(String escapedString)