in version-utils/src/commonMain/kotlin/org/jetbrains/packagesearch/packageversionutils/VersionTokenMatcher.kt [9:38]
override fun matches(value: String): Boolean {
val substringIndex = value.indexOf(toMatch, ignoreCase = true)
if (substringIndex < 0) return false
val afterSubstringIndex = substringIndex + toMatchLength
val valueLength = value.length
// Case 1. The value matches entirely
if (substringIndex == 0 && afterSubstringIndex == valueLength) return true
// Case 2. The match is at the beginning of value
if (substringIndex == 0) {
val nextLetter = value[afterSubstringIndex]
return !nextLetter.isLetter() // Matching whole word
}
// Case 2. The match is at the end of value
if (afterSubstringIndex == valueLength) {
val previousLetter = value[substringIndex - 1]
return !previousLetter.isLetterOrDigit() && previousLetter != '_' // Matching whole word
}
// Case 3. The match is somewhere inside of value
val previousLetter = value[substringIndex - 1]
val startsAtWordBoundary = !previousLetter.isLetterOrDigit() && previousLetter != '_'
val nextLetter = value[afterSubstringIndex]
val endsAtWordBoundary = !nextLetter.isLetter()
return startsAtWordBoundary && endsAtWordBoundary // Needs to be matching a whole word
}