Software / code / prosody
Comparison
util/format.lua @ 9656:3da6cc927ee6
util.format: Tweak how nil values are handled
Because [<nil>] seems exsessive
| author | Kim Alvefur <zash@zash.se> |
|---|---|
| date | Wed, 28 Nov 2018 20:36:53 +0100 |
| parent | 8417:e88db5668cfb |
| child | 9687:8c92ef4270c9 |
comparison
equal
deleted
inserted
replaced
| 9654:ede4e15a0fed | 9656:3da6cc927ee6 |
|---|---|
| 26 local i = 0; | 26 local i = 0; |
| 27 formatstring = formatstring:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec) | 27 formatstring = formatstring:gsub("%%[^cdiouxXaAeEfgGqs%%]*[cdiouxXaAeEfgGqs%%]", function(spec) |
| 28 if spec ~= "%%" then | 28 if spec ~= "%%" then |
| 29 i = i + 1; | 29 i = i + 1; |
| 30 local arg = args[i]; | 30 local arg = args[i]; |
| 31 if arg == nil then -- special handling for nil | |
| 32 arg = "<nil>" | |
| 33 args[i] = "<nil>"; | |
| 34 end | |
| 35 | 31 |
| 36 local option = spec:sub(-1); | 32 local option = spec:sub(-1); |
| 37 if option == "q" or option == "s" then -- arg should be string | 33 if arg == nil then |
| 34 args[i] = "nil"; | |
| 35 spec = "<%s>"; | |
| 36 elseif option == "q" or option == "s" then -- arg should be string | |
| 38 args[i] = tostring(arg); | 37 args[i] = tostring(arg); |
| 39 elseif type(arg) ~= "number" then -- arg isn't number as expected? | 38 elseif type(arg) ~= "number" then -- arg isn't number as expected? |
| 40 args[i] = tostring(arg); | 39 args[i] = tostring(arg); |
| 41 spec = "[%s]"; | 40 spec = "[%s]"; |
| 42 end | 41 end |