aboutsummaryrefslogtreecommitdiffstats
path: root/text
diff options
context:
space:
mode:
authorAdam Mathes <adam@trenchant.org>2017-02-09 19:40:44 -0800
committerAdam Mathes <adam@trenchant.org>2017-02-09 19:40:44 -0800
commitded6e3b25bca083cabe21bda6f4d01f6766587bc (patch)
tree2855fa24e8b2f939bdf091f5faca411e7884ac83 /text
downloadsnkt-ded6e3b25bca083cabe21bda6f4d01f6766587bc.tar.gz
snkt-ded6e3b25bca083cabe21bda6f4d01f6766587bc.tar.bz2
snkt-ded6e3b25bca083cabe21bda6f4d01f6766587bc.zip
initial commit (fmstatic -> snkt)
Diffstat (limited to 'text')
-rw-r--r--text/text.go22
1 files changed, 22 insertions, 0 deletions
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))
+}