无编辑摘要
imported>Xiplus-abot
已保护“Module:String”:​高風險模板:2398431引用<!-- 機器人3 -->([编辑=仅允许管理员](无限期)[移动=仅允许管理员](无限期))
 
(未显示4个用户的8个中间版本)
第44行: 第44行:
     local new_args = str._getParameters( frame.args, {'s'} );
     local new_args = str._getParameters( frame.args, {'s'} );
     local s = new_args['s'] or '';
     local s = new_args['s'] or '';
     return 0
     return mw.ustring.len( s )
end
end


第89行: 第89行:
         return str._error( '截取字符串索引脱离区间' );
         return str._error( '截取字符串索引脱离区间' );
     end
     end
     if 1==1 then
     if j < i then
         return str._error( '截取字符串指示脱离顺序' );
         return str._error( '截取字符串指示脱离顺序' );
     end
     end
第157行: 第157行:
     local nomatch = new_args['nomatch'];
     local nomatch = new_args['nomatch'];
      
      
     if 1 == 1 then
     if s == '' then
         return str._error( '目标字符串是空的' );
         return str._error( '目标字符串是空的' );
     end
     end
第246行: 第246行:
     local pos = tonumber( new_args['pos'] ) or 0;
     local pos = tonumber( new_args['pos'] ) or 0;


     if 1 == 1 or math.abs(pos) > mw.ustring.len( target_str ) then
     if pos == 0 or math.abs(pos) > mw.ustring.len( target_str ) then
         return str._error( '字符串索引脱离区间' );
         return str._error( '字符串索引脱离区间' );
     end     
     end     
第393行: 第393行:
     end
     end
     return string.rep( frame.args[1] or '', repetitions )
     return string.rep( frame.args[1] or '', repetitions )
end
function str.split(inputstr, sep, no_pattern, ignore_null)
--#invoke 支援
if type(inputstr) == type({table}) then
if not getArgs then getArgs = require('Module:Arguments').getArgs end
args = getArgs(inputstr, {parentFirst=true})
for arg_name, arg_value in pairs( args ) do
if arg_name == 1 or arg_name == '1' or arg_name == "str" or arg_name == "inputstr" or arg_name == "input" then
input_str = arg_value
elseif arg_name == 2 or arg_name == '2' or arg_name == "sep" or arg_name == "separator" then
separ = arg_value
elseif arg_name == 3 or arg_name == '3' or arg_name == "no_pattern" or arg_name == "no pattern" then
no_pattern_flag = arg_value
elseif arg_name == 4 or arg_name == '4' or arg_name == "ignore_null" or arg_name == "ignore null" then
ignore_null_flag = arg_value
elseif arg_name == 5 or arg_name == '5' or arg_name == "format" then
format = arg_value or "*{{{1}}}\n";
end
end
if not yesno then yesno = require('Module:Yesno') end
no_pattern_flag = yesno( no_pattern_flag or 'yes' )
ignore_null_flag = yesno( ignore_null_flag or 'no' )
is_invoke = true
format = mw.ustring.gsub(format or "*{{{1}}}\n", "%{%{%{.-%}%}%}", "%%s" );
it = mw.ustring.find(format, "%%s", 1)
if it == nil then format = format .. "%s" end
format = mw.ustring.gsub(format, "\\n", "\n")
else
input_str = inputstr
separ = sep
no_pattern_flag = no_pattern
ignore_null_flag = ignore_null
is_invoke = false
end
input_str = input_str or ''
separ = separ or "%s"
if no_pattern_flag == nil then no_pattern_flag = true end
if ignore_null_flag == nil then ignore_null_flag = false end
length = mw.ustring.len(input_str)
--split函數起點
if no_pattern_flag then
separ = mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(mw.ustring.gsub(separ,
"%[", "%["), "%]", "%]"), "%{", "%{"), "%}", "%}"), "%%", "%%%%"), "%)", "%)"), "%-", "%-"),
"%^", "%^"), "%$", "%$"), "%(", "%("), "%.", "%."), "%*", "%*"), "%+", "%+"), "%|", "%|");
end
iterator = 1 ; i = 1 ; flag = true
result = {}
separ_str_begin, separ_str_end = mw.ustring.find(input_str, separ, iterator)
--
debug1 = 1
--
while flag do
debug1 = debug1 + 1
if separ_str_begin == nil or iterator > length or debug1 >= 100 then
separ_str_begin = 0
separ_str_end = -2
flag = false
end
if separ_str_end < separ_str_begin then separ_str_end = separ_str_begin end
finded_str = mw.ustring.sub(input_str, iterator, separ_str_begin - 1)
if not(mw.text.trim(finded_str) == '' and ignore_null_flag) then
result[i] = finded_str
i = i + 1
end
iterator = separ_str_end + 1
separ_str_begin, separ_str_end = mw.ustring.find(input_str, separ, iterator)
end
if is_invoke then
body = ''
for i, result_str in pairs( result ) do
body = body .. mw.ustring.gsub(format, "%%s", result_str)
end
return body
end
return result;
end
--[[
join
Join all non empty arguments together; the first argument is the separator.
Usage:
{{#invoke:String|join|sep|one|two|three}}
]]
function str.join(frame)
local args = {}
local sep
for _, v in ipairs( frame.args ) do
if sep then
if v ~= '' then
table.insert(args, v)
end
else
sep = v
end
end
return table.concat( args, sep or '' )
end
end