Bearbeiten von „Modul:TemplUtl“
Zur Navigation springen
Zur Suche springen
Die Bearbeitung kann rückgängig gemacht werden. Bitte prüfe den Vergleich unten, um sicherzustellen, dass du dies tun möchtest, und veröffentliche dann unten deine Änderungen, um die Bearbeitung rückgängig zu machen.
Aktuelle Version | Dein Text | ||
Zeile 1: | Zeile 1: | ||
--[=[ 2014-11-24 | |||
TemplUtl | |||
]=] | |||
Zeile 39: | Zeile 10: | ||
-- accept -- string; trimmed title | -- accept -- string; trimmed title | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with pattern | ||
local r; | |||
local start = mw.ustring.sub( accept, 1, 1 ); | local start = mw.ustring.sub( accept, 1, 1 ); | ||
if mw.ustring.match( start, "%a" ) then | if mw.ustring.match( start, "%a" ) then | ||
r = string.format( "[%s%s]%s", | r = string.format( "[%s%s]%s", | ||
Zeile 52: | Zeile 23: | ||
if r:match( " " ) then | if r:match( " " ) then | ||
r = r:gsub( "%", "%%" ) | r = r:gsub( "%", "%%" ) | ||
:gsub( "[ | :gsub( "[^.?+*()$]+", "%$1" ) | ||
:gsub( "_", " " ) | :gsub( "_", " " ) | ||
:gsub( "%s+", "[%s_]+" ); | :gsub( "%s+", "[%s_]+" ); | ||
Zeile 61: | Zeile 32: | ||
local | local TemplUtl = { }; | ||
Zeile 260: | Zeile 41: | ||
-- address -- string; what to inspect, URL presumed | -- address -- string; what to inspect, URL presumed | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns true, if URL beginning | ||
local start, r = address:match( "^%s*((%a*:?)//)" ); | local start, r = address:match( "^%s*((%a*:?)//)" ); | ||
if start then | if start then | ||
Zeile 290: | Zeile 71: | ||
-- after -- true, if only to search for "}}" | -- after -- true, if only to search for "}}" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns | ||
-- -- number; byte position in area | -- -- number; byte position in area | ||
-- -- before "|" or "}}", may be at end | -- -- before "|" or "}}", may be at end | ||
Zeile 427: | Zeile 208: | ||
-- at -- optional number; byte position in area of "{{" | -- at -- optional number; byte position in area of "{{" | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns table | ||
-- [0] template, page, parser function name | |||
-- [0] | |||
local n = 0; | local n = 0; | ||
local j, k, p, r, r2, s, v; | local j, k, p, r, r2, s, v; | ||
Zeile 494: | Zeile 271: | ||
-- ask -- string; parameter name | -- ask -- string; parameter name | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns string with trimmed parameter value, or nil | ||
-- Does not return value if template inside | -- Does not return value if template inside | ||
local r; | local r; | ||
Zeile 525: | Zeile 302: | ||
-- no colon (:) | -- no colon (:) | ||
-- Postcondition: | -- Postcondition: | ||
-- | -- Returns ustring position of "{{" in area, or false | ||
-- Requires: | -- Requires: | ||
-- fiatTitleRegExp() | -- fiatTitleRegExp() | ||
local r, space, start, suffix; | |||
local scan = string.format( "{{%s%s%s", | local scan = string.format( "{{%s%s%s", | ||
"([%w_%s:]*)%s*", | "([%w_%s:]*)%s*", | ||
fiatTitleRegExp( access ), | fiatTitleRegExp( access ), | ||
"%s*([|}<]!?)" ); | "%s*([|}<]!?)" ); | ||
if type( at ) == "number" then | if type( at ) == "number" then | ||
r = at; | r = at; | ||
Zeile 584: | Zeile 361: | ||
return r; | return r; | ||
end -- TemplUtl.find() | end -- TemplUtl.find() | ||
Zeile 734: | Zeile 366: | ||
-- Export | -- Export | ||
local p = { }; | local p = { }; | ||
p.TemplUtl = function () | p.TemplUtl = function () | ||
return TemplUtl; | return TemplUtl; | ||
end | end | ||
return p; | return p; |