summaryrefslogtreecommitdiff
path: root/unix.go
diff options
context:
space:
mode:
Diffstat (limited to 'unix.go')
-rw-r--r--unix.go37
1 files changed, 37 insertions, 0 deletions
diff --git a/unix.go b/unix.go
index 1f31700..3f7ad0b 100644
--- a/unix.go
+++ b/unix.go
@@ -5,6 +5,7 @@ import (
"os"
"os/exec"
"strings"
+ "regexp"
"go.wit.com/log"
)
@@ -52,3 +53,39 @@ func listFiles(directory string) []string {
return files
}
+
+/*
+// string handling examples that might be helpful for normalizeInt()
+isAlpha := regexp.MustCompile(`^[A-Za-z]+$`).MatchString
+
+for _, username := range []string{"userone", "user2", "user-three"} {
+ if !isAlpha(username) {
+ log.Log(GUI, "%q is not valid\n", username)
+ }
+}
+
+const alpha = "abcdefghijklmnopqrstuvwxyz"
+
+func alphaOnly(s string) bool {
+ for _, char := range s {
+ if !strings.Contains(alpha, strings.ToLower(string(char))) {
+ return false
+ }
+ }
+ return true
+}
+*/
+
+func normalizeVersion(s string) string {
+ // reg, err := regexp.Compile("[^a-zA-Z0-9]+")
+ parts := strings.Split(s, "-")
+ if len(parts) == 0 { return "" }
+ reg, err := regexp.Compile("[^0-9.]+")
+ if err != nil {
+ log.Log(WARN, "normalizeVersion() regexp.Compile() ERROR =", err)
+ return parts[0]
+ }
+ clean := reg.ReplaceAllString(parts[0], "")
+ log.Log(WARN, "normalizeVersion() s =", clean)
+ return clean
+}