편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.
최신판 | 당신의 편집 | ||
6번째 줄: | 6번째 줄: | ||
-- string.find | -- string.find | ||
function str.len( frame ) | function str.len( frame ) | ||
local new_args = str._getParameters( | local args = getArgs(frame) | ||
local new_args = str._getParameters( args, {'s'} ) | |||
local s = new_args['s'] or '' | local s = new_args['s'] or '' | ||
return ustring.len( s ) | return ustring.len( s ) | ||
135번째 줄: | 136번째 줄: | ||
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번째 줄: | 145번째 줄: | ||
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 | ||
171번째 줄: | 150번째 줄: | ||
return start | return start | ||
end | end | ||
-- string.gsub | -- string.gsub | ||
function str.gsub( frame ) | function str.gsub( frame ) | ||
local new_args = str._getParameters( | local args = getArgs(frame) | ||
local new_args = str._getParameters( args, {'source', 'pattern', 'replace', 'count', 'plain' } ) | |||
local source_str = new_args['source'] or '' | local source_str = new_args['source'] or '' | ||
local pattern = new_args['pattern'] or '' | local pattern = new_args['pattern'] or '' | ||
218번째 줄: | 175번째 줄: | ||
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 | ||
235번째 줄: | 185번째 줄: | ||
-- string.rep | -- string.rep | ||
function str.rep( frame ) | function str.rep( frame ) | ||
local repetitions = tonumber( | local args = getArgs(frame) | ||
local repetitions = tonumber( args[2] ) | |||
if not repetitions then | if not repetitions then | ||
return str._error( 'function rep expects a number as second parameter, received "' .. ( | return str._error( 'function rep expects a number as second parameter, received "' .. ( args[2] or '' ) .. '"' ) | ||
end | end | ||
return ustring.rep( | return ustring.rep( args[1] or '', repetitions ) | ||
end | end | ||
-- string.upper | -- string.upper | ||
function str.upper( frame ) | function str.upper( frame ) | ||
local new_args = str._getParameters( | local args = getArgs(frame) | ||
local new_args = str._getParameters( args, { 's' } ) | |||
local s = new_args['s'] or '' | local s = new_args['s'] or '' | ||
return ustring.upper( s ) | return ustring.upper( s ) | ||
251번째 줄: | 203번째 줄: | ||
-- string.lower | -- string.lower | ||
function str.lower( frame ) | function str.lower( frame ) | ||
local new_args = str._getParameters( | local args = getArgs(frame) | ||
local new_args = str._getParameters( args, { 's' } ) | |||
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 args = getArgs( frame ) | local args = getArgs(frame) | ||
local | local new_args = str._getParameters( args, { 's', 'i', 'j' } ) | ||
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] ) | |||
local | |||
end | end | ||
290번째 줄: | 223번째 줄: | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local new_args = str._getParameters( args, { 'c' } ) | local new_args = str._getParameters( args, { 'c' } ) | ||
local c = | local c = new_args['c'] or '' | ||
return ustring.char( c ) | return ustring.char( c ) | ||
end | end | ||
314번째 줄: | 247번째 줄: | ||
end | end | ||
local _, count = ustring.gsub(source, pattern, '') | local _, count = ustring.gsub(source, pattern, '') | ||
return count | return count | ||
end | end | ||
344번째 줄: | 272번째 줄: | ||
function str.join(frame) | function str.join(frame) | ||
local args = getArgs(frame) | local args = getArgs(frame) | ||
local | local str_ = '' | ||
local sep = args[1] | local sep = args[1] | ||
local i | local i = 2 | ||
while args[i] ~= nil do | while args[i] ~= nil do | ||
str_ = str_..args[i]..sep | |||
i = i + 1 | |||
end | end | ||
str_ = ustring.gsub(str_, '.$', '') | |||
return str_ | |||
end | end | ||