모듈:한글조합

리버티게임, 모두가 만들어가는 자유로운 게임


모듈 설명문서[보기] [편집] [역사] [새로 고침]

틀:한글입력기틀:입력기를 위한 윤희코드 한글 조합 모듈입니다.


local p = {}

function p.typ(frame)
	local han = mw.loadJsonData('모듈:한글조합/변환') -- {{모듈:한글조합/변환}}
	
	local text = mw.ustring.toNFD(frame.args[1])
	local key = frame.args[2]
	
	local last = mw.ustring.isutf8(text:sub(-1)) and text:sub(-1) or text:sub(-3)
	local left = text:sub(1, -#last - 1)
	
	local keycode = mw.ustring.codepoint(key)
	local lastcode = mw.ustring.codepoint(last, 3) or mw.ustring.codepoint(last, 2) or mw.ustring.codepoint(last, 1)
	
	local reallast = last ~= '' and mw.ustring.char(lastcode)
	
	if (last ~= '') then
		if (0x3131 <= lastcode and lastcode <= 0x314E) then -- 자음
			if (0x314F <= keycode and keycode <= 0x3163) then -- 모음
				return left .. han.letter.cho[last] .. han.letter.jung[key] -- 초성 .. 중성
			else return text .. key end
		elseif (0x1100 <= lastcode and lastcode <= 0x1112) then -- 초성
			if (0x314F <= keycode and keycode <= 0x3163) then -- 모음
				return text .. han.letter.jung[key] -- .. 중성
			else return text .. key end
		elseif (0x1161 <= lastcode and lastcode <= 0x1175) then -- 중성
			if (0x314F <= keycode and keycode <= 0x3163) then -- 모음
				return left .. (han.letter.jung[reallast .. key] or last .. key) -- 중성 or 중성 .. 모음
			elseif (0x3131 <= keycode and keycode <= 0x314E) then -- 자음
				return text .. (han.letter.jong[key] or key) -- .. 종성 or 자음
			else return text .. key end
		elseif (0x11A8 <= lastcode and lastcode <= 0x11C2) then -- 종성
			if (0x3131 <= keycode and keycode <= 0x314E) then -- 자음
				return left .. (han.letter.jong[reallast .. key] or last .. key) -- 종성 or 종성 .. 초성
			elseif (0x314F <= keycode and keycode <= 0x3163) then -- 모음
				return left .. han.jong.cho[reallast] .. han.letter.jung[key] -- (종성 .. 초성) .. 중성
			else return text .. key end
		else return text .. key end
	else return text .. key end
end

return p