All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.neotys.neoload.model.v3.util.RegExpUtils Maven / Gradle / Ivy

package com.neotys.neoload.model.v3.util;


/**
 * This class utility methods are copied from com.neotys.nl.util.RegExpUtils.
 * Should be refactored to use the same code at some point.
 */
public class RegExpUtils {

    // the states used for parsing
    private static final int CONTINUE = 1;
    private static final int ON_DOLLAR = 2;
    private static final int EDIT_VAR = 3;

    private static char[] reservedCars = new char[] { '.', '\\', '+', '*', '?', '(', ')', '{' , '}' ,'[', ']', '$', '^', '|' };

    private RegExpUtils() {}

    private static boolean isReservedCar(char c) {
        for (char reservedCar : reservedCars) {
            if (reservedCar == c) return true;
        }
        return false;
    }

    /**
     * Return the sentence escaped for regular expression
     * ie: .txt -> \.txt
     * @param sentence
     * @return
     */
    public static String escape(String sentence) {
        StringBuilder result = new StringBuilder(sentence.length()+2);
        for(int i=0;i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy