|
|
@ -21,6 +21,15 @@ func dotChars() []rune { // Returns all possible characters represented by the d
|
|
|
|
return to_return
|
|
|
|
return to_return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Returns true if str[idx] and str[idx-1] are separated by a word boundary.
|
|
|
|
|
|
|
|
func isWordBoundary(str []rune, idx int) bool {
|
|
|
|
|
|
|
|
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]))
|
|
|
|
|
|
|
|
return wbounded
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
func isAlphaNum(c rune) bool {
|
|
|
|
func isAlphaNum(c rune) bool {
|
|
|
|
return unicode.IsLetter(c) || unicode.IsNumber(c)
|
|
|
|
return unicode.IsLetter(c) || unicode.IsNumber(c)
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -31,6 +40,16 @@ func assert(cond bool) {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
func deleteFromSlice[T comparable](slc []T, val T) []T {
|
|
|
|
|
|
|
|
toReturn := make([]T, 0)
|
|
|
|
|
|
|
|
for _, v := range slc {
|
|
|
|
|
|
|
|
if v != val {
|
|
|
|
|
|
|
|
toReturn = append(toReturn, v)
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
return toReturn
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Ensure that the given elements are only appended to the given slice if they
|
|
|
|
// Ensure that the given elements are only appended to the given slice if they
|
|
|
|
// don't already exist. Returns the new slice, and the number of unique items appended.
|
|
|
|
// don't already exist. Returns the new slice, and the number of unique items appended.
|
|
|
|
func unique_append[T comparable](slc []T, items ...T) ([]T, int) {
|
|
|
|
func unique_append[T comparable](slc []T, items ...T) ([]T, int) {
|
|
|
|