ParseVersionedPackage checks if the given package is a versioned package (`python@3.10`) and returns its name and version
(versionedName string)
| 10 | // ParseVersionedPackage checks if the given package is a versioned package |
| 11 | // (`python@3.10`) and returns its name and version |
| 12 | func ParseVersionedPackage(versionedName string) (name, version string, found bool) { |
| 13 | // use the last @ symbol as the version delimiter, some packages have @ in the name |
| 14 | atSymbolIndex := strings.LastIndex(versionedName, "@") |
| 15 | if atSymbolIndex == -1 { |
| 16 | return "", "", false |
| 17 | } |
| 18 | if atSymbolIndex == len(versionedName)-1 { |
| 19 | // This case handles packages that end with `@` in the name |
| 20 | // example: `emacsPackages.@` |
| 21 | return "", "", false |
| 22 | } |
| 23 | |
| 24 | // Common case: package@version |
| 25 | name, version = versionedName[:atSymbolIndex], versionedName[atSymbolIndex+1:] |
| 26 | return name, version, true |
| 27 | } |
no outgoing calls