본문으로 이동
  • 이 서버는 리버티게임의 개발용 베타 서버로, 게임 플레이 용도로 제작된 사이트가 아닙니다.
  • 리버티게임의 자동 인증된 사용자라면 개발에 필요한 관리자 권한을 신청할 수 있습니다.
  • 틀 및 기능별 소도구를 필요한 문서에만 선택적으로 로딩하는 테스트를 진행하고 있습니다. 작동하지 않는 문서가 있다면 담당자에게 알려주세요.

모듈:한글조합

리버티게임(개발), 모두가 만들어가는 자유로운 게임
백괴게임>Gustmd7410님의 2018년 7월 29일 (일) 03:50 판


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

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


local p = {}

function p.typ(frame)
	local han = mw.text.jsonDecode(frame:expandTemplate{title = '모듈:한글조합/변환'})
	
	local text = frame.args[1]
	local key = frame.args[2]
	
	local last = text:sub(-3)
	local left = text:sub(1, -4)
	
	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.codepoint(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 (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] -- .. 종성
			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