# HG changeset patch # User jbe # Date 1495673183 -7200 # Node ID a9fea293b2d6830174108d29b0eddc86eb88eba3 # Parent ddab87fc05c33004de78a80dda9418ab966a3cd9 New function format.file_path_element(...) diff -r ddab87fc05c3 -r a9fea293b2d6 framework/env/format/file_path_element.lua --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/framework/env/format/file_path_element.lua Thu May 25 02:46:23 2017 +0200 @@ -0,0 +1,28 @@ +--[[-- +text = -- a string +format.file_path_element( + value, -- part of an encoded file path, see encode.file_path_element(...) + options -- options as supported by format.string(...) +) + +Undoes the encoding done by encode.file_path_element(...) and additionally formats the resulting string using the options available for format.string(...). + +--]]-- + +function format.file_path_element(value, options) + local options = options or {} + if value == nil then + return options.nil_as or "" + else + return format.string( + string.gsub( + tostring(value), + "%%(%x%x)", + function (hexcode) + return string.char(tonumber("0x" .. hexcode)) + end + ), + options + ) + end +end diff -r ddab87fc05c3 -r a9fea293b2d6 framework/env/format/string.lua --- a/framework/env/format/string.lua Wed May 24 20:45:51 2017 +0200 +++ b/framework/env/format/string.lua Thu May 25 02:46:23 2017 +0200 @@ -1,5 +1,5 @@ --[[-- -text = -- a string +text = -- a string format.string( value, -- any value where tostring(value) gives a reasonable result {