Scoop API

scoop:scoop.ui:0.1.0

src/text/services.scoop

Selected production source · src/text/services.scoop

1package scoop.ui.text
3import scoop.window.*
5internal struct TextCheckingContext(val text: String, val start: Long)
7internal fun textCheckingContext(text: String, range: Utf8Range): TextCheckingContext {
8 val bytes = text.toByteArray()
9 var start = range.start
10 var end = range.end
11 while (start > 0L && bytes[start - 1L] != 10.toByte() && bytes[start - 1L] != 13.toByte())
12 start -= 1L
13 while (end < bytes.size && bytes[end] != 10.toByte() && bytes[end] != 13.toByte())
14 end += 1L
15 return TextCheckingContext(text.utf8Slice(Utf8Range(start, end)), start)
18internal fun textCheckTouches(finding: Utf8Range, selection: Utf8Range): Boolean =
19 if (selection.start == selection.end)
20 finding.start <= selection.start && finding.end >= selection.end
21 else
22 finding.start < selection.end && finding.end > selection.start