Example usage for java.util.regex Matcher end

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

Introduction

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

Prototype

public int end() 

Source Link

Document

Returns the offset after the last character matched.

Usage

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

protected String substituteRuntimeWsdl(String wsdl) {
    StringBuffer substituted = new StringBuffer(wsdl.length());
    Matcher matcher = tokenPattern.matcher(wsdl);
    int index = 0;
    while (matcher.find()) {
        String match = matcher.group();
        substituted.append(wsdl.substring(index, matcher.start()));
        String propName = match.substring(2, match.length() - 1);
        String value = PropertyManager.getProperty(propName);
        if (value != null)
            substituted.append(value);/*from w  w w .  ja  va2s .  c om*/
        index = matcher.end();
    }
    substituted.append(wsdl.substring(index));
    return substituted.toString();
}

From source file:com.g3net.tool.StringUtils.java

public static int lastIndexOf(String srcStr, String regexp, boolean ignoreCase, TInteger endPos) {

    Pattern p = null;/*www.  ja  v  a  2 s. c  o m*/
    if (ignoreCase) {
        p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
    } else {
        p = Pattern.compile(regexp);
    }
    Matcher m = p.matcher(srcStr);
    int end = -1;
    while (m.find()) {
        // log.info(m.group()+":"+m.start()+":"+m.end());
        end = m.start();
        endPos.setValue(m.end());
    }
    return end;
    // sql3.regionMatches(ignoreCase, toffset, other, ooffset, len)
    // log.info(m.matches());
}

From source file:com.g3net.tool.StringUtils.java

public static int indexOf(String srcStr, String regexp, boolean ignoreCase, TInteger endPos) {

    Pattern p = null;/*from   w  w w.j av a2s  .c  om*/
    if (ignoreCase) {
        p = Pattern.compile(regexp, Pattern.CASE_INSENSITIVE);
    } else {
        p = Pattern.compile(regexp);
    }
    Matcher m = p.matcher(srcStr);
    int startPos = -1;
    while (m.find()) {
        // log.info(m.group()+":"+m.start()+":"+m.end());
        startPos = m.start();
        endPos.setValue(m.end());
        return startPos;

    }
    return -1;
    // sql3.regionMatches(ignoreCase, toffset, other, ooffset, len)
    // log.info(m.matches());
}

From source file:com.gargoylesoftware.htmlunit.CodeStyleTest.java

private int getIndentation(final String line) {
    final Matcher matcher = leadingWhitespace.matcher(line);
    if (matcher.find()) {
        return matcher.end() - matcher.start();
    }//from   w w  w.ja  va  2s  . c  o m
    return 0;
}

From source file:com.krawler.portal.tools.SourceFormatter.java

private static String _formatTaglibQuotes(String fileName, String content, String quoteType) {

    String quoteFix = StringPool.APOSTROPHE;

    if (quoteFix.equals(quoteType)) {
        quoteFix = StringPool.QUOTE;/*from   w ww .ja va2s.c om*/
    }

    Pattern pattern = Pattern.compile(_getTaglibRegex(quoteType));

    Matcher matcher = pattern.matcher(content);

    while (matcher.find()) {
        int x = content.indexOf(quoteType + "<%=", matcher.start());
        int y = content.indexOf("%>" + quoteType, x);

        while ((x != -1) && (y != -1)) {
            String result = content.substring(x + 1, y + 2);

            if (result.indexOf(quoteType) != -1) {
                int lineCount = 1;

                char contentCharArray[] = content.toCharArray();

                for (int i = 0; i < x; i++) {
                    if (contentCharArray[i] == CharPool.NEW_LINE) {
                        lineCount++;
                    }
                }

                if (result.indexOf(quoteFix) == -1) {
                    StringBuilder sb = new StringBuilder();

                    sb.append(content.substring(0, x));
                    sb.append(quoteFix);
                    sb.append(result);
                    sb.append(quoteFix);
                    sb.append(content.substring(y + 3, content.length()));

                    content = sb.toString();
                } else {
                    logger.debug("taglib: " + fileName + " " + lineCount);
                }
            }

            x = content.indexOf(quoteType + "<%=", y);

            if (x > matcher.end()) {
                break;
            }

            y = content.indexOf("%>" + quoteType, x);
        }
    }

    return content;
}

