add ReplaceExtensions to pathtools
Change-Id: I6dc92323d4b0ef4b0f31076c868802dc568346c4
This commit is contained in:
parent
e98b8a927d
commit
310794f016
1 changed files with 13 additions and 0 deletions
|
@ -2,6 +2,11 @@ package pathtools
|
|||
|
||||
import (
|
||||
"path/filepath"
|
||||
"regexp"
|
||||
)
|
||||
|
||||
var (
|
||||
replaceRegexp = regexp.MustCompile(`\.[^\.]+$`)
|
||||
)
|
||||
|
||||
// PrefixPaths returns a list of paths consisting of prefix joined with each
|
||||
|
@ -14,3 +19,11 @@ func PrefixPaths(paths []string, prefix string) []string {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
func ReplaceExtensions(paths []string, extension string) []string {
|
||||
result := make([]string, len(paths))
|
||||
for i, path := range paths {
|
||||
result[i] = replaceRegexp.ReplaceAllString(path, "."+extension)
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue