Software /
code /
prosody
Diff
util/stanza.lua @ 5431:19d537b5aacc
Merge 0.9->trunk
author | Matthew Wild <mwild1@gmail.com> |
---|---|
date | Fri, 05 Apr 2013 10:05:18 +0100 |
parent | 5424:7318527c6dea |
child | 5435:f56e449a63e3 |
line wrap: on
line diff
--- a/util/stanza.lua Wed Apr 03 13:53:21 2013 +0100 +++ b/util/stanza.lua Fri Apr 05 10:05:18 2013 +0100 @@ -18,6 +18,7 @@ local ipairs = ipairs; local type = type; local s_gsub = string.gsub; +local s_sub = string.sub; local s_find = string.find; local os = os; @@ -174,6 +175,31 @@ return self; end +function stanza_mt:find(path) + local pos = 1; + local len = #path + 1; + + repeat + local xmlns, name, text; + local char = s_sub(path, pos, pos); + if char == "@" then + return self.attr[s_sub(path, pos + 1)]; + elseif char == "{" then + xmlns, pos = s_match(path, "^([^}]+)}()", pos + 1); + end + name, text, pos = s_match(path, "^([^@/#]*)([/#]?)()", pos); + name = name ~= "" and name or nil; + if pos == len then + if text == "#" then + return self:get_child_text(name, xmlns); + end + return self:get_child(name, xmlns); + end + self = self:get_child(name, xmlns); + until not self +end + + local xml_escape do local escape_table = { ["'"] = "'", ["\""] = """, ["<"] = "<", [">"] = ">", ["&"] = "&" };