更改
per User:A2569875 EP
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
mw.log(no_pattern_flag, ignore_null_flag);
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
mw.log(separ_str_begin, separ_str_end, iterator)
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
mw.log("\"" .. result[i] .. "\"")
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
end