Changeset

2463:d9ff0190eb4a

xmlhandlers: Define ns_separator and ns_pattern to save repeating it in literal form throughout the file
author Matthew Wild <mwild1@gmail.com>
date Mon, 18 Jan 2010 19:00:18 +0000
parents 2462:2d81cc25b5a6
children 2464:0b5f0ae7a6b1
files core/xmlhandlers.lua
diffstat 1 files changed, 5 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/core/xmlhandlers.lua	Mon Jan 18 18:20:03 2010 +0000
+++ b/core/xmlhandlers.lua	Mon Jan 18 19:00:18 2010 +0000
@@ -26,6 +26,8 @@
 local ns_prefixes = {
 						["http://www.w3.org/XML/1998/namespace"] = "xml";
 				}
+local ns_separator = "\1";
+local ns_pattern = "^([^"..ns_separator.."]*)"..ns_separator.."?(.*)$";
 
 function init_xmlhandlers(session, stream_callbacks)
 		local ns_stack = { "" };
@@ -49,7 +51,7 @@
 				stanza:text(t_concat(chardata));
 				chardata = {};
 			end
-			local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$");
+			local curr_ns,name = tagname:match(ns_pattern);
 			if name == "" then
 				curr_ns, name = "", curr_ns;
 			end
@@ -62,7 +64,7 @@
 			for i=1,#attr do
 				local k = attr[i];
 				attr[i] = nil;
-				local ns, nm = k:match("^([^\1]*)\1?(.*)$");
+				local ns, nm = k:match(ns_pattern);
 				if nm ~= "" then
 					ns = ns_prefixes[ns]; 
 					if ns then 
@@ -104,7 +106,7 @@
 			end
 		end
 		function xml_handlers:EndElement(tagname)
-			local curr_ns,name = tagname:match("^([^\1]*)\1?(.*)$");
+			local curr_ns,name = tagname:match(ns_pattern);
 			if name == "" then
 				curr_ns, name = "", curr_ns;
 			end