<commit_before>/**
 * Copyright 2011-2014 eBusiness Information, Groupe Excilys (www.ebusinessinformation.fr)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gatling.core.check.extractor.regex

import scala.annotation.implicitNotFound

import java.util.regex.Matcher

import com.typesafe.scalalogging.slf4j.StrictLogging

import io.gatling.core.util.StringHelper.RichString

trait LowPriorityGroupExtractorImplicits extends StrictLogging {

	implicit val stringGroupExtractor = new GroupExtractor[String] {
		def extract(matcher: Matcher): String =
			safeGetGroupValue(matcher, math.min(matcher.groupCount, 1))
	}

	def safeGetGroupValue(matcher: Matcher, i: Int): String =
		if (matcher.groupCount >= i)
			matcher.group(i) match {
				case null => ""
				case value => value.ensureTrimmedCharsArray<commit_msg>Have stringGroupExtractor deal with pipes, close #1683<commit_after>/**
 * Copyright 2011-2014 eBusiness Information, Groupe Excilys (www.ebusinessinformation.fr)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * 		http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package io.gatling.core.check.extractor.regex

import java.util.regex.Matcher

import scala.annotation.{ implicitNotFound, tailrec }

import com.typesafe.scalalogging.slf4j.StrictLogging

import io.gatling.core.util.StringHelper.RichString

trait LowPriorityGroupExtractorImplicits extends StrictLogging {

	implicit val stringGroupExtractor = new GroupExtractor[String] {

		def extract(matcher: Matcher): String = {

			@tailrec
			def extractFirstNonNullGroupRec(i: Int, max: Int): String = {
				matcher.group(i) match {
					case null =>
						if (i < max)
							extractFirstNonNullGroupRec(i + 1, max)
						else
							"" // shouldn't happen, as the regex matched, we should have at least one non null group
					case value => value.ensureTrimmedCharsArray
				}
			}

			matcher.groupCount match {
				case 0 => safeGetGroupValue(matcher, 0)
				case count => extractFirstNonNullGroupRec(1, count)
			}
		}
	}

	def safeGetGroupValue(matcher: Matcher, i: Int): String =
		if (matcher.groupCount >= i)
			matcher.group(i) match {
				case null => ""
				case value => value.ensureTrimmedCharsArray
{'fraction_non_alphanumeric': 0.08533501896333755, 'fraction_numerical': 0.011061946902654867, 'mean_word_length': 4.137987012987013, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7063584', 'n_tokens_mistral': 1023, 'n_tokens_neox': 907, 'n_words': 306}