Files
silo-server/internal/collectionutil/collectionutil.go
T

43 lines
825 B
Go

package collectionutil
import (
"errors"
"strings"
)
var ErrOrderedIDsMismatch = errors.New("ordered_ids does not match the current set")
func HasDuplicateOrderedIDs(ids []string) bool {
seen := make(map[string]struct{}, len(ids))
for _, id := range ids {
if _, ok := seen[id]; ok {
return true
}
seen[id] = struct{}{}
}
return false
}
func SlugifyGroupSlug(s string) string {
s = strings.ToLower(strings.TrimSpace(s))
var b strings.Builder
prevDash := false
for _, r := range s {
switch {
case (r >= 'a' && r <= 'z') || (r >= '0' && r <= '9'):
b.WriteRune(r)
prevDash = false
case r == ' ' || r == '-' || r == '_':
if !prevDash && b.Len() > 0 {
b.WriteRune('-')
prevDash = true
}
}
}
out := strings.Trim(b.String(), "-")
if out == "" {
return "group"
}
return out
}