求真百科歡迎當事人提供第一手真實資料,洗刷冤屈,終結網路霸凌。

“模块:Str endswith”的版本间的差异查看源代码查看历史

跳转至: 导航搜索
mediawiki1>Mr. Stradivarius
(Protected "Module:Str endswith": High-risk Lua module ([Edit=Require template editor access] (indefinite) [Move=Require template editor access] (indefinite)))
 
(导入1个版本)
 
(没有差异)

2018年7月18日 (三) 00:34的最新版本

此模块的文档可以在模块:Str endswith/doc创建

-- 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