summaryrefslogtreecommitdiff
path: root/Master/bin/i386-cygwin
diff options
context:
space:
mode:
authorMojca Miklavec <mojca.miklavec@gmail.com>2012-06-08 12:19:55 +0000
committerMojca Miklavec <mojca.miklavec@gmail.com>2012-06-08 12:19:55 +0000
commit7d4d7bd57d826a9576318a3e8f1db50188764566 (patch)
tree2336337a3561087d91ffefa47a4366d3a4cac3a2 /Master/bin/i386-cygwin
parent4809fa94a8d42936d46320477ce193190987f4d4 (diff)
ConTeXt 2012.05.30 11:26
git-svn-id: svn://tug.org/texlive/trunk@26861 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/bin/i386-cygwin')
-rwxr-xr-xMaster/bin/i386-cygwin/mtxrun97
1 files changed, 94 insertions, 3 deletions
diff --git a/Master/bin/i386-cygwin/mtxrun b/Master/bin/i386-cygwin/mtxrun
index d2f7e408f0d..108f2a8a112 100755
--- a/Master/bin/i386-cygwin/mtxrun
+++ b/Master/bin/i386-cygwin/mtxrun
@@ -4087,8 +4087,10 @@ local one = P(1)
local two = C(1) * C(1)
local four = C(R(utfchar(0xD8),utfchar(0xFF))) * C(1) * C(1) * C(1)
+-- actually one of them is already utf ... sort of useless this one
+
local pattern = P("\254\255") * Cs( (
- four / function(a,b,c,d)
+ four / function(a,b,c,d)
local ab = 0xFF * byte(a) + byte(b)
local cd = 0xFF * byte(c) + byte(d)
return utfchar((ab-0xD800)*0x400 + (cd-0xDC00) + 0x10000)
@@ -4099,7 +4101,7 @@ local pattern = P("\254\255") * Cs( (
+ one
)^1 )
+ P("\255\254") * Cs( (
- four / function(b,a,d,c)
+ four / function(b,a,d,c)
local ab = 0xFF * byte(a) + byte(b)
local cd = 0xFF * byte(c) + byte(d)
return utfchar((ab-0xD800)*0x400 + (cd-0xDC00) + 0x10000)
@@ -4114,6 +4116,22 @@ function string.toutf(s)
return lpegmatch(pattern,s) or s -- todo: utf32
end
+local validatedutf = Cs (
+ (
+ patterns.utf8one
+ + patterns.utf8two
+ + patterns.utf8three
+ + patterns.utf8four
+ + P(1) / "�"
+ )^0
+)
+
+patterns.validatedutf = validatedutf
+
+function string.validutf(str)
+ return lpegmatch(validatedutf,str)
+end
+
end -- of closure
@@ -8174,6 +8192,34 @@ function xml.makestandalone(root)
return root
end
+function xml.kind(e)
+ local dt = e and e.dt
+ if dt then
+ local n = #dt
+ if n == 1 then
+ local d = dt[1]
+ if d.special then
+ local tg = d.tg
+ if tg == "@cd@" then
+ return "cdata"
+ elseif tg == "@cm" then
+ return "comment"
+ elseif tg == "@pi@" then
+ return "instruction"
+ elseif tg == "@dt@" then
+ return "declaration"
+ end
+ elseif type(d) == "string" then
+ return "text"
+ end
+ return "element"
+ elseif n > 0 then
+ return "mixed"
+ end
+ end
+ return "empty"
+end
+
end -- of closure
@@ -9601,7 +9647,7 @@ local xmlfilter = xml.filter
local type, setmetatable, getmetatable = type, setmetatable, getmetatable
local insert, remove, fastcopy, concat = table.insert, table.remove, table.fastcopy, table.concat
-local gmatch, gsub, format = string.gmatch, string.gsub, string.format
+local gmatch, gsub, format, find, strip = string.gmatch, string.gsub, string.format, string.find, string.strip
local utfbyte = utf.byte
local function report(what,pattern,c,e)
@@ -10293,6 +10339,51 @@ function xml.setcdata(e,str) -- also setcomment
} }
end
+-- maybe helpers like this will move to an autoloader
+
+function xml.separate(x,pattern)
+ local collected = xmlapplylpath(x,pattern)
+ if collected then
+ for c=1,#collected do
+ local e = collected[c]
+ local d = e.dt
+ if d == x then
+ report_xml("warning: xml.separate changes root")
+ x = d
+ end
+ local t, n = { "\n" }, 1
+ local i, nd = 1, #d
+ while i <= nd do
+ while i <= nd do
+ local di = d[i]
+ if type(di) == "string" then
+ if di == "\n" or find(di,"^%s+$") then -- first test is speedup
+ i = i + 1
+ else
+ d[i] = strip(di)
+ break
+ end
+ else
+ break
+ end
+ end
+ if i > nd then
+ break
+ end
+ t[n+1] = "\n"
+ t[n+2] = d[i]
+ t[n+3] = "\n"
+ n = n + 3
+ i = i + 1
+ end
+ t[n+1] = "\n"
+ setmetatable(t,getmetatable(d))
+ e.dt = t
+ end
+ end
+ return x
+end
+
end -- of closure