Changeset

1783:f79972ad8965

ejabberd2prosody: Fixed escape code processing when parsing strings.
author Waqas Hussain <waqas20@gmail.com>
date Fri, 18 Sep 2009 02:11:16 +0500
parents 1782:dd819e5bb0b8
children 1784:b2bfd3b93da6
files tools/erlparse.lua
diffstat 1 files changed, 13 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/tools/erlparse.lua	Fri Sep 18 00:54:12 2009 +0500
+++ b/tools/erlparse.lua	Fri Sep 18 02:11:16 2009 +0500
@@ -45,16 +45,26 @@
 	return ch <= _space;
 end
 
+local escapes = {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"};
 local function readString()
 	read("\""); -- skip quote
 	local slash = nil;
 	local str = "";
 	while true do
 		local ch = read();
-		if ch == "\"" and not slash then break; end
-		str = str..ch;
+		if slash then
+			slash = slash..ch;
+			if not escapes[slash] then error("Unknown escape sequence: "..slash); end
+			str = str..escapes[slash];
+			slash = nil;
+		elseif ch == "\"" then
+			break;
+		elseif ch == "\\" then
+			slash = ch;
+		else
+			str = str..ch;
+		end
 	end
-	str = str:gsub("\\.", {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"});
 	return str;
 end
 local function readAtom1()