편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
1번째 줄: | 1번째 줄: | ||
local getArgs = require('Module:Arguments').getArgs | local getArgs = require('Module:Arguments').getArgs | ||
local args = getArgs(frame) | |||
local ustring = mw.ustring | local ustring = mw.ustring | ||
12번째 줄: | 13번째 줄: | ||
-- string.sub | -- string.sub | ||
function str.sub( frame ) | function str.sub( frame ) | ||
local new_args = str._getParameters( frame.args, { 's', 'i', 'j' } ) | |||
local new_args = str._getParameters( args, { 's', 'i', 'j' } ) | |||
local s = new_args['s'] or '' | local s = new_args['s'] or '' | ||
local i = tonumber( new_args['i'] ) or 1 | local i = tonumber( new_args['i'] ) or 1 | ||
102번째 줄: | 102번째 줄: | ||
-- string.match | -- string.match | ||
function str.match( frame ) | function str.match( frame ) | ||
local new_args = str._getParameters( frame.args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} ) | |||
local new_args = str._getParameters( args, {'s', 'pattern', 'start', 'match', 'plain', 'nomatch'} ) | |||
local s = new_args['s'] or '' | local s = new_args['s'] or '' | ||
local start = tonumber( new_args['start'] ) or 1 | local start = tonumber( new_args['start'] ) or 1 | ||
116번째 줄: | 115번째 줄: | ||
-- | -- | ||
function str.pos( frame ) | function str.pos( frame ) | ||
local new_args = str._getParameters( frame.args, {'target', 'pos'} ) | |||
local new_args = str._getParameters( args, {'target', 'pos'} ) | |||
local target_str = new_args['target'] or '' | local target_str = new_args['target'] or '' | ||
local pos = tonumber( new_args['pos'] ) or 0 | local pos = tonumber( new_args['pos'] ) or 0 | ||
130번째 줄: | 128번째 줄: | ||
-- string.find | -- string.find | ||
function str.find( frame ) | function str.find( frame ) | ||
local new_args = str._getParameters( frame.args, {'source', 'target', 'start', 'plain' } ) | |||
local new_args = str._getParameters( args, {'source', 'target', 'start', 'plain' } ) | |||
local source_str = new_args['source'] or '' | local source_str = new_args['source'] or '' | ||
local pattern = new_args['target'] or '' | local pattern = new_args['target'] or '' | ||
local start_pos = tonumber(new_args['start']) or 1 | local start_pos = tonumber(new_args['start']) or 1 | ||
local plain = new_args['plain'] or | local plain = new_args['plain'] or true | ||
if source_str == '' or pattern == '' then | if source_str == '' or pattern == '' then | ||
144번째 줄: | 141번째 줄: | ||
local start = ustring.find( source_str, pattern, start_pos, plain ) | local start = ustring.find( source_str, pattern, start_pos, plain ) | ||
if start == nil then | if start == nil then | ||
start = 0 | start = 0 | ||
150번째 줄: | 146번째 줄: | ||
return start | return start | ||
end | end | ||
218번째 줄: | 170번째 줄: | ||
if count ~= nil then | if count ~= nil then | ||
result = ustring.gsub( source_str, pattern, replace, count ) | |||
else | else | ||
result = ustring.gsub( source_str, pattern, replace ) | |||
end | end | ||
return result | return result | ||
end | end | ||
254번째 줄: | 199번째 줄: | ||
local s = new_args['s'] or '' | local s = new_args['s'] or '' | ||
return ustring.lower( s ) | return ustring.lower( s ) | ||
end | end | ||
-- string.byte의 유니코드 호환 버전 | -- string.byte의 유니코드 호환 버전 | ||
function str.tounicode( frame ) | function str.tounicode( frame ) | ||
local | local new_args = str._getParameters( frame.args, { 's', 'i', 'j' } ) | ||
local s = | local s = new_args['s'] or '' | ||
local i = tonumber( new_args['i'] ) or 1 | |||
local j = tonumber( new_args['j'] ) or -1 | |||
return ustring.codepoint( frame.args[1] ) | |||
end | end | ||
-- string.char | -- string.char | ||
function str.char( frame ) | function str.char( frame ) | ||
local new_args = str._getParameters( frame.args, { 'c' } ) | |||
local new_args = str._getParameters( args, { 'c' } ) | local c = new_args['c'] or '' | ||
local c = | |||
return ustring.char( c ) | return ustring.char( c ) | ||
end | end | ||
function str.escapePattern( frame ) | function str.escapePattern( frame ) | ||
local | local pattern_str = frame.args[1] | ||
if not pattern_str then | if not pattern_str then | ||
return str._error( 'No pattern string specified' ) | return str._error( 'No pattern string specified' ) | ||
305번째 줄: | 227번째 줄: | ||
function str.count(frame) | function str.count(frame) | ||
local args = str._getParameters(frame.args, {'source', 'pattern', 'plain'}) | |||
local args = str._getParameters( | |||
local source = args.source or '' | local source = args.source or '' | ||
local pattern = args.pattern or '' | local pattern = args.pattern or '' | ||
314번째 줄: | 235번째 줄: | ||
end | end | ||
local _, count = ustring.gsub(source, pattern, '') | local _, count = ustring.gsub(source, pattern, '') | ||
return count | return count | ||
end | end | ||
327번째 줄: | 243번째 줄: | ||
]] | ]] | ||
function str.endswith(frame) | function str.endswith(frame) | ||
local args = str._getParameters(frame.args, {'source', 'pattern'}) | |||
local args = str._getParameters( | |||
local source = args.source or '' | local source = args.source or '' | ||
local pattern = args.pattern or '' | local pattern = args.pattern or '' | ||
343번째 줄: | 258번째 줄: | ||
function str.join(frame) | function str.join(frame) | ||
getArgs(frame) | |||
local | local i = 1 | ||
local | local temp = '' | ||
local | local sep = args[i] | ||
while args[i] ~= nil do | while args[i] ~= nil do | ||
i = i + 1 | |||
temp = temp..sep..args[i] | |||
end | end | ||
return | return temp | ||
end | end | ||