From ded6e3b25bca083cabe21bda6f4d01f6766587bc Mon Sep 17 00:00:00 2001 From: Adam Mathes Date: Thu, 9 Feb 2017 19:40:44 -0800 Subject: initial commit (fmstatic -> snkt) --- text/text.go | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) create mode 100644 text/text.go (limited to 'text') diff --git a/text/text.go b/text/text.go new file mode 100644 index 0000000..7666e91 --- /dev/null +++ b/text/text.go @@ -0,0 +1,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)) +} -- cgit v1.2.3