From source file:com.gargoylesoftware.htmlunit.javascript.regexp.HtmlUnitRegExpProxy.java

private String doReplacement(final String originalString, final String replacement, final Matcher matcher,
        final boolean replaceAll) {

    final StringBuilder sb = new StringBuilder();
    int previousIndex = 0;
    while (matcher.find()) {
        sb.append(originalString, previousIndex, matcher.start());
        String localReplacement = replacement;
        if (replacement.contains("$")) {
            localReplacement = computeReplacementValue(replacement, originalString, matcher);
        }//from  w  w w  .  j a  va 2  s  .  co  m
        sb.append(localReplacement);
        previousIndex = matcher.end();

        setProperties(matcher, originalString, matcher.start(), previousIndex);
        if (!replaceAll) {
            break;
        }
    }
    sb.append(originalString, previousIndex, originalString.length());
    return sb.toString();
}

From source file:org.shredzone.commons.view.manager.ViewPattern.java

/**
 * Compiles a view pattern. Generates a parameter list, a list of expressions for
 * building URLs to this view, and a regular expression for matching URLs against this
 * view pattern./* w  ww.  j a  v  a2 s .  co m*/
 *
 * @param pstr
 *            the view pattern
 * @param pattern
 *            {@link StringBuilder} to assemble the regular expression in
 * @param expList
 *            List of {@link Expression} to assemble expressions in
 * @param paramList
 *            List to assemble parameters in
 */
private void compilePattern(String pstr, StringBuilder pattern, List<Expression> expList,
        List<String> paramList) {
    ExpressionParser parser = new SpelExpressionParser();
    int previous = 0;

    Matcher m = PATH_PART.matcher(pstr);
    while (m.find()) {
        String fixedPart = pstr.substring(previous, m.start());
        if (fixedPart.indexOf('\'') >= 0) {
            throw new IllegalArgumentException("path parameters must not contain \"'\"");
        }

        String expressionPart = m.group(1);

        pattern.append(Pattern.quote(fixedPart));
        pattern.append("([^/]*)");

        paramList.add(expressionPart);

        expList.add(parser.parseExpression('\'' + fixedPart + '\''));
        expList.add(parser.parseExpression(expressionPart));

        previous = m.end();
    }

    String postPart = pstr.substring(previous);
    pattern.append(Pattern.quote(postPart));
    expList.add(parser.parseExpression('\'' + postPart + '\''));
}

From source file:de.huberlin.wbi.hiway.am.galaxy.GalaxyTaskInstance.java

/**
 * A (recursive) method that is passed a file along with the JSON object in this task instance's tool state that corresponds to this file. This method is
 * used to populate the tool state with information on the file.
 * /*from  ww w .  j a  v a 2  s .  c  o  m*/
 * @param name
 *            the parameter name for this file, as specified in the workflow description
 * @param computeMetadata
 *            a parameter that determines whether metadata is to be computed for this file, which will only be the case for input data
 * @param data
 *            the Hi-WAY data object for this file
 * @param jo
 *            the JSON object in the tool state that corresponds to this file parameter
 */
