Fixed error in calculating word boundary (off-by-one)

master
Aadhavan Srinivasan 2 months ago
parent c032dcb2ea
commit 9698c4f1d8

@ -25,7 +25,7 @@ func dotChars() []rune { // Returns all possible characters represented by the d
func isWordBoundary(str string, idx int) bool { func isWordBoundary(str string, idx int) bool {
str_runes := []rune(str) str_runes := []rune(str)
wbounded := idx == 0 || wbounded := idx == 0 ||
idx >= len(str)-1 || idx >= len(str) ||
(!slices.Contains(wordChars, str_runes[idx-1]) && slices.Contains(wordChars, str_runes[idx])) || (!slices.Contains(wordChars, str_runes[idx-1]) && slices.Contains(wordChars, str_runes[idx])) ||
(slices.Contains(wordChars, str_runes[idx-1]) && !slices.Contains(wordChars, str_runes[idx])) (slices.Contains(wordChars, str_runes[idx-1]) && !slices.Contains(wordChars, str_runes[idx]))
return wbounded return wbounded

Loading…
Cancel
Save