開啟主選單

求真百科

變更

模块:String

移除 3,177 位元組, 6 年前
导入1个版本
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
 
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
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
行政員使用者查核員拒收員巡檢員管理員、water、waterc、waterh、waterm、waterp、waters、watert、waterv、waterw、waterz
10,323
次編輯