モジュール:Split

提供:Wikisource
モジュールの解説[作成]
local p = {}

function p.main( frame )
	local args = require( 'Module:Arguments' ).getArgs( frame, { wrappers = 'Template:Split', removeBlanks = false } )
	local text = args[1] or ''
		if text == '' then
			text = frame:preprocess( '{{FULLPAGENAME}}' )
		end
	local split_text = args[2] or ''
		if split_text == '' then
			return frame:preprocess( '{{error|エラー:分断指定する文字列を入力して下さい。}}' )
		end
	local type = args[3] or args.type or ''
		if type == '' then
			type = 'left'
		end

	local split = mw.text.split( text, split_text )

	if type == 'right' then
		return split[2]
	else
		return split[1]
	end
end

return p