diff options
| author | Jeff Carr <[email protected]> | 2024-01-09 19:35:05 -0600 |
|---|---|---|
| committer | Jeff Carr <[email protected]> | 2024-01-09 19:35:05 -0600 |
| commit | be54390fcd3513d0c1a0a57f783e57f5fe8f9816 (patch) | |
| tree | 69ce2dc69dafcf1a1c5ce315bdfc51aca319e2d8 /unix.go | |
| parent | abd9781d8a60ed9695951aa14e3a60275e831f63 (diff) | |
figure out the version
Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'unix.go')
| -rw-r--r-- | unix.go | 37 |
1 files changed, 37 insertions, 0 deletions
@@ -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 +} |
