Module:HTMLParse: Difference between revisions

463 bytes removed ,  16:11, 19 September 2019
moved possessive/pluralize logic to its own module
mNo edit summary
(moved possessive/pluralize logic to its own module)
Line 1: Line 1:
local p = {}
local p = {}
local conjugate = require'Module:Grammar/Conjugate'


function p.pluralize(frame, apostrophe)
function p.pluralize(frame, apostrophe)
Line 10: Line 11:
     if (prefix == nil or prefix == '' or postfix == nil or postfix == '') then
     if (prefix == nil or prefix == '' or postfix == nil or postfix == '') then
         return htmlString  --return unmodified string (couldn't find alpha character followed by closing HTML tag)
         return htmlString  --return unmodified string (couldn't find alpha character followed by closing HTML tag)
    elseif (string.sub(prefix, -1) == 's') then
        return (htmlString .. apostrophe)  --return unmodified (ends with 's', like 'boots', so we shouldn't append another 's')
    elseif (string.sub(prefix, -1) == 'y') and apostrophe == '' then
        return (string.sub(prefix, 1, -2) ..  'ies' .. postfix)
    elseif (string.sub(prefix, -1) == 'z' or string.sub(prefix, -2) == 'ch' or string.sub(prefix, -2) == 'sh' or string.sub(prefix, -1) == 'x') and apostrophe == '' then
        return (prefix ..  'es' .. postfix)
     else
     else
        return (prefix .. apostrophe .. 's' .. postfix)
      return (conjugate.pluralize(prefix, apostrophe) .. postfix)
     end
     end
end
end