Skip to content
Permalink
Browse files
Java Regex split() works quite different to oro split()
Use a different approach to split the template and correct the
difference between Java Regex groupCount() and Oro groups()
  • Loading branch information
FSchumacher committed Mar 5, 2022
1 parent ce9adc6 commit 9681192291ccd7e89cb1bd3d60b704abdaac7c09
Showing 1 changed file with 11 additions and 23 deletions.
@@ -291,7 +291,7 @@ private Pattern generateOroPattern() throws InvalidVariableException {
}

private void saveGroups(java.util.regex.MatchResult result, String namep, JMeterVariables vars) {
for (int x = 0; x < result.groupCount(); x++) {
for (int x = 0; x <= result.groupCount(); x++) {
vars.put(namep + "_g" + x, result.group(x)); //$NON-NLS-1$
}
}
@@ -363,32 +363,20 @@ private Object[] generateTemplate(String rawTemplate) {

private Object[] generateTemplateWithJavaRegex(String rawTemplate) {
// String or Integer
List<Object> combined = new ArrayList<>();
List<String> pieces = Arrays.asList(templatePatternJava.split(rawTemplate));
List<Object> pieces = new ArrayList<>();
Matcher matcher = templatePatternJava.matcher(rawTemplate);
boolean startsWith = isFirstElementGroup(rawTemplate);
if (startsWith) {
pieces.remove(0);// Remove initial empty entry
}
Iterator<String> iter = pieces.iterator();
while (iter.hasNext()) {
boolean matchExists = matcher.find();
if (startsWith) {
if (matchExists) {
combined.add(Integer.valueOf(matcher.group(1)));
}
combined.add(iter.next());
} else {
combined.add(iter.next());
if (matchExists) {
combined.add(Integer.valueOf(matcher.group(1)));
}
int pos = 0;
while (matcher.find()) {
if (pos < matcher.start()) {
pieces.add(rawTemplate.substring(pos, matcher.start()));
}
pieces.add(Integer.valueOf(matcher.group(1)));
pos = matcher.end();
}
if (matcher.find()) {
combined.add(Integer.valueOf(matcher.group(1)));
if (pos < rawTemplate.length()) {
pieces.add(rawTemplate.substring(pos));
}
return combined.toArray();
return pieces.toArray();
}

private Object[] generateTemplateWithOroRegex(String rawTemplate) {

0 comments on commit 9681192

Please sign in to comment.