Skip to content

Commit 52fd9be

Browse files
committed
resolve annoying rune bug
1 parent 0830b4b commit 52fd9be

1 file changed

Lines changed: 6 additions & 5 deletions

File tree

index.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,14 @@ func IndexAllIgnoreCase(haystack string, needle string, limit int) [][]int {
245245
}
246246

247247
// Cut off the number at the end to the number we need which is the length of the needle runes
248-
var toMatch []rune
249-
if match[0]+e > len(haystack) {
250-
toMatch = []rune(haystack[match[0] : len(haystack)-1])[:len(needleRune)]
251-
} else {
252-
toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]
248+
toMatchRune := []rune(haystack[match[0] : match[0]+e])
249+
toMatchEnd := len(needleRune)
250+
if len(toMatchRune) < len(needleRune) {
251+
toMatchEnd = len(toMatchRune)
253252
}
254253

254+
toMatch := toMatchRune[:toMatchEnd]
255+
255256
// old logic here
256257
//toMatch = []rune(haystack[match[0] : match[0]+e])[:len(needleRune)]
257258

0 commit comments

Comments
 (0)