Comparison

tools/erlparse.lua @ 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
parent 1572:1b87dfb76caa
child 2923:b7049746bd29
comparison
equal deleted inserted replaced
1782:dd819e5bb0b8 1783:f79972ad8965
43 local function isSpace(ch) 43 local function isSpace(ch)
44 ch = string.byte(ch) or "x"; 44 ch = string.byte(ch) or "x";
45 return ch <= _space; 45 return ch <= _space;
46 end 46 end
47 47
48 local escapes = {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"};
48 local function readString() 49 local function readString()
49 read("\""); -- skip quote 50 read("\""); -- skip quote
50 local slash = nil; 51 local slash = nil;
51 local str = ""; 52 local str = "";
52 while true do 53 while true do
53 local ch = read(); 54 local ch = read();
54 if ch == "\"" and not slash then break; end 55 if slash then
55 str = str..ch; 56 slash = slash..ch;
57 if not escapes[slash] then error("Unknown escape sequence: "..slash); end
58 str = str..escapes[slash];
59 slash = nil;
60 elseif ch == "\"" then
61 break;
62 elseif ch == "\\" then
63 slash = ch;
64 else
65 str = str..ch;
66 end
56 end 67 end
57 str = str:gsub("\\.", {["\\b"]="\b", ["\\d"]="\d", ["\\e"]="\e", ["\\f"]="\f", ["\\n"]="\n", ["\\r"]="\r", ["\\s"]="\s", ["\\t"]="\t", ["\\v"]="\v", ["\\\""]="\"", ["\\'"]="'", ["\\\\"]="\\"});
58 return str; 68 return str;
59 end 69 end
60 local function readAtom1() 70 local function readAtom1()
61 local var = read(); 71 local var = read();
62 while isAtom(peek()) do 72 while isAtom(peek()) do