變更
per EP
if i > len or j > len or i < 1 or j < 1 then
return str._error( 'String subset index out of range截取字符串索引脱离区间' );
end
if j < i then
return str._error( 'String subset indices out of order截取字符串指示脱离顺序' );
end
if s == '' then
return str._error( 'Target string is empty目标字符串是空的' );
end
if pattern == '' then
return str._error( 'Pattern string is empty模式字符串是空的' );
end
if math.abs(start) < 1 or math.abs(start) > mw.ustring.len( s ) then
return str._error( 'Requested start is out of range要求的起始点脱离区间' );
end
if match_index == 0 then
return str._error( 'Match index is out of range匹配索引脱离区间' );
end
if plain_flag then
if result == nil then
if nomatch == nil then
return str._error( 'Match not found找不到匹配' );
else
return nomatch;
if pos == 0 or math.abs(pos) > mw.ustring.len( target_str ) then
return str._error( 'String index out of range字符串索引脱离区间' );
end
end
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
function str._error( error_str )
local frame = mw.getCurrentFrame();
local error_category = frame.args.error_category or 'Errors reported by Module String字符串模块报告的错误';
local ignore_errors = frame.args.ignore_errors or false;
local no_category = frame.args.no_category or false;
end
local error_str = '<strong class="error">String Module Error: 字符串模块出错:' .. error_str .. '</strong>';
if error_category ~= '' and not str._getBoolean( no_category ) then
error_str = '[[Category:' .. error_category .. ']]' .. error_str;
boolean_value = boolean_str;
else
error( 'No boolean value found布尔值找不到' );
end
return boolean_value