From c1496e943b4f73838abbcfa83e07b5ea5e084edb Mon Sep 17 00:00:00 2001 From: NiLuJe Date: Thu, 10 Dec 2020 20:51:21 +0100 Subject: [PATCH] util: Simplify splitFile* util functions * Use a single match call instead of two gsubs --- frontend/util.lua | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/frontend/util.lua b/frontend/util.lua index 27001ec99..42e2e3934 100644 --- a/frontend/util.lua +++ b/frontend/util.lua @@ -810,11 +810,11 @@ end --- If the given path has a trailing /, returns the entire path as the directory --- path and "" as the file name. ---- @string file ----- @treturn string path, filename +---- @treturn string directory, filename function util.splitFilePathName(file) if file == nil or file == "" then return "", "" end if string.find(file, "/") == nil then return "", file end - return string.gsub(file, "(.*/)(.*)", "%1"), string.gsub(file, ".*/", "") + return file:match'(.*/)(.*)' end --- Splits a file name into its pure file name and suffix @@ -823,7 +823,7 @@ end function util.splitFileNameSuffix(file) if file == nil or file == "" then return "", "" end if string.find(file, "%.") == nil then return file, "" end - return string.gsub(file, "(.*)%.(.*)", "%1"), string.gsub(file, ".*%.", "") + return file:match'(.*)%.(.*)' end --- Gets file extension @@ -835,7 +835,7 @@ function util.getFileNameSuffix(file) end --- Companion helper function that returns the script's language, ---- based on the filme extension. +--- based on the file extension. ---- @string filename ---- @treturn string (lowercase) (or nil if not Device:canExecuteScript(file)) function util.getScriptType(file)