private void addFile(String name, boolean computeMetadata, GalaxyData data, JSONObject jo) {
    try {
        Pattern p = Pattern.compile("(_[0-9]*)?\\|");
        Matcher m = p.matcher(name);

        // (1) if the to-be-added file is part of a repeat (and thus can be identified by an underscore and index number in its name), compute its prefix
        // (the repeat name) as well as its suffix (the actual parameter name) and index; use the prefix and index to obtain its JSON object from the tool
        // state and (recursively) call this method to proceed to (2)
        if (m.find()) {
            String prefix = name.substring(0, m.start());
            String suffix = name.substring(m.end());
            if (m.end() - m.start() > 2) {
                int index = Integer.parseInt(name.substring(m.start() + 1, m.end() - 1));
                JSONArray repeatJa = jo.getJSONArray(prefix);
                for (int i = 0; i < repeatJa.length(); i++) {
                    JSONObject repeatJo = repeatJa.getJSONObject(i);
                    if (repeatJo.getInt("__index__") == index) {
                        addFile(suffix, computeMetadata, data, repeatJo);
                        break;
                    }
                }
            } else {
                addFile(suffix, computeMetadata, data, jo.getJSONObject(prefix));
            }
            // (2) fix both the template of this tool and the tool state of the task instance calling this method, such that they are in compliance with one
            // another when the tool state is used to set the parameters of the task instance at execution time
        } else {
            // (a) add several properties for this parameter to the tool state
            String fileName = data.getName();
            JSONObject fileJo = new JSONObject();
            fileJo.putOpt("path", fileName);
            fileJo.putOpt("name", fileName.split("\\.(?=[^\\.]+$)")[0]);
            Path dir = data.getLocalDirectory();
            String dirString = (dir == null) ? "" : dir.toString();
            if (dirString.length() == 0) {
                dirString = ".";
            }
            fileJo.putOpt("files_path", dirString);
            if (data.hasDataType()) {
                GalaxyDataType dataType = data.getDataType();
                String fileExt = dataType.getExtension();
                fileJo.putOpt("extension", fileExt);
                fileJo.putOpt("ext", fileExt);
            }
            // note that this metadata is an empty dictionary that will only be be filled for input data of the task instance calling this method; this is
            // done by executing a python script designed to populate the tool state with metadata prior to execution
            if (data.hasDataType())
                fileJo.putOpt("metadata", new JSONObject());
            jo.putOpt(name, fileJo);

            // (b) adjust the Python script for setting parameters at runtime to compute metadata for this file, given the computeMetadata parameter is set
            if (computeMetadata && data.hasDataType()) {
                GalaxyDataType dataType = data.getDataType();
                paramScript.append("from ");
                paramScript.append(dataType.getFile());
                paramScript.append(" import ");
                paramScript.append(dataType.getName());
                paramScript.append("\n");
                inputs.add(data);
            }
        }
    } catch (JSONException e) {
        e.printStackTrace();
        System.exit(-1);
    }
}

From source file:mitm.djigzo.web.render.impl.AbstractInlineAddClassPattern.java

private void applyPattern(StrBuilder builder) {
    Pattern pattern = getPattern();

    if (pattern != null) {
        Matcher matcher = pattern.matcher(builder.toString());

        StrBuilder copy = null;/*from  w  w w. ja  va  2s .  co  m*/

        /*
         * Because we will modify the StrBuilder (replacing matches etc.) we need
         * to keep track of changes with respect to indexes. If there is a match
         * we will create a copy of the line and do the replacing on that line. We
         * however need to correct the indexes because we are adding or removing 
         * characters to the copy.  
         */
        int indexCorrection = 0;

        while (matcher.find()) {
            if (copy == null) {
                copy = new StrBuilder(builder.toString());
            }

            String replaceWith = "<span class=\"" + className + "\">" + matcher.group() + "</span>";

            copy.replace(matcher.start() + indexCorrection, matcher.end() + indexCorrection, replaceWith);

            indexCorrection = indexCorrection + replaceWith.length() - matcher.group().length();
        }

        if (copy != null) {
            /*
             * Content has changed so replace it
             */
            builder.clear();
            builder.append(copy.toString());
        }
    }
}

From source file:com.mawujun.utils.string.StringUtils.java

/**
 *  ?//from  w  w  w.j  av a2  s  .  c om
 * @author mawujun email:160649888@163.com qq:16064988
 * @param param
 * @return
 */
public static String underlineToCamel2(String param) {
    if (param == null || "".equals(param.trim())) {
        return "";
    }
    StringBuilder sb = new StringBuilder(param);
    Matcher mc = Pattern.compile("_").matcher(param);
    int i = 0;
    while (mc.find()) {
        int position = mc.end() - (i++);
        // String.valueOf(Character.toUpperCase(sb.charAt(position)));
        sb.replace(position - 1, position + 1, sb.substring(position, position + 1).toUpperCase());
    }
    return sb.toString();
}