summaryrefslogtreecommitdiff
path: root/tex/context/base/mkiv/util-str.lua
diff options
context:
space:
mode:
authorHans Hagen <pragma@wxs.nl>2018-06-22 16:42:14 +0200
committerContext Git Mirror Bot <phg42.2a@gmail.com>2018-06-22 16:42:14 +0200
commitda8162d4e816cf49d9790a1c81556b499f442bed (patch)
tree5c631b1fb8282670a6cea1087afa766a8b94db43 /tex/context/base/mkiv/util-str.lua
parent204057fdc5023b5f4ff55a69bc6593388ea427e7 (diff)
downloadcontext-da8162d4e816cf49d9790a1c81556b499f442bed.tar.gz
2018-06-22 16:02:00
Diffstat (limited to 'tex/context/base/mkiv/util-str.lua')
-rw-r--r--tex/context/base/mkiv/util-str.lua13
1 files changed, 12 insertions, 1 deletions
diff --git a/tex/context/base/mkiv/util-str.lua b/tex/context/base/mkiv/util-str.lua
index 5317da423..f575050ff 100644
--- a/tex/context/base/mkiv/util-str.lua
+++ b/tex/context/base/mkiv/util-str.lua
@@ -612,6 +612,7 @@ local sequenced=table.sequenced
local formattednumber=number.formatted
local sparseexponent=number.sparseexponent
local formattedfloat=number.formattedfloat
+local stripper=lpeg.patterns.stripzeros
]]
else
@@ -639,6 +640,7 @@ else
formattednumber = number.formatted,
sparseexponent = number.sparseexponent,
formattedfloat = number.formattedfloat,
+ stripper = lpeg.patterns.stripzeros,
}
end
@@ -907,9 +909,18 @@ local format_n = function() -- strips leading and trailing zeros and removes .0
return format("((a%s %% 1 == 0) and format('%%i',a%s) or tostring(a%s))",n,n,n)
end
+-- local format_N = function() -- strips leading and trailing zeros (also accepts string)
+-- n = n + 1
+-- return format("tostring(tonumber(a%s) or a%s)",n,n)
+-- end
+
local format_N = function() -- strips leading and trailing zeros (also accepts string)
n = n + 1
- return format("tostring(tonumber(a%s) or a%s)",n,n)
+ if not f or f == "" then
+ return format("(((a%s > -0.0000000005 and a%s < 0.0000000005) and '0') or ((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%.9f',a%s)))",n,n,n,n,n)
+ else
+ return format("(((a%s %% 1 == 0) and format('%%i',a%s)) or lpegmatch(stripper,format('%%%sf',a%s)))",n,n,f,n)
+ end
end
local format_a = function(f)