Documentation for this module may be created at Module:Sandbox/Zaffrecrb/gloss/doc

local p = {}

function split(str, pat)
   local t = {n=0}
   local fpat = "(.-)" .. pat
   local last_end = 1
   local s, e, cap = str:find(fpat, 1)
   while s do
      if s ~= 1 or cap ~= "" then
         table.insert(t,cap)
      end
      last_end = e+1
      s, e, cap = str:find(fpat, last_end)
   end
   if last_end <= #str then
      cap = str:sub(last_end)
      table.insert(t, cap)
   end
   return t
end

function p.main(frame)
    local str = frame.args[1]

    function cap_if(s)
        if string.upper(s) == s then
            return table.concat({"<small>", s, "</small>"}, "")
        else
            return s
        end
    end

    function capsize(s)
        local inter2 = {}
        for i, k in ipairs(split(s, "%-")) do
        	local sub2 = {}
        	for j, v in ipairs(split(k, "%.")) do table.insert(sub2, cap_if(v)) end
        	table.insert(inter2, cap_if(table.concat(sub2, ".")))
        end
        return table.concat(inter2, "-")
    end

    return capsize(str)
end

return p