MCPcopy Create free account
hub / github.com/codehamr/codehamr / runeIndex

Function runeIndex

internal/tui/prompt.go:368–388  ·  view source on GitHub ↗

runeIndex is a rune-level strings.Index: first occurrence of needle in haystack, or -1. promptInput works in runes throughout because textarea's cursor is rune-addressed (column = rune count, not byte count).

(haystack, needle []rune)

Source from the content-addressed store, hash-verified

366// haystack, or -1. promptInput works in runes throughout because textarea's
367// cursor is rune-addressed (column = rune count, not byte count).
368func runeIndex(haystack, needle []rune) int {
369 if len(needle) == 0 {
370 return 0
371 }
372 if len(needle) > len(haystack) {
373 return -1
374 }
375 for i := 0; i <= len(haystack)-len(needle); i++ {
376 match := true
377 for j := range needle {
378 if haystack[i+j] != needle[j] {
379 match = false
380 break
381 }
382 }
383 if match {
384 return i
385 }
386 }
387 return -1
388}
389
390// cursorRuneOffset returns the cursor as an absolute rune index into Value().
391// textarea only exposes (row, col) plus LineInfo, so we reconstruct it by

Callers 2

reconcileMethod · 0.85
runeCountFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected