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

Function runeCount

internal/tui/prompt.go:350–363  ·  view source on GitHub ↗

runeCount is the counting counterpart of runeIndex: non-overlapping occurrences of needle in haystack. Exact for chip labels, which cannot self-overlap (they start with the unique "[" of the label format).

(haystack, needle []rune)

Source from the content-addressed store, hash-verified

348// occurrences of needle in haystack. Exact for chip labels, which cannot
349// self-overlap (they start with the unique "[" of the label format).
350func runeCount(haystack, needle []rune) int {
351 if len(needle) == 0 {
352 return 0
353 }
354 count, from := 0, 0
355 for {
356 idx := runeIndex(haystack[from:], needle)
357 if idx < 0 {
358 return count
359 }
360 count++
361 from += idx + len(needle)
362 }
363}
364
365// runeIndex is a rune-level strings.Index: first occurrence of needle in
366// haystack, or -1. promptInput works in runes throughout because textarea's

Callers 1

reconcileMethod · 0.85

Calls 1

runeIndexFunction · 0.85

Tested by

no test coverage detected