Module:DPLlua: Difference between revisionsGive feedback
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 = { | ||
['{'] = '{', | ['{'] = '{', | ||
[' | ['❴'] = '{', -- Wtf dpl... | ||
['}'] = '}', | ['}'] = '}', | ||
[' | ['❵'] = '}', | ||
['['] = '[', | ['['] = '[', | ||
[']'] = ']', | [']'] = ']', | ||
['|'] = '|', | ['|'] = '|', | ||
['-'] = '‐ | ['-'] = '‐' | ||
} | } | ||
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. | ||
str = string.gsub( str, '[{}%[%]|%-]', escapeChars ):gsub( '\226\157[\180\181]', escapeChars ) | |||
str = string.gsub( str, '[{}%[%]|%-\226\157 | |||
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: | 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: | 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, ' | 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 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*$' ) | ||