Merged in tbasnoopy/premake-dev/extension replace (pull request #148)

add replaceextension function for paths
This commit is contained in:
Jason Perkins 2015-03-29 17:25:44 -04:00
commit 34bf41ea9d
4 changed files with 50 additions and 0 deletions

View File

@ -27,3 +27,4 @@ Since 5.0-alpha1:
* Embedded scripts now compressed with LuaSrcDiet (Oliver Schneider)
* Checks to prevent self-linking (Mark Chandler)
* os.rmdir() can now removes dotted subdirectories (Alexey Orlov)
* Added path.replaceextension() (M Skibbe)

View File

@ -23,6 +23,8 @@ Patch contributors:
* Prevent self-linking
Mihai Sebea <http://twitter.com/mihai_sebea>
* Xcode exporter fixes and improvements
M Skibbe
* path.replaceextension()
Oliver Schneider
* compress embedded scripts with LuaSrcDiet
Renaud Guillard <https://bitbucket.org/noresources>

View File

@ -210,6 +210,27 @@
end
--
-- Replace the file extension.
--
function path.replaceextension(p, newext)
local ext = path.getextension(p)
if not ext then
return p
end
if not newext:findlast(".", true) then
newext = "."..newext
end
return p:match("^(.*)"..ext.."$")..newext
end
--
-- Converts from a simple wildcard syntax, where * is "match any"
-- and ** is "match recursive", to the corresponding Lua pattern.

View File

@ -298,6 +298,32 @@
end
--
-- path.replaceextension() tests
--
function suite.getabsolute_replaceExtension()
test.isequal("/AB.foo", path.replaceextension("/AB.exe","foo"))
end
function suite.getabsolute_replaceExtensionWithDot()
test.isequal("/AB.foo", path.replaceextension("/AB.exe",".foo"))
end
function suite.getabsolute_replaceExtensionWithDotMultipleDots()
test.isequal("/nunit.framework.foo", path.replaceextension("/nunit.framework.dll",".foo"))
end
function suite.getabsolute_replaceExtensionCompletePath()
test.isequal("/nunit/framework/main.foo", path.replaceextension("/nunit/framework/main.cpp",".foo"))
end
function suite.getabsolute_replaceExtensionWithoutExtension()
test.isequal("/nunit/framework/main.foo", path.replaceextension("/nunit/framework/main",".foo"))
end
--
-- path.translate() tests
--