Example usage for java.util.regex Matcher hitEnd

List of usage examples for java.util.regex Matcher hitEnd

Introduction

In this page you can find the example usage for java.util.regex Matcher hitEnd.

Prototype

boolean hitEnd

To view the source code for java.util.regex Matcher hitEnd.

Click Source Link

Document

Boolean indicating whether or not more input could change the results of the last match.

Usage

From source file:org.dbpedia.spotlight.spot.OpenNLPUtil.java

protected static List<Integer> chars2remove(String orgText) {

    //See: http://en.wikipedia.org/wiki/Quotation_mark_glyphs
    char[] charArray = { '"', '\u002C', '\u00AB', '\u00BB', '\u2018', '\u2019', '\u201A', '\u201B', '\u201C',
            '\u201D', '\u201E', '\u201F', '\u2039', '\u203A' };
    String regexp = "[";
    for (Character ch : charArray) {
        regexp = regexp + ch;//w  w  w  .j a  v a2s . c om
    }
    regexp = regexp + "]";

    //System.out.println("\nregexp: " + regexp);
    List<Integer> remCharPosLst = new ArrayList<Integer>();

    Pattern p = Pattern.compile(regexp);
    Matcher m = p.matcher(orgText);

    while (!m.hitEnd()) {
        boolean mth = m.find();
        if (mth) {
            //System.out.println("Charater to remove: " + orgText.charAt(m.start()));
            remCharPosLst.add(m.start());
        }
    }
    return remCharPosLst;
}

From source file:org.openestate.io.core.CsvPrinter.java

/**
 * Helper function to replace line breaks in a string with a custom value
 * before printing.//from  ww w  .  j ava  2 s  . c  o m
 * <p>
 * This method may be used by inheriting classes, if the particular format
 * does not support line breaks.
 *
 * @param value
 * value to replace
 *
 * @param lineBreak
 * value, that is used for replacement of line breaks - if null, &lt;br/&gt;
 * is used
 *
 * @return
 * value with replaced line breaks
 */
protected static String replaceLineBreaks(String value, String lineBreak) {
    value = StringUtils.trimToNull(value);
    if (value == null)
        return null;
    if (lineBreak == null)
        lineBreak = "<br/>";
    Matcher m = LINES.matcher(value);
    StringBuilder out = new StringBuilder();
    while (m.find()) {
        out.append(StringUtils.trimToEmpty(m.group()));
        if (!m.hitEnd())
            out.append(lineBreak);
    }
    return out.toString();
}

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Substitutes any number of variable references in the given string, returning
 * the resultant string with all variable references replaced by the corresponding
 * variable values./*from ww w.j av  a2s  .com*/
 * 
 * @param textWithVars
 * @param variableContext
 * @return
 */
public static String substitute(String textWithVars, SPVariableHelper variableHelper) {

    logger.debug("Performing variable substitution on " + textWithVars);

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(textWithVars);

    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            Object variableValue;
            if (variableName.equals("$")) {
                variableValue = "$";
            } else {
                variableValue = variableHelper.resolve(variableName);
            }
            logger.debug("Found variable " + variableName + " = " + variableValue);
            text.append(textWithVars.substring(currentIndex, matcher.start()));
            text.append(variableValue);
            currentIndex = matcher.end();
        }
    }

    text.append(textWithVars.substring(currentIndex));

    return text.toString();
}

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Helper method that takes a connection and a SQL statement which includes variable and 
 * converts all that in a nifty prepared statement ready for execution, on time for Christmas.
 * @param connection A connection object to use in order to generate the prepared statement.
 * @param sql A SQL string which might include variables.
 * @param variableHelper A {@link SPVariableHelper} object to resolve the variables.
 * @return A {@link PreparedStatement} object ready for execution.
 * @throws SQLException Might get thrown if we cannot generate a {@link PreparedStatement} with the supplied connection.
 */// ww  w  .  jav a 2s. c  om
public static PreparedStatement substituteForDb(Connection connection, String sql,
        SPVariableHelper variableHelper) throws SQLException {

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(sql);
    List<Object> vars = new LinkedList<Object>();

    // First, change all vars to '?' markers.
    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            if (variableName.equals("$")) {
                vars.add("$");
            } else {
                vars.add(variableHelper.resolve(variableName));
            }
            text.append(sql.substring(currentIndex, matcher.start()));
            text.append("?");
            currentIndex = matcher.end();
        }
    }
    text.append(sql.substring(currentIndex));

    // Now generate a prepared statement and inject it's variables.
    PreparedStatement ps = connection.prepareStatement(text.toString());
    for (int i = 0; i < vars.size(); i++) {
        ps.setObject(i + 1, vars.get(i));
    }

    return ps;
}

From source file:ca.sqlpower.object.SPVariableHelper.java

/**
 * Helper method that takes a connection and a MDX statement which includes variable and 
 * converts all that in a nifty prepared statement ready for execution, on time for Christmas.
 * @param connection A connection object to use in order to generate the prepared statement.
 * @param sql A MDX string which might include variables.
 * @param variableHelper A {@link SPVariableHelper} object to resolve the variables.
 * @return A {@link PreparedStatement} object ready for execution.
 * @throws SQLException Might get thrown if we cannot generate a {@link PreparedStatement} with the supplied connection.
 *//*from  w ww.j a v a2  s  .c  om*/
