diff options
Diffstat (limited to 'android/util.go')
-rw-r--r-- | android/util.go | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/android/util.go b/android/util.go index e02cca1df..010244209 100644 --- a/android/util.go +++ b/android/util.go @@ -16,6 +16,7 @@ package android import ( "fmt" + "path/filepath" "reflect" "regexp" "runtime" @@ -292,3 +293,29 @@ func matchPattern(pat, str string) bool { } return strings.HasPrefix(str, pat[:i]) && strings.HasSuffix(str, pat[i+1:]) } + +var shlibVersionPattern = regexp.MustCompile("(?:\\.\\d+(?:svn)?)+") + +// splitFileExt splits a file name into root, suffix and ext. root stands for the file name without +// the file extension and the version number (e.g. "libexample"). suffix stands for the +// concatenation of the file extension and the version number (e.g. ".so.1.0"). ext stands for the +// file extension after the version numbers are trimmed (e.g. ".so"). +func SplitFileExt(name string) (string, string, string) { + // Extract and trim the shared lib version number if the file name ends with dot digits. + suffix := "" + matches := shlibVersionPattern.FindAllStringIndex(name, -1) + if len(matches) > 0 { + lastMatch := matches[len(matches)-1] + if lastMatch[1] == len(name) { + suffix = name[lastMatch[0]:lastMatch[1]] + name = name[0:lastMatch[0]] + } + } + + // Extract the file name root and the file extension. + ext := filepath.Ext(name) + root := strings.TrimSuffix(name, ext) + suffix = ext + suffix + + return root, suffix, ext +} |