libgo: update to Go 1.11
[official-gcc.git] / libgo / go / cmd / go / internal / modfile / gopkgin.go
blobc94b3848a0e163a4d4220f0f39e00a390cd38c23
1 // Copyright 2018 The Go Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
5 // TODO: Figure out what gopkg.in should do.
7 package modfile
9 import "strings"
11 // ParseGopkgIn splits gopkg.in import paths into their constituent parts
12 func ParseGopkgIn(path string) (root, repo, major, subdir string, ok bool) {
13 if !strings.HasPrefix(path, "gopkg.in/") {
14 return
16 f := strings.Split(path, "/")
17 if len(f) >= 2 {
18 if elem, v, ok := dotV(f[1]); ok {
19 root = strings.Join(f[:2], "/")
20 repo = "github.com/go-" + elem + "/" + elem
21 major = v
22 subdir = strings.Join(f[2:], "/")
23 return root, repo, major, subdir, true
26 if len(f) >= 3 {
27 if elem, v, ok := dotV(f[2]); ok {
28 root = strings.Join(f[:3], "/")
29 repo = "github.com/" + f[1] + "/" + elem
30 major = v
31 subdir = strings.Join(f[3:], "/")
32 return root, repo, major, subdir, true
35 return
38 func dotV(name string) (elem, v string, ok bool) {
39 i := len(name) - 1
40 for i >= 0 && '0' <= name[i] && name[i] <= '9' {
41 i--
43 if i <= 2 || i+1 >= len(name) || name[i-1] != '.' || name[i] != 'v' || name[i+1] == '0' && len(name) != i+2 {
44 return "", "", false
46 return name[:i-1], name[i:], true