aboutsummaryrefslogtreecommitdiffstats
path: root/skate/slugify.go
blob: e8fa8bf922570500bda5835786633eaf1312f1a1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
package skate

import (
	"bytes"
	"fmt"
	"strings"
)

// slugifyString is a basic string slugifier.
func slugifyString(s string) string {
	var buf bytes.Buffer
	for _, c := range strings.TrimSpace(strings.ToLower(s)) {
		if (c > 96 && c < 123) || (c > 47 && c < 58) || (c == 32) || (c == 9) || (c == 10) {
			fmt.Fprintf(&buf, "%c", c)
		}
	}
	return strings.Join(strings.Fields(buf.String()), " ")
}