diff options
Diffstat (limited to 'readControlFile.go')
| -rw-r--r-- | readControlFile.go | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/readControlFile.go b/readControlFile.go index 21e141a..b53a79d 100644 --- a/readControlFile.go +++ b/readControlFile.go @@ -4,11 +4,26 @@ import ( "bufio" "os" "strings" + "unicode" "go.wit.com/lib/protobuf/gitpb" "go.wit.com/log" ) +func trimNonNumericPrefix(s string) string { + // Find the index of the first character that IS a digit. + firstDigitIndex := strings.IndexFunc(s, unicode.IsDigit) + + // If no digit is found, IndexFunc returns -1. + // In this case, the result should be an empty string. + if firstDigitIndex == -1 { + return "" + } + + // Return the substring starting from the first digit. + return s[firstDigitIndex:] +} + // readGitConfig reads and parses the control file func readControlFile(repo *gitpb.Repo) error { pairs := make(map[string]string) @@ -31,6 +46,8 @@ func readControlFile(repo *gitpb.Repo) error { } defer file.Close() + pairs["Version"] = trimNonNumericPrefix(repo.GetCurrentVersion()) + scanner := bufio.NewScanner(file) for scanner.Scan() { line := scanner.Text() |
