Änderungen

Wechseln zu: Navigation, Suche

Modul:Str endswith

696 Bytes hinzugefügt, 08:15, 7. Nov. 2016
K
Protected "Module:Str endswith": High-risk Lua module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite))
-- This module implements {{str endswith}}.

local TRUE_STRING = 'yes'
local FALSE_STRING = ''

local p = {}

local function trim(s)
return s:match('^%s*(.-)%s*$')
end

function p.main(frame)
local args = frame:getParent().args
local s = args[1]
local pattern = args[2]
if not s or not pattern then
-- TRUE_STRING is not the natural choice here, but is needed for
-- backwards compatibility.
return TRUE_STRING
end
s = trim(s)
pattern = trim(pattern)
if pattern == '' then
-- All strings end with the empty string.
return TRUE_STRING
end
if mw.ustring.sub(s, 0 - mw.ustring.len(pattern), -1) == pattern then
return TRUE_STRING
else
return FALSE_STRING
end
end

return p
Anonymer Benutzer

Spenden-Adressen:
Bitcoin Icon BTC: 1EoecgUZnAjamUYaKstqwbremQqbucTaoZ
Ethereum Icon ETH: 0x0D2Ab63dfe70a7fA12f9d66eCfEA9dDc8F5173A8
XEM Icon XEM: NBZPMU-XES6ST-ITEBR3-IHAPTR-APGI3Y-RAAMHV-VZFJ
Verge Icon XVG: DGYmzxoe3ryK6MnsR13GqR9r1NThpxPcKs

Navigationsmenü