add ReplaceExtensions to pathtools

Change-Id: I6dc92323d4b0ef4b0f31076c868802dc568346c4
This commit is contained in:
Erik Gilling 2014-06-16 13:58:57 -07:00 committed by Jamie Gennis
parent e98b8a927d
commit 310794f016

View file

@ -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
}