Module:DPLlua: Difference between revisions

osrsw>CephHunter
No edit summary
osrsw>Habblet
m merge changes from rsw:Module:DPLlua
Line 12: Line 12:
local function split( str, pattern, plain )
local function split( str, pattern, plain )
local res = {}
local res = {}
continue = true
local continue = true
local startIndex = 1
local startIndex = 1


Line 36: Line 36:
local escapeChars = {
local escapeChars = {
['{'] = '{',
['{'] = '{',
['\180'] = '{', -- Wtf dpl...
[''] = '{', -- Wtf dpl...
['}'] = '}',
['}'] = '}',
['\181'] = '}',
[''] = '}',
['\147'] = '–',
['['] = '[',
['['] = '[',
[']'] = ']',
[']'] = ']',
['|'] = '|',
['|'] = '|',
['-'] = '‐',
['-'] = '‐'
['\226'] = '',
['\157'] = '',
['\128'] = ''
}
}
local function escape( str )
local function escape( str )
-- the \226\157\180\181 are used to match ❴ (U+2774) and ❵ (U+2775) wich are 3 bytes long (UTF-8) so
-- the \226\157\180\181 are used to match ❴ (U+2774) and ❵ (U+2775) wich are 3 bytes long (UTF-8) so
-- we can't use them directly inside [] patterns. Ustring would fix this but it's way too slow.
-- we can't use them directly inside [] patterns. Ustring would fix this but it's way too slow.
-- \226\128\147 used to match – (U+2013)
str = string.gsub( str, '[{}%[%]|%-]', escapeChars ):gsub( '\226\157[\180\181]', escapeChars )
str = string.gsub( str, '[{}%[%]|%-\226\157\128\180\181\147]', escapeChars )
return str
return str
end
end
Line 221: Line 216:
query = query:gsub( '<p>Extension:DynamicPageList .-</p>', function(item) res.error = item; return '' end )
query = query:gsub( '<p>Extension:DynamicPageList .-</p>', function(item) res.error = item; return '' end )


if query:match( '^@@' ) then -- @@ is used when no result is found
if query:find( '^@@' ) then -- @@ is used when no result is found
return res
return res
end
end
Line 239: Line 234:


for _, v in ipairs( query ) do
for _, v in ipairs( query ) do
if v:match( '%S' ) then
if v:find( '%S' ) and not v:find( '^@@' ) then
v = trim( v )
v = trim( v )
local title = v:match( '^|%[%[(.-)|' )
local title = v:match( '^|%[%[(.-)|' )
Line 269: Line 264:


if dataItem ~= '' then
if dataItem ~= '' then
dataItem = split( dataItem, '\n%s*§' )
dataItem = split( dataItem:sub( 3 ), '§' ) -- The sub(3) removes the first § at the start. § is 2 bytes wide so start at index 3


for i, item in ipairs( dataItem ) do
for i, item in ipairs( dataItem ) do
if i == 1 then -- First item doesn't start with a \n so it still has § in front of it
item = item:sub( 3 )
end
if item:find( '=' ) then -- Check if the parameter is named or unnamed
if item:find( '=' ) then -- Check if the parameter is named or unnamed
local param, value = item:match( '^%s*(.-)%s*=%s*(.-)%s*$' )
local param, value = item:match( '^%s*(.-)%s*=%s*(.-)%s*$' )