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.
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/") {
16 f
:= strings
.Split(path
, "/")
18 if elem
, v
, ok
:= dotV(f
[1]); ok
{
19 root
= strings
.Join(f
[:2], "/")
20 repo
= "github.com/go-" + elem
+ "/" + elem
22 subdir
= strings
.Join(f
[2:], "/")
23 return root
, repo
, major
, subdir
, true
27 if elem
, v
, ok
:= dotV(f
[2]); ok
{
28 root
= strings
.Join(f
[:3], "/")
29 repo
= "github.com/" + f
[1] + "/" + elem
31 subdir
= strings
.Join(f
[3:], "/")
32 return root
, repo
, major
, subdir
, true
38 func dotV(name
string) (elem
, v
string, ok
bool) {
40 for i
>= 0 && '0' <= name
[i
] && name
[i
] <= '9' {
43 if i
<= 2 || i
+1 >= len(name
) || name
[i
-1] != '.' || name
[i
] != 'v' || name
[i
+1] == '0' && len(name
) != i
+2 {
46 return name
[:i
-1], name
[i
:], true