From 310794f016497bd55c0186179970073ecc5b4b23 Mon Sep 17 00:00:00 2001 From: Erik Gilling Date: Mon, 16 Jun 2014 13:58:57 -0700 Subject: [PATCH] add ReplaceExtensions to pathtools Change-Id: I6dc92323d4b0ef4b0f31076c868802dc568346c4 --- blueprint/pathtools/lists.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/blueprint/pathtools/lists.go b/blueprint/pathtools/lists.go index 486678d..3742cf8 100644 --- a/blueprint/pathtools/lists.go +++ b/blueprint/pathtools/lists.go @@ -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 +}