libgo: update to Go1.14beta1
[platform/upstream/gcc.git] / libgo / go / runtime / string.go
index 741b6b4..df4cae7 100644 (file)
@@ -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
+}