Skip to content

Commit 4a65186

Browse files
committed
"Better" XML parsing for the very sad Penlight, and now I'm sad. We're all sad. People, don't use XML files for anything ever. Just don't...
1 parent 9763e3e commit 4a65186

File tree

7 files changed

+104
-0
lines changed

7 files changed

+104
-0
lines changed

bin/libexpat.dll

144 KB
Binary file not shown.

bin/lxp-license.txt

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
Copyright � 2003-2007 The Kepler Project.
2+
3+
Permission is hereby granted, free of charge, to any person obtaining a copy
4+
of this software and associated documentation files (the "Software"), to deal
5+
in the Software without restriction, including without limitation the rights
6+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7+
copies of the Software, and to permit persons to whom the Software is
8+
furnished to do so, subject to the following conditions:
9+
10+
The above copyright notice and this permission notice shall be included in all
11+
copies or substantial portions of the Software.
12+
13+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19+
SOFTWARE.

bin/lxp.dll

100 KB
Binary file not shown.

bin/md5/core.dll

10.5 KB
Binary file not shown.

lib/lxp/lom.lua

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
-- See Copyright Notice in license.html
2+
-- $Id: lom.lua,v 1.6 2005/06/09 19:18:40 tuler Exp $
3+
4+
require "lxp"
5+
6+
local tinsert, tremove, getn = table.insert, table.remove, table.getn
7+
local assert, type, print = assert, type, print
8+
local lxp = lxp
9+
10+
module ("lxp.lom")
11+
12+
local function starttag (p, tag, attr)
13+
local stack = p:getcallbacks().stack
14+
local newelement = {tag = tag, attr = attr}
15+
tinsert(stack, newelement)
16+
end
17+
18+
local function endtag (p, tag)
19+
local stack = p:getcallbacks().stack
20+
local element = tremove(stack)
21+
assert(element.tag == tag)
22+
local level = getn(stack)
23+
tinsert(stack[level], element)
24+
end
25+
26+
local function text (p, txt)
27+
local stack = p:getcallbacks().stack
28+
local element = stack[getn(stack)]
29+
local n = getn(element)
30+
if type(element[n]) == "string" then
31+
element[n] = element[n] .. txt
32+
else
33+
tinsert(element, txt)
34+
end
35+
end
36+
37+
function parse (o)
38+
local c = { StartElement = starttag,
39+
EndElement = endtag,
40+
CharacterData = text,
41+
_nonstrict = true,
42+
stack = {{}}
43+
}
44+
local p = lxp.new(c)
45+
local status, err
46+
if type(o) == "string" then
47+
status, err = p:parse(o)
48+
if not status then return nil, err end
49+
else
50+
for l in o do
51+
status, err = p:parse(l)
52+
if not status then return nil, err end
53+
end
54+
end
55+
status, err = p:parse()
56+
if not status then return nil, err end
57+
p:close()
58+
return c.stack[1][1]
59+
end
60+

lib/md5.lua

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
----------------------------------------------------------------------------
2+
-- $Id: md5.lua,v 1.4 2006/08/21 19:24:21 carregal Exp $
3+
----------------------------------------------------------------------------
4+
5+
local core = require"md5.core"
6+
local string = require"string"
7+
8+
module ("md5")
9+
10+
----------------------------------------------------------------------------
11+
-- @param k String with original message.
12+
-- @return String with the md5 hash value converted to hexadecimal digits
13+
14+
function sumhexa (k)
15+
k = core.sum(k)
16+
return (string.gsub(k, ".", function (c)
17+
return string.format("%02x", string.byte(c))
18+
end))
19+
end

src/main.lua2p

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,12 @@ require"functions"
2929
io.stdout:setvbuf("no")
3030
io.stderr:setvbuf("no")
3131

32+
!if DEV and 1==0 then
33+
-- Test XML parsing.
34+
print(xmlLib.parse('<?xml version="1.0" encoding="UTF-8"?>\n<xml>foo<![CDATA[bar]]></xml>', false))
35+
os.exit(2)
36+
!end
37+
3238
local ok, err = xpcall(
3339
function()
3440
require"app"

0 commit comments

Comments
 (0)