Skip to content

Commit 0c83536

Browse files
committed
add NewIdentityFromString()
1 parent 7cc7021 commit 0c83536

1 file changed

Lines changed: 15 additions & 0 deletions

File tree

lang/uniast/ast.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,21 @@ func NewIdentity(mod, pkg, name string) Identity {
256256
return Identity{ModPath: mod, PkgPath: pkg, Name: name}
257257
}
258258

259+
func NewIdentityFromString(str string) (ret Identity) {
260+
sp := strings.Split(str, "?")
261+
if len(sp) == 2 {
262+
ret.ModPath = sp[0]
263+
str = sp[1]
264+
}
265+
sp = strings.Split(str, "#")
266+
if len(sp) == 2 {
267+
ret.PkgPath = sp[0]
268+
str = sp[1]
269+
}
270+
ret.Name = str
271+
return ret
272+
}
273+
259274
// return full packagepath.name
260275
func (i Identity) String() string {
261276
return i.PkgPath + "#" + i.Name

0 commit comments

Comments
 (0)