tag : break apart into smaller files of related function

This commit is contained in:
bth 2026-01-20 14:46:04 -08:00
commit bab61c31a3
6 changed files with 431 additions and 399 deletions

43
tag/query.go Normal file
View file

@ -0,0 +1,43 @@
package tag
import "strings"
type Operator string
const (
SINGLE Operator = ""
OR Operator = ","
AND Operator = "+"
WILD Operator = "*"
)
type Query struct {
Op Operator
Tags []string
}
// TODO: only accepts one kind of syntax at a time
func parseQuery(query string) Query {
// initialize for the single tag case:
q := Query{
Op: SINGLE,
Tags: []string{query},
}
// count a missing tag as WILD:
if query == "" {
// TODO: somewhat abusing this concept for the empty query case:
q.Op = WILD
return q
}
// NOTE: will match OR first
ops := []Operator{OR, AND}
for _, op := range ops {
if s := strings.Split(query, string(op)); len(s) > 1 {
q.Op = op
q.Tags = s
break
}
}
return q
}