plugins/ietf.lua

changeset 111
a47a1de8993e
parent 110
e5903656c21a
child 114
d11cf84975c5
equal deleted inserted replaced
110:e5903656c21a 111:a47a1de8993e
52 number = ("%04d"):format(number); 52 number = ("%04d"):format(number);
53 debug("search for RFC%s", number); 53 debug("search for RFC%s", number);
54 link, match = self.data:match("\n(" .. number .. ")%s*([^\n]*)"); 54 link, match = self.data:match("\n(" .. number .. ")%s*([^\n]*)");
55 count = 1 55 count = 1
56 else 56 else
57 local pat = string:gsub("[()]", function(s) return "%" .. s end) 57 local pat = string:gsub("[-()%[]", "%%%1")
58 :gsub("[%[]",function(s) return "%" .. s end)
59 :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end) 58 :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end)
60 :gsub("\n+", " "):gsub("\\n", ""); 59 :gsub("\n+", " "):gsub("\\n", "")
60 :gsub("%w", function(s) return '['..s:lower()..s:upper()..']' end)
61 debug("fulltext search for \"%s\"", pat); 61 debug("fulltext search for \"%s\"", pat);
62 --link, match = self.data:match("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)"); 62 --link, match = self.data:match("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)");
63 for l,m in self.data:gmatch("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)") do 63 for l,m in self.data:gmatch("\n(%d%d%d%d) ([^\n]-"..pat.."[^\n]*)") do
64 link, match = l, m 64 link, match = l, m
65 count = count + 1 65 count = count + 1
104 end 104 end
105 end 105 end
106 106
107 function data.draft:_search(string, cb) 107 function data.draft:_search(string, cb)
108 debug("really search for %s", string); 108 debug("really search for %s", string);
109 local pat = string:gsub("[()]", function(s) return "%" .. s end) 109 local pat = string:gsub("[-()%[]", "%%%1")
110 :gsub("[%[]",function(s) return "%" .. s end)
111 :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end) 110 :gsub("%%(%b[])",function(s) return (#s > 2 and "" or "%") .. s end)
112 :gsub("\n+", " "):gsub("\\n", ""); 111 :gsub("\n+", " "):gsub("\\n", "")
112 :gsub("%w", function(s) return '['..s:lower()..s:upper()..']' end)
113 debug("fulltext search for \"%s\"", pat); 113 debug("fulltext search for \"%s\"", pat);
114 local match = self.data:match("\n([^\n]-"..pat.."[^\n]*)") 114 local match = self.data:match("\n([^\n]-"..pat.."[^\n]*)")
115 115
116 if match then 116 if match then
117 debug("match: %s", match); 117 debug("match: %s", match);

mercurial