webmcp

annotate framework/env/format/file_path_element.lua @ 471:a9fea293b2d6

New function format.file_path_element(...)
author jbe
date Thu May 25 02:46:23 2017 +0200 (2017-05-25)
parents
children
rev   line source
jbe@471 1 --[[--
jbe@471 2 text = -- a string
jbe@471 3 format.file_path_element(
jbe@471 4 value, -- part of an encoded file path, see encode.file_path_element(...)
jbe@471 5 options -- options as supported by format.string(...)
jbe@471 6 )
jbe@471 7
jbe@471 8 Undoes the encoding done by encode.file_path_element(...) and additionally formats the resulting string using the options available for format.string(...).
jbe@471 9
jbe@471 10 --]]--
jbe@471 11
jbe@471 12 function format.file_path_element(value, options)
jbe@471 13 local options = options or {}
jbe@471 14 if value == nil then
jbe@471 15 return options.nil_as or ""
jbe@471 16 else
jbe@471 17 return format.string(
jbe@471 18 string.gsub(
jbe@471 19 tostring(value),
jbe@471 20 "%%(%x%x)",
jbe@471 21 function (hexcode)
jbe@471 22 return string.char(tonumber("0x" .. hexcode))
jbe@471 23 end
jbe@471 24 ),
jbe@471 25 options
jbe@471 26 )
jbe@471 27 end
jbe@471 28 end

Impressum / About Us