diff options
Diffstat (limited to 'libgo/go/runtime/string.go')
-rw-r--r-- | libgo/go/runtime/string.go | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/libgo/go/runtime/string.go b/libgo/go/runtime/string.go index 741b6b4..df4cae7 100644 --- a/libgo/go/runtime/string.go +++ b/libgo/go/runtime/string.go @@ -508,3 +508,37 @@ func __go_byte_array_to_string(p unsafe.Pointer, l int) string { func __go_string_to_byte_array(s string) []byte { return stringtoslicebyte(nil, s) } + +// parseRelease parses a dot-separated version number. It follows the +// semver syntax, but allows the minor and patch versions to be +// elided. +func parseRelease(rel string) (major, minor, patch int, ok bool) { + // Strip anything after a dash or plus. + for i := 0; i < len(rel); i++ { + if rel[i] == '-' || rel[i] == '+' { + rel = rel[:i] + break + } + } + + next := func() (int, bool) { + for i := 0; i < len(rel); i++ { + if rel[i] == '.' { + ver, ok := atoi(rel[:i]) + rel = rel[i+1:] + return ver, ok + } + } + ver, ok := atoi(rel) + rel = "" + return ver, ok + } + if major, ok = next(); !ok || rel == "" { + return + } + if minor, ok = next(); !ok || rel == "" { + return + } + patch, ok = next() + return +} |