모듈:Unicode: 두 판 사이의 차이
보이기
편집 요약 없음 |
편집 요약 없음 |
||
| 6번째 줄: | 6번째 줄: | ||
---@param code string string: U+ABCD | ---@param code string string: U+ABCD | ||
function p.tochar(code) | function p.tochar(code) | ||
return ustring.char(tonumber(code:gsub(" ", ""):gsub("[Uu][+]", "0x"), 16)) | |||
end | end | ||
| 14번째 줄: | 14번째 줄: | ||
---@return string | ---@return string | ||
function p.tounicode(frame) | function p.tounicode(frame) | ||
return 'U+' .. string.format('%x', ustring.codepoint(frame.args[1])):upper() | |||
end | end | ||
------------------------- codepoint ------------------------------------------ | ------------------------- codepoint ------------------------------------------ | ||
---문자 코드를 반환합니다. | ---문자 코드를 반환합니다. | ||
---@param | ---@param char string | ||
---@param base string example) 10 : U+1234, r10 : 1234, 16( | ---@param base string example) 10 : U+1234, r10 : 1234, 16(default) : U+ABCD | ||
---@param offset integer | ---@param offset integer 0(default) | ||
---@return string | ---@return string | ||
function p._code(char, base, offset) | |||
if char == nil then | |||
return 'char is nil' | |||
end | |||
if type(char) ~= 'number' then | |||
return 'char is not a number' | |||
end | |||
if type(offset) ~= 'number' then | |||
return 'offset is not a number' | |||
end | |||
base = base or '16' | |||
local codepoint = ustring.codepoint(char) + (offset or 0) | |||
if base == 'r10' then | |||
return codepoint | |||
end | |||
local head = 'U+' | |||
local baseformat = { | |||
['10'] = "%d", | |||
['16'] = "%x" | |||
} | |||
return head .. ustring.format(baseformat[base], codepoint):upper() | |||
end | |||
function p.code(data, base, offset) | function p.code(data, base, offset) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char = getArgs(data)[1] or nil | |||
return p._code(char, base, offset) | |||
end | end | ||
---------------------- next codepoint --------------------------------------- | ---------------------- next codepoint --------------------------------------- | ||
--- | --- | ||
| 54번째 줄: | 68번째 줄: | ||
---@return string | ---@return string | ||
function p.nextcode(data) | function p.nextcode(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
if type(data) == 'table' then | |||
char = getArgs(data)[1] or nil | |||
else | |||
char = data or nil | |||
end | |||
if char then | |||
return p._code(char, '16', 1) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
---------------------- prev codepoint --------------------------------------- | ---------------------- prev codepoint --------------------------------------- | ||
--- | --- | ||
| 73번째 줄: | 88번째 줄: | ||
---@return string | ---@return string | ||
function p.prevcode(data) | function p.prevcode(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
if type(data) == 'table' then | |||
char = getArgs(data)[1] or nil | |||
else | |||
char = data or nil | |||
end | |||
if char then | |||
return p._code(char, '16', -1) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
---------------------- next char --------------------------------------- | ---------------------- next char --------------------------------------- | ||
--- | --- | ||
| 92번째 줄: | 108번째 줄: | ||
---@return string nextchar | ---@return string nextchar | ||
function p.nextchar(data) | function p.nextchar(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
if type(data) == 'table' then | |||
char = getArgs(data)[1] or nil | |||
else | |||
char = data or nil | |||
end | |||
if char then | |||
return ustring.char(p._code(char, 'r10', 1)) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
---------------------- prev char --------------------------------------- | ---------------------- prev char --------------------------------------- | ||
--- | --- | ||
| 111번째 줄: | 128번째 줄: | ||
---@return string prevchar | ---@return string prevchar | ||
function p.prevchar(data) | function p.prevchar(data) | ||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
local char | |||
if type(data) == 'table' then | |||
char = getArgs(data)[1] or nil | |||
else | |||
char = data or nil | |||
end | |||
if char then | |||
return ustring.char(p._code(char, 'r10', -1)) | |||
else | |||
return '입력값이 없습니다.' | |||
end | |||
end | end | ||
---------------------- {{유니코드문자}} -------------------------- | ---------------------- {{유니코드문자}} -------------------------- | ||
---@param frame table | ---@param frame table | ||
---@return string | ---@return string | ||
function p. | function p.uni_char(frame) | ||
local unicodeBlock = require('Module:UnicodeBlock').unicodeBlock | |||
local _buildlink = require('Module:linkwithtemplate').makelink | |||
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리 | |||
---@type table | |||
local args = getArgs(frame) | |||
local class = (args['class'] == 'x') and '' or (args['class'] or 'infobox') | |||
local char_current = args[1] or args['기호'] or args['문자'] or nil | |||
local char_name = args['이름'] or mw.title.getCurrentTitle().prefixedText | |||
local eng_name = args['영어이름'] or unicodeBlock(char_current) | |||
local locale = args['lang'] or 'ko' | |||
local prefix = args['경로'] or '' | |||
local prev_arrow_icon = '<i class="fas fa-chevron-left uni_char-arrow"></i></span>' | |||
local prev_char = args['이전'] or args['전문자']; | |||
local prev_linkname = args['전문자이름'] or args['이전이름'] or prev_char | |||
local next_arrow_icon = '<i class="fas fa-chevron-right uni_char-arrow"></i></span>' | |||
local | local next_char = args['이후'] or args['후문자']; | ||
local next_linkname = args['후문자이름'] or args['이후이름'] or next_char | |||
local template = args['템플릿'] | |||
local editintro = args['editintro'] | |||
local prev_link, next_link | |||
local htmlroot = mw.html.create('table') | |||
:addClass(class) | |||
:addClass('uni_char') | |||
:cssText('margin: 0 auto; float: right; text-align: center; clear:right') | |||
local header | |||
if char_name == '없음' then | |||
header = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>', eng_name) | |||
else | |||
header = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>', char_name, eng_name) | |||
end | |||
local function buildlink(article, linkname, arrow, preload, editintro) | |||
if preload then | if preload then | ||
return | return _buildlink(article, string.format('<div>%s<br>%s</div>', linkname, arrow), preload, editintro) | ||
else | else | ||
return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '') | return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '') | ||
end | end | ||
end | end | ||
if char_current == nil then | |||
return '<span class="warning">기호 인수가 없습니다.</span>' | |||
else | else | ||
if | if char_current:find("[Uu]") then | ||
char_current = p.tochar(char_current) | |||
end | end | ||
--------------------- 이전 문자 | --------------------- 이전 문자 | ||
if prev_char then | |||
prev_link = buildlink(prev_char, prev_linkname, prev_arrow_icon, template, editintro) | |||
--- 이전 문자 없으면 자동 계산 | |||
else | |||
local char = ustring.char(p._code(char_current, 'r10', -1)) | |||
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', -1) or char) | |||
prev_link = buildlink(article, prev_linkname or char, prev_arrow_icon, template, editintro) | |||
end | |||
------------------- 다음 문자 | ------------------- 다음 문자 | ||
if next_char then | |||
next_link = buildlink(next_char, next_linkname, next_arrow_icon, template, editintro) | |||
--- 이전 문자 없으면 자동 계산 | |||
else | |||
local char = ustring.char(p._code(char_current, 'r10', 1)) | |||
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', 1) or char) | |||
next_link = buildlink(article, next_linkname or char, next_arrow_icon, template, editintro) | |||
end | |||
end | |||
local t = {} | |||
local format = | |||
[[<td class='uni_char-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td> | |||
<td class='uni_char-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div> | |||
[[<td class=' | |||
<td class=' | |||
<div style="font-size:80%%; color: gray; ">%s</div></td> | <div style="font-size:80%%; color: gray; ">%s</div></td> | ||
<td class=' | <td class='uni_char-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]] | ||
if args['순서반전'] then | |||
header = ustring.format(format .. "%s", locale, prev_link, locale, char_current, p._code(char_current), locale, | |||
next_link, header) | |||
else | |||
header = ustring.format("%s" .. format, header, locale, prev_link, locale, char_current, p._code(char_current), | |||
locale, next_link) | |||
end | |||
return tostring(htmlroot:node(header)) | |||
end | end | ||
return p | return p | ||
2025년 1월 30일 (목) 19:40 판
{{#css: .template-documentation {
clear: both; margin: 1em 0 0 0; padding: 1em
} /* 아래 상자 */ .mbox-text {
clear: both; background-color: #e8ffe8;
}
.template-documentation-template-data .mw-templatedata-doc-desc {
display: none;
}
}}
모듈:Unicode을 이용합니다.
Lua 오류: bad argument #1 to 'char' (number expected, got string).
{{유니코드문자|[}}
Lua 오류: bad argument #1 to 'char' (number expected, got string).
{{유니코드문자|이름=왼쪽 대괄호|[}}
아래는 가능한 모든 변수들을 나열한 것입니다.
왼쪽 대괄호 Left Square Bracket | ||
|---|---|---|
Z |
[
char is not a number |
역슬래시 |
위 설명은 모듈:Unicode/설명문서의 내용을 가져와 보여주고 있습니다.
연습장이나 사용자 문서에서 틀의 사용이나 수정을 연습할 수 있습니다.
local mw = mw
local ustring = mw.ustring
local p = {}
------------------------- code to char ------------------------------------------
---@param code string string: U+ABCD
function p.tochar(code)
return ustring.char(tonumber(code:gsub(" ", ""):gsub("[Uu][+]", "0x"), 16))
end
------------------------- codepoint (frame) ------------------------------------------
---return 'U+ABCD'
---@param frame table
---@return string
function p.tounicode(frame)
return 'U+' .. string.format('%x', ustring.codepoint(frame.args[1])):upper()
end
------------------------- codepoint ------------------------------------------
---문자 코드를 반환합니다.
---@param char string
---@param base string example) 10 : U+1234, r10 : 1234, 16(default) : U+ABCD
---@param offset integer 0(default)
---@return string
function p._code(char, base, offset)
if char == nil then
return 'char is nil'
end
if type(char) ~= 'number' then
return 'char is not a number'
end
if type(offset) ~= 'number' then
return 'offset is not a number'
end
base = base or '16'
local codepoint = ustring.codepoint(char) + (offset or 0)
if base == 'r10' then
return codepoint
end
local head = 'U+'
local baseformat = {
['10'] = "%d",
['16'] = "%x"
}
return head .. ustring.format(baseformat[base], codepoint):upper()
end
function p.code(data, base, offset)
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local char = getArgs(data)[1] or nil
return p._code(char, base, offset)
end
---------------------- next codepoint ---------------------------------------
---
---입력된 문자의 이후 문자 코드 반환
---@param data table | string table : frame, string : char
---@return string
function p.nextcode(data)
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local char
if type(data) == 'table' then
char = getArgs(data)[1] or nil
else
char = data or nil
end
if char then
return p._code(char, '16', 1)
else
return '입력값이 없습니다.'
end
end
---------------------- prev codepoint ---------------------------------------
---
---입력된 문자의 이전 문자 코드 반환
---@param data table | string table : frame, string : char
---@return string
function p.prevcode(data)
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local char
if type(data) == 'table' then
char = getArgs(data)[1] or nil
else
char = data or nil
end
if char then
return p._code(char, '16', -1)
else
return '입력값이 없습니다.'
end
end
---------------------- next char ---------------------------------------
---
---입력된 문자의 이후 문자 반환
---@param data table | string table : frame, string : char
---@return string nextchar
function p.nextchar(data)
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local char
if type(data) == 'table' then
char = getArgs(data)[1] or nil
else
char = data or nil
end
if char then
return ustring.char(p._code(char, 'r10', 1))
else
return '입력값이 없습니다.'
end
end
---------------------- prev char ---------------------------------------
---
---입력된 문자의 이전 문자 반환
---@param data table | string table : frame, string : char
---@return string prevchar
function p.prevchar(data)
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
local char
if type(data) == 'table' then
char = getArgs(data)[1] or nil
else
char = data or nil
end
if char then
return ustring.char(p._code(char, 'r10', -1))
else
return '입력값이 없습니다.'
end
end
---------------------- {{유니코드문자}} --------------------------
---@param frame table
---@return string
function p.uni_char(frame)
local unicodeBlock = require('Module:UnicodeBlock').unicodeBlock
local _buildlink = require('Module:linkwithtemplate').makelink
local getArgs = require('Module:Arguments').getArgs --- frame 인수 처리
---@type table
local args = getArgs(frame)
local class = (args['class'] == 'x') and '' or (args['class'] or 'infobox')
local char_current = args[1] or args['기호'] or args['문자'] or nil
local char_name = args['이름'] or mw.title.getCurrentTitle().prefixedText
local eng_name = args['영어이름'] or unicodeBlock(char_current)
local locale = args['lang'] or 'ko'
local prefix = args['경로'] or ''
local prev_arrow_icon = '<i class="fas fa-chevron-left uni_char-arrow"></i></span>'
local prev_char = args['이전'] or args['전문자'];
local prev_linkname = args['전문자이름'] or args['이전이름'] or prev_char
local next_arrow_icon = '<i class="fas fa-chevron-right uni_char-arrow"></i></span>'
local next_char = args['이후'] or args['후문자'];
local next_linkname = args['후문자이름'] or args['이후이름'] or next_char
local template = args['템플릿']
local editintro = args['editintro']
local prev_link, next_link
local htmlroot = mw.html.create('table')
:addClass(class)
:addClass('uni_char')
:cssText('margin: 0 auto; float: right; text-align: center; clear:right')
local header
if char_name == '없음' then
header = ustring.format('<tr><th colspan="3"><small>%s</small></th></tr>', eng_name)
else
header = ustring.format('<tr><th colspan="3"><div>%s</div><small>%s</small></th></tr>', char_name, eng_name)
end
local function buildlink(article, linkname, arrow, preload, editintro)
if preload then
return _buildlink(article, string.format('<div>%s<br>%s</div>', linkname, arrow), preload, editintro)
else
return ustring.format('[[%s|<div>%s<br>%s</div>]]', article, linkname, arrow or '')
end
end
if char_current == nil then
return '<span class="warning">기호 인수가 없습니다.</span>'
else
if char_current:find("[Uu]") then
char_current = p.tochar(char_current)
end
--------------------- 이전 문자
if prev_char then
prev_link = buildlink(prev_char, prev_linkname, prev_arrow_icon, template, editintro)
--- 이전 문자 없으면 자동 계산
else
local char = ustring.char(p._code(char_current, 'r10', -1))
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', -1) or char)
prev_link = buildlink(article, prev_linkname or char, prev_arrow_icon, template, editintro)
end
------------------- 다음 문자
if next_char then
next_link = buildlink(next_char, next_linkname, next_arrow_icon, template, editintro)
--- 이전 문자 없으면 자동 계산
else
local char = ustring.char(p._code(char_current, 'r10', 1))
local article = prefix .. (ustring.codepoint(char) > 65535 and p._code(char_current, '16', 1) or char)
next_link = buildlink(article, next_linkname or char, next_arrow_icon, template, editintro)
end
end
local t = {}
local format =
[[<td class='uni_char-prev' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>
<td class='uni_char-char' style="width: 6em"><div style="font-size: 1.8em;line-height: 1.4em;"><b lang="%s">%s</b></div>
<div style="font-size:80%%; color: gray; ">%s</div></td>
<td class='uni_char-next' style="width: 7em;font-size:1.2em;" lang="%s">%s</td>]]
if args['순서반전'] then
header = ustring.format(format .. "%s", locale, prev_link, locale, char_current, p._code(char_current), locale,
next_link, header)
else
header = ustring.format("%s" .. format, header, locale, prev_link, locale, char_current, p._code(char_current),
locale, next_link)
end
return tostring(htmlroot:node(header))
end
return p