diff options
author | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2013-04-08 00:43:40 +0000 |
commit | 824f7b0903de8ad7f6ee3d7656005e4c59155e06 (patch) | |
tree | abfc8673ef9916f3ab7074e811207384c301492b /Master/texmf-dist/tex/context/base/syst-aux.lua | |
parent | 689aefb0727676ed3cddf331337b4be226495e72 (diff) |
context import for TL13, from www.pragma-ade.com/context/beta/cont-tmf.zip
git-svn-id: svn://tug.org/texlive/trunk@29731 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/context/base/syst-aux.lua')
-rw-r--r-- | Master/texmf-dist/tex/context/base/syst-aux.lua | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/Master/texmf-dist/tex/context/base/syst-aux.lua b/Master/texmf-dist/tex/context/base/syst-aux.lua index 7fd25d6ab0a..b0fb8483b35 100644 --- a/Master/texmf-dist/tex/context/base/syst-aux.lua +++ b/Master/texmf-dist/tex/context/base/syst-aux.lua @@ -6,19 +6,36 @@ if not modules then modules = { } end modules ['syst-aux'] = { license = "see context related readme files" } +-- slower than lpeg: +-- +-- utfmatch(str,"(.?)(.*)$") +-- utf.sub(str,1,1) + +local commands, context = commands, context + local settings_to_array = utilities.parsers.settings_to_array -local concat = table.concat +local format = string.format +local utfsub = utf.sub +local P, C, Carg, lpegmatch, utf8char = lpeg.P, lpeg.C, lpeg.Carg, lpeg.match, lpeg.patterns.utf8char local setvalue = context.setvalue +local pattern = C(utf8char^-1) * C(P(1)^0) + function commands.getfirstcharacter(str) - local first, rest = utf.match(str,"(.?)(.*)$") + local first, rest = lpegmatch(pattern,str) setvalue("firstcharacter",first) setvalue("remainingcharacters",rest) end +local pattern = C(utf8char^-1) + function commands.doiffirstcharelse(chr,str) - commands.doifelse(utf.sub(str,1,1) == chr) + commands.doifelse(lpegmatch(pattern,str) == chr) +end + +function commands.getsubstring(str,first,last) + context(utfsub(str,tonumber(first),tonumber(last))) end -- function commands.addtocommalist(list,item) @@ -50,3 +67,14 @@ end -- end -- end -- end + +local pattern = (C((1-P("%"))^1) * Carg(1)) /function(n,d) return format("%.0fsp",d * tonumber(n)/100) end * P("%") * P(-1) + +-- commands.percentageof("10%",65536*10) + +function commands.percentageof(str,dim) + context(lpegmatch(pattern,str,1,dim) or str) +end + +-- \gdef\setpercentdimen#1#2% +-- {#1=\ctxcommand{percentageof("#2",\number#1)}\relax} |