public void display(ValueWriter w) throws IOException { w.append("#<regexp ") .append(pattern.getClass().getName()) .append(" '") .append(pattern.getPattern().toString()) .append("'>"); }
private void recompilePatternIfNecessary(String regexpPattern) { if (pattern == null || !regexpPattern.equals(pattern.getPattern())) { try { pattern = compiler.compile(regexpPattern); } catch (MalformedPatternException e) { throw new RuntimeException(e); } } }
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; }
public void serialize(sisc.ser.Serializer s) throws IOException { s.writeExpression(type); s.writeUTF(pattern.getPattern()); s.writeInt(pattern.getOptions()); }
public boolean valueEqual(Value ov) { return (ov instanceof RPattern) && pattern.equals(((RPattern) ov).pattern); }