Replaced rune-slice parameters with string parameters in functions; avoids unnecessary conversion from strings to rune-slices

This commit is contained in:
2024-11-01 01:53:50 -04:00
parent 723be527fb
commit dca81c1796
3 changed files with 10 additions and 9 deletions

View File

@@ -22,11 +22,12 @@ func dotChars() []rune { // Returns all possible characters represented by the d
}
// Returns true if str[idx] and str[idx-1] are separated by a word boundary.
func isWordBoundary(str []rune, idx int) bool {
func isWordBoundary(str string, idx int) bool {
str_runes := []rune(str)
wbounded := idx == 0 ||
idx >= len(str)-1 ||
(!slices.Contains(wordChars, str[idx-1]) && slices.Contains(wordChars, str[idx])) ||
(slices.Contains(wordChars, str[idx-1]) && !slices.Contains(wordChars, str[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
}