Jump to content

Module:String: Difference between revisions

accommodate the commonly used "no_category" function
m>Dragons flight
(improves commenting, adds whitespace and error handling to sub, improvements to error handling generally.)
m>Dragons flight
(accommodate the commonly used "no_category" function)
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]. If set to an empty
         [Category:Errors reported by Module String].
        string, no category will be added during an error.  
       
    no_category: If set to 'true' or 1, no category will be added if an error
        is generated.
]]
]]


Line 80: Line 82:
     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
    if j < i then
        return str._error( 'String subset indices out of order' );
     end
     end
      
      
Line 299: Line 301:
     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;
    local no_category = frame.args.no_category or false;
      
      
     if str._getBoolean(ignore_errors) then
     if str._getBoolean(ignore_errors) then
Line 305: Line 308:
      
      
     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 ~= '' then
     if error_category ~= '' and not str._getBoolean( no_category ) then
         error_str = '[[Category:' .. error_category .. ']]' .. error_str;
         error_str = '[[Category:' .. error_category .. ']]' .. error_str;
     end         
     end         
Line 320: Line 323:
     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' then
         if boolean_str == 'false' or boolean_str == 'no' or boolean_str == '0'
                or boolean_str == '' then
             boolean_value = false;
             boolean_value = false;
         else
         else
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.