From 52fd9be42987905a0cc868fa28e24217c3f12f4b Mon Sep 17 00:00:00 2001 From: Ben Boyter Date: Mon, 29 May 2023 16:11:28 +1000 Subject: [PATCH] resolve annoying rune bug --- index.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/index.go b/index.go index a51fc44..388d1c9 100644 --- a/index.go +++ b/index.go @@ -245,13 +245,14 @@ func IndexAllIgnoreCase(haystack string, needle string, limit int) [][]int { } // Cut off the number at the end to the number we need which is the length of the needle runes - var toMatch []rune - if match[0]+e > len(haystack) { - toMatch = []rune(haystack[match[0] : len(haystack)-1])[:len(needleRune)] - } else { - toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)] + toMatchRune := []rune(haystack[match[0] : match[0]+e]) + toMatchEnd := len(needleRune) + if len(toMatchRune) < len(needleRune) { + toMatchEnd = len(toMatchRune) } + toMatch := toMatchRune[:toMatchEnd] + // old logic here //toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]