aboutsummaryrefslogtreecommitdiffstats
path: root/text/text.go
diff options
context:
space:
mode:
Diffstat (limited to 'text/text.go')
-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))
+}