Scoop API

scoop:scoop.readline:0.1.0

src/history/matching.scoop

Selected production source · src/history/matching.scoop

1package scoop.readline.history
3import scoop.charset.unicodeCasefold
4import scoop.text.*
6internal fun foldedMatch(entry: String, term: String, prefix: Boolean): Long {
7 val folded = StringBuilder()
8 val offsets = ArrayList<Long>()
9 var offset = 0L
10 for (character in entry) {
11 val part = unicodeCasefold(character.toString())
12 folded.append(part)
13 var index = 0L
14 while (index < part.charLength) { offsets.add(offset); index += 1L }
15 offset += 1L
16 }
17 val query = unicodeCasefold(term)
18 val position = folded.toString().indexOf(query)
19 if (position < 0L || (prefix && position != 0L)) return -1L
20 return if (prefix) offsets[query.charLength - 1L] + 1L else offsets[position]