aboutsummaryrefslogtreecommitdiffstats
path: root/text/text.go
blob: 7666e91f8da0191aed344d61b918c19c69ef9f1a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
// package text is a utility library of various text/string manipulations
package text

import (
	"regexp"
	"strings"
	"path"
)

// Sanitize filename string for FILE/URL output but removing non-alphanumerics and trimming space
func SanitizeFilename(s string) string {
	fileNoNos := regexp.MustCompile(`[^[:alnum:]-]`)
	s = strings.Trim(s, " ")
	s = strings.Replace(s, " ", "-", -1)
	s = fileNoNos.ReplaceAllString(s, "-")
	return s
}

// Remove the filename extension
func RemoveExt(src string) string {
	return strings.TrimSuffix(src, path.Ext(src))
}