Module:Utilities: Difference between revisions

Jump to navigation Jump to search
added function to split pascal into separate words
fixed add_space_before_cap
Line 43: Line 43:
-- i.e. BulletVelocity > Bullet Velocity
-- i.e. BulletVelocity > Bullet Velocity
function p.add_space_before_cap(str)
function p.add_space_before_cap(str)
    return str:gsub("(%u)", function(c)
        return " " .. c
    end, 2)
end
function p.split_pascal(str)
    -- Insert a space before each capital letter (except the first one) that is followed by a lowercase letter
    local result = str:gsub("(%l)(%u)", "%1 %2")
    local result = str:gsub("(%l)(%u)", "%1 %2")
   
    -- Return the result with a capital letter followed by another capital and lowercase letters split
    return result:gsub("(%u)(%u%l)", " %1%2")
    return result:gsub("(%u)(%u%l)", " %1%2")
end
end
return p
return p