You can edit almost every page by Creating an account and confirming your email.

Module:Str endswith/sandbox

From EverybodyWiki Bios & Wiki

Documentation for this module may be created at Module:Str endswith/sandbox/doc

-- This module implements {{str endswith}}.

local TRUE_STRING = 'yes'
local FALSE_STRING = ''

local p = {}

local function normalizeString(s)
	-- Convert a UTF-8 string into a form appropriate for equality testing
	s = mw.text.trim(s)
	return mw.ustring.toNFD(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 = normalizeString(s)
	pattern = normalizeString(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