Example usage for java.util.regex Matcher regionEnd

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

Introduction

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

Prototype

public int regionEnd() 

Source Link

Document

Reports the end index (exclusive) of this matcher's region.

Usage

From source file:com.application.utils.FastDateParser.java

/**
 * Initialize derived fields from defining fields.
 * This is called from constructor and from readObject (de-serialization)
 *
 * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser
 *//*w  ww .j  a va 2s .  co  m*/
private void init(Calendar definingCalendar) {

    final StringBuilder regex = new StringBuilder();
    final List<Strategy> collector = new ArrayList<Strategy>();

    final Matcher patternMatcher = formatPattern.matcher(pattern);
    if (!patternMatcher.lookingAt()) {
        throw new IllegalArgumentException(
                "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'");
    }

    currentFormatField = patternMatcher.group();
    Strategy currentStrategy = getStrategy(currentFormatField, definingCalendar);
    for (;;) {
        patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd());
        if (!patternMatcher.lookingAt()) {
            nextStrategy = null;
            break;
        }
        final String nextFormatField = patternMatcher.group();
        nextStrategy = getStrategy(nextFormatField, definingCalendar);
        if (currentStrategy.addRegex(this, regex)) {
            collector.add(currentStrategy);
        }
        currentFormatField = nextFormatField;
        currentStrategy = nextStrategy;
    }
    if (patternMatcher.regionStart() != patternMatcher.regionEnd()) {
        throw new IllegalArgumentException(
                "Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
    }
    if (currentStrategy.addRegex(this, regex)) {
        collector.add(currentStrategy);
    }
    currentFormatField = null;
    strategies = collector.toArray(new Strategy[collector.size()]);
    parsePattern = Pattern.compile(regex.toString());
}

From source file:org.sqlite.date.FastDateParser.java

/**
 * Initialize derived fields from defining fields.
 * This is called from constructor and from readObject (de-serialization)
 *
 * @param definingCalendar the {@link java.util.Calendar} instance used to initialize this FastDateParser
 *//*ww w .j  a v a2  s.  co  m*/
private void init(final Calendar definingCalendar) {

    final StringBuilder regex = new StringBuilder();
    final List<Strategy> collector = new ArrayList<Strategy>();

    final Matcher patternMatcher = formatPattern.matcher(pattern);
    if (!patternMatcher.lookingAt()) {
        throw new IllegalArgumentException(
                "Illegal pattern character '" + pattern.charAt(patternMatcher.regionStart()) + "'");
    }

    currentFormatField = patternMatcher.group();
    Strategy currentStrategy = getStrategy(currentFormatField, definingCalendar);
    for (;;) {
        patternMatcher.region(patternMatcher.end(), patternMatcher.regionEnd());
        if (!patternMatcher.lookingAt()) {
            nextStrategy = null;
            break;
        }
        final String nextFormatField = patternMatcher.group();
        nextStrategy = getStrategy(nextFormatField, definingCalendar);
        if (currentStrategy.addRegex(this, regex)) {
            collector.add(currentStrategy);
        }
        currentFormatField = nextFormatField;
        currentStrategy = nextStrategy;
    }
    if (patternMatcher.regionStart() != patternMatcher.regionEnd()) {
        throw new IllegalArgumentException(
                "Failed to parse \"" + pattern + "\" ; gave up at index " + patternMatcher.regionStart());
    }
    if (currentStrategy.addRegex(this, regex)) {
        collector.add(currentStrategy);
    }
    currentFormatField = null;
    strategies = collector.toArray(new Strategy[collector.size()]);
    parsePattern = Pattern.compile(regex.toString());
}

From source file:org.xchain.framework.jsl.TemplateSourceBuilder.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  www  . j  a va 2  s.  c  o  m
public static List<String> parseAttributeValueTemplate(String attributeValueTemplate) throws SAXException {
    // the result.
    ArrayList<String> result = new ArrayList<String>();

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

    while (matcher.find()) {
        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);
        }
    }

    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: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 av  a 2 s .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;
}