diff options
author | Philipp Gesang <phg42.2a@gmail.com> | 2014-05-31 13:34:55 +0200 |
---|---|---|
committer | Philipp Gesang <phg42.2a@gmail.com> | 2014-05-31 13:34:55 +0200 |
commit | cc8eda7f75260c2e1486248df5c56abffb449f65 (patch) | |
tree | 92e2a9f9e829832c2e9daa3337d485b3f0134099 | |
parent | aeeb88565f5dfe856e22b92d7a76dda382622799 (diff) | |
download | lualibs-cc8eda7f75260c2e1486248df5c56abffb449f65.tar.gz |
sync with Context as of 2014-05-31
-rw-r--r-- | lualibs-util-str.lua | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/lualibs-util-str.lua b/lualibs-util-str.lua index 52c48ba..6f95254 100644 --- a/lualibs-util-str.lua +++ b/lualibs-util-str.lua @@ -284,6 +284,7 @@ end -- octal %...o number -- string %...s string number -- float %...f number +-- checked float %...F number -- exponential %...e number -- exponential %...E number -- autofloat %...g number @@ -524,9 +525,22 @@ local format_f = function(f) return format("format('%%%sf',a%s)",f,n) end -local format_F = function(f) +-- The next one formats an integer as integer and very small values as zero. This is needed +-- for pdf backend code. +-- +-- 1.23 % 1 : 0.23 +-- - 1.23 % 1 : 0.77 +-- +-- We could probably use just %s with integers but who knows what Lua 5.3 will do? So let's +-- for the moment use %i. + +local format_F = function() n = n + 1 - return format("((a%s == 0 and '0') or (a%s == 1 and '1') or format('%%%sf',a%s))",n,n,f,n) + if not f or f == "" then + return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or format((a%s %% 1 == 0) and '%%i' or '%%.9f',a%s))",n,n,n,n) + else + return format("format((a%s %% 1 == 0) and '%%i' or '%%%sf',a%s)",n,f,n) + end end local format_g = function(f) |