모듈:String 편집하기

귀하는 로그인되어 있지 않습니다. 이대로 편집하면 귀하의 IP 주소가 편집 기록에 남게 됩니다.

편집을 취소할 수 있습니다. 이 편집을 되돌리려면 아래의 바뀐 내용을 확인한 후 게시해주세요.

최신판 당신의 편집
135번째 줄: 135번째 줄:
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 false
local plain = new_args['plain'] or true


if source_str == '' or pattern == '' then
if source_str == '' or pattern == '' then
144번째 줄: 144번째 줄:


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번째 줄: 149번째 줄:


return start
return start
end
function str.find_( str1,  str2 , str3, str4)
local source_str = str1 or ''
local pattern_str = str2 or ''
local start_ = str3 or 1
local plain_ = str4 or false
if source_str == '' or pattern_str == '' then
return 0
end
plain_ = str._getBoolean( plain_ )
local start = ustring.find( source_str, pattern_str, start_, plain_ )
if start == nil then
start = 0
end
return start
end
function str.ifexist( frame )
local args = getArgs(frame)
local new_args = str._getParameters( args, {'source', 'target', 'return1', 'return2' } )
local source_str = new_args['source'] or ''
local pattern = new_args['target'] or ''
local return1 = new_args['return1'] or ''
local return2 = new_args['return2'] or ''
if str.find_( source_str,  pattern) == 0 then
return return2
else
return return1
end
end
function str.ifexist_( source_str, pattern, return1, return2 )
if str.find_( source_str,  pattern) == 0 then
return return2
else
return return1
end
end
end


268번째 줄: 223번째 줄:
-- string.byte의 유니코드 호환 버전
-- string.byte의 유니코드 호환 버전
function str.tounicode( frame )
function str.tounicode( frame )
local args = getArgs( frame )
local args = getArgs(frame)
local s = args[1] or -1
local new_args = str._getParameters( args, { 's', 'i', 'j' } )
if s == -1 then
local s = new_args['s'] or ''
return '입력값이 없습니다.'
local i = tonumber( new_args['i'] ) or 1
else
local j = tonumber( new_args['j'] ) or -1
return 'U+0'..ustring.upper(string.format("%x", ustring.codepoint(s)))
return ustring.codepoint( frame.args[1], i, j )
end
end
 
function str.tounicode_( char )
local s = char or -1
if s == -1 then
return 0
else
return 'U+0'..ustring.upper(string.format("%x", ustring.codepoint(s)))
end
end
end


314번째 줄: 259번째 줄:
end
end
local _, count = ustring.gsub(source, pattern, '')
local _, count = ustring.gsub(source, pattern, '')
return count
end
function str.count_(str, pattern)
local _, count = ustring.gsub(str, pattern, '')
return count
return count
end
end
344번째 줄: 284번째 줄:
function str.join(frame)
function str.join(frame)
local args = getArgs(frame)
local args = getArgs(frame)
local table_ = {}
local str_ = ''
local sep = args[1]
local sep = args[2]
local i, j = 2, 1
local i = 3
-- args,table
while args[i] ~= nil and args[i] ~= "" do
str_ = str_..args[i]..sep
while args[i] ~= nil do
i = i + 1
if args[i] ~= '_' then
table_[j] = args[i]
i = i + 1
j = j + 1
else
i = i + 1
end
end
end
return table.concat(table_, sep)
str_ =  ustring.gsub(str_, '.$', '')
return str_
end
end


가온 위키에서의 모든 기여는 크리에이티브 커먼즈 저작자표시-동일조건변경허락 라이선스로 배포된다는 점을 유의해 주세요(자세한 내용에 대해서는 가온 위키:저작권 문서를 읽어주세요). 만약 여기에 동의하지 않는다면 문서를 저장하지 말아 주세요.
또한, 직접 작성했거나 퍼블릭 도메인과 같은 자유 문서에서 가져왔다는 것을 보증해야 합니다. 저작권이 있는 내용을 허가 없이 저장하지 마세요!
취소 편집 도움말 (새 창에서 열림)

이 문서에서 사용한 틀: