「モジュール:Str endswith」の版間の差分
ナビゲーションに移動
検索に移動
Iyokanmorigen (トーク | 投稿記録) 細 1版 をインポートしました |
Iyokanmorigen (トーク | 投稿記録) 細 「モジュール:Str endswith」を保護しました ([編集=管理者のみ許可] (無期限) [移動=管理者のみ許可] (無期限)) |
||
(相違点なし)
| |||
2019年2月1日 (金) 04:21時点における最新版
このモジュールについての説明文ページを モジュール: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