in src/main/kotlin/com/intellij/ideolog/lex/LogFileLexer.kt [76:113]
fun lexRegex(event: CharSequence, output: MutableList<LogToken>, onlyValues: Boolean, parser: RegexLogParser) {
val endOfLineIndex = if (event.length > MAX_PARSING_LENGTH) MAX_PARSING_LENGTH else event.indexOf('\n')
val eventIsMultiline = endOfLineIndex != -1
val dataToMatch = if (!eventIsMultiline) event else event.subSequence(0, endOfLineIndex)
val matcher = parser.regex.matcher(dataToMatch)
if (!matcher.find() || matcher.groupCount() == 0) {
output.add(LogToken(0, event.length, false))
return
}
var lastGroupEnd = 0
for(i in 1 .. matcher.groupCount()) {
val start = matcher.start(i)
if (start < lastGroupEnd) continue
val end = matcher.end(i)
if(end < 0)
continue
if(start > lastGroupEnd) {
if(!onlyValues)
output.add(LogToken(lastGroupEnd, start, true))
}
output.add(LogToken(start, end, false))
lastGroupEnd = end
}
if (eventIsMultiline) {
val lastToken = output.removeAt(output.lastIndex)
output.add(LogToken(lastToken.startOffset, event.length, false))
} else if(lastGroupEnd < matcher.end() && !onlyValues) {
output.add(LogToken(lastGroupEnd, matcher.end(), true))
}
}