Java String Unquote unquote(String entityName)

Here you can find the source of unquote(String entityName)

Description

unquote

License

Open Source License

Declaration

private static String unquote(String entityName) 

Method Source Code

//package com.java2s;

public class Main {
    public static final char SINGLE_QUOTE = '\'';
    public static final char ESCAPE_CHAR = '\\';

    private static String unquote(String entityName) {
        if (entityName.length() < 2) {
            return entityName;
        }/* ww w .j  a  v a  2  s.c  om*/
        if (!(entityName.charAt(0) == SINGLE_QUOTE && entityName.charAt(entityName.length() - 1) == SINGLE_QUOTE)) {
            return entityName;
        }
        if (entityName.indexOf('\'') == -1) {
            return entityName.substring(1, entityName.length() - 1);
        } else {
            StringBuilder sb = new StringBuilder();
            for (int i = 1; i < entityName.length() - 1; i++) {
                char curChar = entityName.charAt(i);
                if (curChar != ESCAPE_CHAR) {
                    sb.append(curChar);
                } else {
                    if (i + 1 < entityName.length()) {
                        sb.append(entityName.charAt(i + 1));
                        i = i + 1;
                    } else {
                        sb.append(ESCAPE_CHAR);
                    }
                }
            }
            return sb.toString();
        }
    }
}

Related

  1. unquote(final String str)
  2. unquote(String _path)
  3. unquote(String argument)
  4. unquote(String argument)
  5. unquote(String aString)
  6. unquote(String in)
  7. unquote(String input, char quoteChar)
  8. unquote(String literal)
  9. unquote(String maybeQuoted)