text.gno
0.80 Kb · 36 lines
1package gild
2
3import "strings"
4
5func trimSpace(s string) string { return strings.TrimSpace(s) }
6
7// checkText panics with msg unless s has between min and max characters and
8// contains no control characters other than newline and tab.
9func checkText(s string, min, max int, msg string) {
10 n := 0
11 for _, r := range s {
12 if r < 0x20 && r != '\n' && r != '\t' {
13 panic(msg)
14 }
15 if r == 0x7f {
16 panic(msg)
17 }
18 n++
19 }
20 if n < min || n > max {
21 panic(msg)
22 }
23}
24
25// isWorkURL accepts https links with no spaces or control characters.
26func isWorkURL(s string) bool {
27 if len(s) > MaxURL || !strings.HasPrefix(s, "https://") || len(s) <= len("https://") {
28 return false
29 }
30 for _, r := range s {
31 if r <= 0x20 || r == 0x7f || r == '"' || r == '<' || r == '>' || r == '`' {
32 return false
33 }
34 }
35 return true
36}