Example usage for org.apache.lucene.util.automaton Automata makeAnyChar

List of usage examples for org.apache.lucene.util.automaton Automata makeAnyChar

Introduction

In this page you can find the example usage for org.apache.lucene.util.automaton Automata makeAnyChar.

Prototype

public static Automaton makeAnyChar() 

Source Link

Document

Returns a new (deterministic) automaton that accepts any single codepoint.

Usage

From source file:org.elasticsearch.xpack.core.security.support.Automatons.java

License:Open Source License

/**
 * Builds and returns an automaton that represents the given pattern.
 *///w w  w.j a v  a 2 s  .c o m
@SuppressWarnings("fallthrough") // explicit fallthrough at end of switch
static Automaton wildcard(String text) {
    List<Automaton> automata = new ArrayList<>();
    for (int i = 0; i < text.length();) {
        final char c = text.charAt(i);
        int length = 1;
        switch (c) {
        case WILDCARD_STRING:
            automata.add(Automata.makeAnyString());
            break;
        case WILDCARD_CHAR:
            automata.add(Automata.makeAnyChar());
            break;
        case WILDCARD_ESCAPE:
            // add the next codepoint instead, if it exists
            if (i + length < text.length()) {
                final char nextChar = text.charAt(i + length);
                length += 1;
                automata.add(Automata.makeChar(nextChar));
                break;
            } // else fallthru, lenient parsing with a trailing \
        default:
            automata.add(Automata.makeChar(c));
        }
        i += length;
    }
    return concatenate(automata);
}