2021-09-18 15:32:39 +02:00
|
|
|
package txt
|
|
|
|
|
|
|
|
import (
|
|
|
|
"strings"
|
|
|
|
)
|
|
|
|
|
|
|
|
const (
|
2022-07-22 12:38:25 +02:00
|
|
|
EmptyString = ""
|
|
|
|
Space = " "
|
|
|
|
Or = "|"
|
|
|
|
And = "&"
|
2021-09-18 15:32:39 +02:00
|
|
|
)
|
|
|
|
|
2021-10-13 16:12:56 +02:00
|
|
|
// Spaced returns the string padded with a space left and right.
|
|
|
|
func Spaced(s string) string {
|
|
|
|
return Space + s + Space
|
|
|
|
}
|
|
|
|
|
|
|
|
// StripOr removes or operators from a query.
|
|
|
|
func StripOr(s string) string {
|
|
|
|
s = strings.ReplaceAll(s, Or, Space)
|
|
|
|
return s
|
|
|
|
}
|
|
|
|
|
2021-09-18 15:32:39 +02:00
|
|
|
// QueryTooShort tests if a search query is too short.
|
|
|
|
func QueryTooShort(q string) bool {
|
|
|
|
q = strings.Trim(q, "- '")
|
|
|
|
|
2022-07-22 12:38:25 +02:00
|
|
|
return q != EmptyString && len(q) < 3 && IsLatin(q)
|
2021-09-18 15:32:39 +02:00
|
|
|
}
|