Java Wildcard wildcardSqlToUser(String exp)

Here you can find the source of wildcardSqlToUser(String exp)

Description

Convert an SQL LIKE/NOT LIKE expression to a * wildcard expression.

License

GNU General Public License

Parameter

Parameter Description
exp the wildcard expression

Return

the SQL LIKE parameter

Declaration

@Deprecated
public static String wildcardSqlToUser(String exp) 

Method Source Code

//package com.java2s;
/*/*from   www  .  j a v  a  2s.c  om*/
 * Copyright (C) 2002-2017 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

public class Main {
    /**
     * Convert an SQL LIKE/NOT LIKE expression to a * wildcard expression. See
     * wildcardUserToSql method for more information.
     * @param exp  the wildcard expression
     * @return     the SQL LIKE parameter
     * @deprecated I don't think this is used anymore?
     */
    @Deprecated
    public static String wildcardSqlToUser(String exp) {
        StringBuffer sb = new StringBuffer();

        // Java needs backslashes to be backslashed in strings.
        for (int i = 0; i < exp.length(); i++) {
            String substring = exp.substring(i);
            if (substring.startsWith("%")) {
                sb.append("*");
            } else {
                if (substring.startsWith("_")) {
                    sb.append("?");
                } else {
                    if (substring.startsWith("\\%")) {
                        sb.append("%");
                        i++;
                    } else {
                        if (substring.startsWith("\\_")) {
                            sb.append("_");
                            i++;
                        } else {
                            if (substring.startsWith("*")) {
                                sb.append("\\*");
                            } else {
                                if (substring.startsWith("?")) {
                                    sb.append("\\?");
                                } else {
                                    // a single '\' as in Dpse\GA10108
                                    if (substring.startsWith("\\\\")) {
                                        i++;
                                        sb.append("\\");
                                    } else {
                                        sb.append(substring.charAt(0));
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }

        return sb.toString();
    }
}

Related

  1. wildcardCompare(String s, String z)
  2. wildcardCriterionSQL(final String query)
  3. wildcardIfEmpty(String inString)
  4. wildcardOrIsNullIfEmpty(String column, String inString)
  5. wildcardSearchToRegex(final String wildcard)
  6. wildCardsToX(String s)
  7. wildcardToCaseInsensitiveRegex(final String pattern)
  8. wildcardUserToSql(String exp)