Module:Str endswith
Jump to navigation
Jump to search
This module may meet Wikipedia's criteria for speedy deletion because a consensus to delete this page has been reached at a deletion discussion, but it has not yet been deleted. See templates for discussion. See CSD G6.
If this module does not meet the criteria for speedy deletion, please remove this notice. This page was last edited by MSGJ (contribs | logs) at 14:17, 30 May 2019 (UTC) (7 days ago) |
![]() | This Lua module is used on approximately 5,800 pages, so changes to it will be widely noticed. Please test any changes in the module's /sandbox or /testcases subpages. Please consider discussing changes on the talk page before implementing them. |
![]() | This module is subject to page protection. It is a highly visible module in use by a very large number of pages, or is substituted very frequently. Because vandalism or mistakes would affect many pages, and even trivial editing might cause substantial load on the servers, it is protected from editing. |
This module implements {{str endswith}}. Please see the template page for documentation.
The above documentation is transcluded from Module:Str endswith/doc. (edit | history) Editors can experiment in this module's sandbox (edit | diff) and testcases (create) pages. Subpages of this module. |
-- 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