Take caution when advancing to the next match after an empty string was matched not to stuck at the same position.

This commit is contained in:
Ilya Gorbunov
2015-04-23 18:04:50 +03:00
parent 260553d516
commit aa6bdb039b
3 changed files with 4 additions and 4 deletions
+1 -1
View File
@@ -188,6 +188,6 @@ private fun RegExp.findNext(input: String, from: Int): MatchResult? {
override fun get(index: Int): MatchGroup? = match[index]?.let { MatchGroup(it) }
}
override fun next(): MatchResult? = this@findNext.findNext(input, range.end + 1)
override fun next(): MatchResult? = this@findNext.findNext(input, if (range.isEmpty()) range.start + 1 else range.end + 1)
}
}
@@ -244,7 +244,7 @@ private fun Matcher.findNext(from: Int): MatchResult? {
}
override fun next(): MatchResult? = this@findNext.findNext(matchResult.end())
override fun next(): MatchResult? = this@findNext.findNext(matchResult.end() + if (matchResult.end() == matchResult.start()) 1 else 0)
}
}
+2 -2
View File
@@ -86,8 +86,8 @@ class RegexTest {
test fun matchMultiline() {
val regex = "^[a-z]*$".toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE))
val matchedValues = regex.matchAll("test\r\nLine").map { it.value }.toList()
assertEquals(listOf("test", "Line"), matchedValues)
val matchedValues = regex.matchAll("test\n\nLine").map { it.value }.toList()
assertEquals(listOf("test", "", "Line"), matchedValues)
}
test fun escapeLiteral() {