Exemple #1
0
    public Value matchPositions(Value str) {
      PatternMatcher matcher = getMatcher();

      // Do the matching
      PatternMatcherInput jStr = new PatternMatcherInput(string(str));
      Pair result = null;
      Pair prev = null;
      boolean found = false;

      while (matcher.contains(jStr, pattern)) {
        found = true;

        MatchResult matchResult = matcher.getMatch();

        for (int i = 0, length = matchResult.groups(); i < length; i++) {
          Pair m =
              new Pair(
                  Quantity.valueOf(matchResult.beginOffset(i)),
                  Quantity.valueOf(matchResult.endOffset(i)));
          Pair elem = new Pair(m, EMPTYLIST);
          if (result == null) result = prev = elem;
          else {
            prev.setCdr(elem);
            prev = elem;
          }
        }
      }

      if (!found) return FALSE;
      else return result;
    }
Exemple #2
0
  public RubyValue post_match() {
    String res = "";
    int nMatchEnd = result_.endOffset(result_.groups() - 1);
    if (nMatchEnd >= 0 && nMatchEnd + 1 < str_.length()) res = str_.substring(nMatchEnd);

    if (res == null) return RubyConstant.QNIL;

    return ObjectFactory.createString(res);
  }
Exemple #3
0
  private void initTemplate() {
    if (template != null) {
      return;
    }
    // Contains Strings and Integers
    List<Object> combined = new ArrayList<Object>();
    String rawTemplate = getTemplate();
    PatternMatcher matcher = JMeterUtils.getMatcher();
    Pattern templatePattern =
        JMeterUtils.getPatternCache()
            .getPattern(
                "\\$(\\d+)\\$" // $NON-NLS-1$
                ,
                Perl5Compiler.READ_ONLY_MASK & Perl5Compiler.SINGLELINE_MASK);
    if (log.isDebugEnabled()) {
      log.debug("Pattern = " + templatePattern.getPattern());
      log.debug("template = " + rawTemplate);
    }
    int beginOffset = 0;
    MatchResult currentResult;
    PatternMatcherInput pinput = new PatternMatcherInput(rawTemplate);
    while (matcher.contains(pinput, templatePattern)) {
      currentResult = matcher.getMatch();
      final int beginMatch = currentResult.beginOffset(0);
      if (beginMatch > beginOffset) { // string is not empty
        combined.add(rawTemplate.substring(beginOffset, beginMatch));
      }
      combined.add(Integer.valueOf(currentResult.group(1))); // add match as Integer
      beginOffset = currentResult.endOffset(0);
    }

    if (beginOffset < rawTemplate.length()) { // trailing string is not empty
      combined.add(rawTemplate.substring(beginOffset, rawTemplate.length()));
    }
    if (log.isDebugEnabled()) {
      log.debug("Template item count: " + combined.size());
      for (Object o : combined) {
        log.debug(o.getClass().getSimpleName() + " '" + o.toString() + "'");
      }
    }
    template = combined;
  }