Editing Module:String
From MINR.ORG WIKI
Warning: You are not logged in. Your IP address will be publicly visible if you make any edits. If you log in or create an account, your edits will be attributed to your username, along with other benefits.
The edit can be undone.
Please check the comparison below to verify that this is what you want to do, and then save the changes below to finish undoing the edit.
Latest revision | Your text | ||
Line 15: | Line 15: | ||
error_category: If an error occurs, specifies the name of a category to | error_category: If an error occurs, specifies the name of a category to | ||
include with the error message. The default category is | include with the error message. The default category is | ||
− | [Category:Errors reported by Module String]. | + | [Category:Errors reported by Module String]. If set to an empty |
− | + | string, no category will be added during an error. | |
− | |||
− | |||
− | |||
− | |||
]] | ]] | ||
Line 84: | Line 80: | ||
if j < 0 then | if j < 0 then | ||
j = len + j + 1; | j = len + j + 1; | ||
+ | end | ||
+ | if j < i then | ||
+ | return str._error( 'String subset indices out of order' ); | ||
end | end | ||
if i > len or j > len or i < 1 or j < 1 then | if i > len or j > len or i < 1 or j < 1 then | ||
return str._error( 'String subset index out of range' ); | return str._error( 'String subset index out of range' ); | ||
− | |||
− | |||
− | |||
end | end | ||
Line 96: | Line 92: | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
function str.sublength( frame ) | function str.sublength( frame ) | ||
local i = tonumber( frame.args.i ) or 0 | local i = tonumber( frame.args.i ) or 0 | ||
Line 106: | Line 98: | ||
end | end | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
function str.match( frame ) | function str.match( frame ) | ||
− | + | return mw.ustring.match( frame.args.s, frame.args.pattern, tonumber( frame.args.i ) ) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 369: | Line 255: | ||
if plain then | if plain then | ||
pattern = str._escapePattern( pattern ); | pattern = str._escapePattern( pattern ); | ||
− | replace = | + | replace = str._escapePattern( replace ); |
end | end | ||
Line 381: | Line 267: | ||
return result; | return result; | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
end | end | ||
Line 425: | Line 299: | ||
local error_category = frame.args.error_category or 'Errors reported by Module String'; | local error_category = frame.args.error_category or 'Errors reported by Module String'; | ||
local ignore_errors = frame.args.ignore_errors or false; | local ignore_errors = frame.args.ignore_errors or false; | ||
− | |||
if str._getBoolean(ignore_errors) then | if str._getBoolean(ignore_errors) then | ||
Line 432: | Line 305: | ||
local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>'; | local error_str = '<strong class="error">String Module Error: ' .. error_str .. '</strong>'; | ||
− | if error_category ~= '' | + | if error_category ~= '' then |
error_str = '[[Category:' .. error_category .. ']]' .. error_str; | error_str = '[[Category:' .. error_category .. ']]' .. error_str; | ||
end | end | ||
Line 447: | Line 320: | ||
if type( boolean_str ) == 'string' then | if type( boolean_str ) == 'string' then | ||
boolean_str = boolean_str:lower(); | boolean_str = boolean_str:lower(); | ||
− | if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0 | + | if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0' then |
− | |||
boolean_value = false; | boolean_value = false; | ||
else | else |