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)
| 348 | // occurrences of needle in haystack. Exact for chip labels, which cannot |
| 349 | // self-overlap (they start with the unique "[" of the label format). |
| 350 | func 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 |