From cc8eda7f75260c2e1486248df5c56abffb449f65 Mon Sep 17 00:00:00 2001 From: Philipp Gesang Date: Sat, 31 May 2014 13:34:55 +0200 Subject: sync with Context as of 2014-05-31 --- lualibs-util-str.lua | 18 ++++++++++++++++-- 1 file 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) -- cgit v1.2.3