public static PreparedOlapStatement substituteForDb(OlapConnection connection, String mdxQuery,
        SPVariableHelper variableHelper) throws SQLException {

    // Make sure that the registry is ready.
    SPResolverRegistry.init(variableHelper.getContextSource());

    StringBuilder text = new StringBuilder();
    Matcher matcher = varPattern.matcher(mdxQuery);
    List<Object> vars = new LinkedList<Object>();

    // First, change all vars to '?' markers.
    int currentIndex = 0;
    while (!matcher.hitEnd()) {
        if (matcher.find()) {
            String variableName = matcher.group(1);
            if (variableName.equals("$")) {
                vars.add("$");
            } else {
                vars.add(variableHelper.resolve(variableName));
            }
            text.append(mdxQuery.substring(currentIndex, matcher.start()));
            text.append("?");
            currentIndex = matcher.end();
        }
    }
    text.append(mdxQuery.substring(currentIndex));

    // Now generate a prepared statement and inject it's variables.
    PreparedOlapStatement ps = connection.prepareOlapStatement(text.toString());
    for (int i = 0; i < vars.size(); i++) {
        ps.setObject(i + 1, vars.get(i));
    }

    return ps;
}

From source file:org.xchain.framework.util.AttributesUtil.java

/**
 * Parses an attribute value template into fixed and dynamic parts.  This list will always start with a fixed part and
 * then include alternating dynamic and fixed parts.
 *///from ww w . j a v a  2s  .  com
public static List<String> parseAttributeValueTemplate(String attributeValueTemplate) throws SAXException {
    // the result.
    ArrayList<String> result = new ArrayList<String>();

    // create the matcher.
    Matcher matcher = attributeValueTemplatePattern.matcher(attributeValueTemplate);

    while (matcher.lookingAt()) {
        String fixedPart = matcher.group(1);
        String dynamicPart = matcher.group(2);

        if (result.isEmpty() && fixedPart == null) {
            result.add("");
        }

        if (fixedPart != null) {
            result.add(fixedPart.replaceAll("\\{\\{", "{").replaceAll("\\}\\}", "}"));
        }
        if (dynamicPart != null) {
            result.add(dynamicPart);
        }
        matcher.region(matcher.regionStart() + matcher.group().length(), matcher.regionEnd());
    }

    if (!matcher.hitEnd()) {
        throw new SAXException(
                "The attribute value template '" + attributeValueTemplate + "' has an error between characters "
                        + matcher.regionStart() + " and " + matcher.regionEnd() + ".");
    }

    return result;
}

From source file:com.meltmedia.cadmium.servlets.BasicFileServlet.java

public static List<String> parseETagList(String value) {
    List<String> etags = new ArrayList<String>();
    value = value.trim();/*from  w ww.ja v  a  2s .  co m*/
    if ("*".equals(value)) {
        etags.add(value);
    } else {
        Matcher etagMatcher = etagPattern.matcher(value);
        while (etagMatcher.lookingAt()) {
            etags.add(unescapePattern.matcher(etagMatcher.group(2)).replaceAll("$1"));
            etagMatcher.region(etagMatcher.start() + etagMatcher.group().length(), value.length());
        }
        if (!etagMatcher.hitEnd()) {
            etags.clear();
        }
    }
    return etags;
}

From source file:org.dice_research.topicmodeling.preprocessing.docsupplier.decorator.WikipediaMarkupDeletingDecorator.java

private static String cleanTagDeleteContent(final String beginPattern, final String endPattern,
        final String text, final String replacement) {

    String s = "(" + beginPattern + ")|(" + endPattern + ")";
    Pattern pat = Pattern.compile(s);
    Matcher matchRef = pat.matcher(text);

    String cleanText = "";
    String rep = (replacement == null) ? "" : replacement;

    int isRef = 0;
    int refBegin = 0;
    int refEnd = 0;

    while (matchRef.find()) {
        if (matchRef.group().matches(beginPattern)) {
            // System.out.println("found a " + beginPattern + "!!");
            if (isRef == 0) {
                refEnd = matchRef.start();
                cleanText += text.substring(refBegin, refEnd) + rep;
            }/*w  w  w .ja v a  2  s  . com*/
            isRef++;
        }
        if (matchRef.group().matches(endPattern)) {
            // System.out.println("found a " + endPattern + "!!");
            isRef--;
            if (isRef == 0) {
                refBegin = matchRef.end();
            }
        }
    }
    if (matchRef.hitEnd()) {
        cleanText += text.substring(refBegin, text.length());
    }
    return cleanText;
}

From source file:org.apache.zeppelin.kylin.KylinInterpreter.java

private String formatResult(String msg) {
    StringBuilder res = new StringBuilder("%table ");

    Matcher ml = KYLIN_TABLE_FORMAT_REGEX_LABEL.matcher(msg);
    while (!ml.hitEnd() && ml.find()) {
        res.append(ml.group(1) + " \t");
    }//from ww  w . j a  v a  2 s. c  om
    res.append(" \n");

    Matcher mr = KYLIN_TABLE_FORMAT_REGEX.matcher(msg);
    String table = null;
    while (!mr.hitEnd() && mr.find()) {
        table = mr.group(1);
    }

    String[] row = table.split("\"],\\[\"");
    for (int i = 0; i < row.length; i++) {
        String[] col = row[i].split("\",\"");
        for (int j = 0; j < col.length; j++) {
            res.append(col[j] + " \t");
        }
        res.append(" \n");
    }
    return res.toString();
}

From source file:org.lockss.daemon.PrunedCachedUrlSetSpec.java

boolean matches0(String url) {
    if (!super.matches(url)) {
        return false;
    }//w  ww . ja  va2s.c  o m
    if (includePat != null) {
        Matcher mat = includePat.matcher(url);
        return mat.lookingAt() || mat.hitEnd();
    }
    if (excludePat != null) {
        Matcher mat = excludePat.matcher(url);
        return !mat.lookingAt();
    }
    return true;
}