You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

30 lines
348 B

package tagengine
import "unicode"
func ngramLength(s string) int {
N := len(s)
i := 0
count := 0
for {
// Eat spaces.
for i < N && unicode.IsSpace(rune(s[i])) {
i++
}
// Done?
if i == N {
break
}
// Non-space!
count++
// Eat non-spaces.
for i < N && !unicode.IsSpace(rune(s[i])) {
i++
}
}
return count
}