webmcp
changeset 471:a9fea293b2d6
New function format.file_path_element(...)
author | jbe |
---|---|
date | Thu May 25 02:46:23 2017 +0200 (2017-05-25) |
parents | ddab87fc05c3 |
children | 07e7e218d8df a2ff42a66212 |
files | framework/env/format/file_path_element.lua framework/env/format/string.lua |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/framework/env/format/file_path_element.lua Thu May 25 02:46:23 2017 +0200 1.3 @@ -0,0 +1,28 @@ 1.4 +--[[-- 1.5 +text = -- a string 1.6 +format.file_path_element( 1.7 + value, -- part of an encoded file path, see encode.file_path_element(...) 1.8 + options -- options as supported by format.string(...) 1.9 +) 1.10 + 1.11 +Undoes the encoding done by encode.file_path_element(...) and additionally formats the resulting string using the options available for format.string(...). 1.12 + 1.13 +--]]-- 1.14 + 1.15 +function format.file_path_element(value, options) 1.16 + local options = options or {} 1.17 + if value == nil then 1.18 + return options.nil_as or "" 1.19 + else 1.20 + return format.string( 1.21 + string.gsub( 1.22 + tostring(value), 1.23 + "%%(%x%x)", 1.24 + function (hexcode) 1.25 + return string.char(tonumber("0x" .. hexcode)) 1.26 + end 1.27 + ), 1.28 + options 1.29 + ) 1.30 + end 1.31 +end
2.1 --- a/framework/env/format/string.lua Wed May 24 20:45:51 2017 +0200 2.2 +++ b/framework/env/format/string.lua Thu May 25 02:46:23 2017 +0200 2.3 @@ -1,5 +1,5 @@ 2.4 --[[-- 2.5 -text = -- a string 2.6 +text = -- a string 2.7 format.string( 2.8 value, -- any value where tostring(value) gives a reasonable result 2.9 {