Jump to content

Module:Citation/CS1: Difference between revisions

testing
m>Dragons flight
(code cleanup)
m>Dragons flight
(testing)
Line 94: Line 94:
     end
     end
end
end
function safejoin( tbl, duplicate_char, space_char )
    local str = '';
    for _, value in ipairs( tbl ) do
        if value == nil then value = ''; end
       
        -- Trim spaces
        value = value:match( '^%s*(.-)%s*$' );
       
        if str == '' then
            str = value;
        elseif value ~= '' then
            if value:sub(1,1) == duplicate_char then
                if str:sub(-1,-1) == duplicate_char then
                    str = str .. space_char .. value:sub(2);
                elseif str:sub(-3,-1) == duplicate_char .. "''" then                 
                    str = str .. space_char .. value:sub(2);
                else
                    str = str .. space_char .. value;
                end
            else
                str = str .. space_char .. value;
            end
        end
    end
    return str;
end 


function selectyear( str )
function selectyear( str )
Line 910: Line 937:
         end
         end
         text = Authors .. Date .. Chapter .. Editors .. tcommon
         text = Authors .. Date .. Chapter .. Editors .. tcommon
         if ( text:sub(-1,-1) == "." and --prior text ends as "."
         safejoin( {text, pgtext, idcommon}, sepc, ' ' );
            pgtext:sub(1,1) == "." )
            then pgtext = pgtext:sub(2,-1) end --truncate by 1
        text = text .. pgtext .. idcommon
     elseif ( "" ~= Editors) then
     elseif ( "" ~= Editors) then
         if ( "" ~= Date ) then
         if ( "" ~= Date ) then
Line 930: Line 954:
         end
         end
         text = Editors .. Date .. Chapter .. tcommon
         text = Editors .. Date .. Chapter .. tcommon
         if ( text:sub(-1,-1) == "." and --prior text ends as "."
         text = safejoin( {text, pgtext, idcommon}, sepc, ' ' );
            pgtext:sub(1,1) == "." )
            then pgtext = pgtext:sub(2,-1) end --truncate by 1
        text = text .. pgtext .. idcommon
     else
     else
         if ( "" ~= Date ) then
         if ( "" ~= Date ) then
Line 942: Line 963:
         end -- endif ""~=Date
         end -- endif ""~=Date
         text = Chapter .. tcommon .. Date
         text = Chapter .. tcommon .. Date
         if ( text:sub(-1,-1) == "." and --prior text ends as "."
         text = safejoin( {text, pgtext, idcommon}, sepc, ' ' );
            pgtext:sub(1,1) == "." )
            then pgtext = pgtext:sub(2,-1) end --truncate by 1
        text = text .. pgtext .. idcommon
     end
     end
      
      
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.