モジュール:サンドボックス/本日晴天/Title with non-BMP

モジュールの解説[作成]
getNonBmp = function(str)
	local nonbmp = {}
	for c in mw.ustring.gcodepoint(str) do
		if c > 0xFFFF then	-- BMP外の文字である
			table.insert(nonbmp, c)
		end
	end
    return nonbmp
end
    
return {
	main = function(frame) 
		local title = mw.title.getCurrentTitle()
		local nonbmp = getNonBmp(title.text)
		if #nonbmp == 0 then	-- BMP外の文字が存在しない
			return frame:expandTemplate{ title="Error", args={ "ページ名に[[基本多言語面]](U+0000からU+FFFFまで)の範囲外にある文字が含まれていません。" } } ..
				frame:expandTemplate{ title="Main other", args={ "[[Category:テンプレート呼び出しエラーのあるページ/Template:Title with non-BMP]]" } }
		end
		if title.namespace ~= 0 then	-- 標準名前空間でない
			return ""	-- 空の文字列を返す
		end
		if title.isRedirect then	-- リダイレクトである
			for i = 1, #nonbmp do
				nonbmp[i] = mw.ustring.format('<span style="font-size:large">「[[wikt:&#x%X;|&#x%X;]]」</span>(U+%X)',
					nonbmp[i], nonbmp[i], nonbmp[i])
			end
			return mw.ustring.format("* [[:Category:Unicode基本多言語面外の文字を含むリダイレクト|Unicode基本多言語面外の文字を含むリダイレクト]]: " ..
					"このリダイレクトのタイトルにはUnicodeの[[基本多言語面]]にない文字%sを含んでいます。" .. 
					"[[Category:Unicode基本多言語面外の文字を含むリダイレクト|+]]",
				table.concat(nonbmp, "、"))
		else	-- リダイレクトでない
			return "[[Category:Unicode基本多言語面外の文字を含むページ名|+]]"
		end
    end
}