-- {{{ License
-- Awesome utils functions
-- 2012, Emmanuel Bouthenot <kolter@openics.org>
--
-- This file is distributed in the hope that it will be useful,
-- but WITHOUT ANY WARRANTY
--
-- }}}

-- {{{ Functions
function table.pos(t, k)
    local ret = nil
    for i,n in ipairs(t) do
        if n == k then
            ret = i
            break
        end
    end
    return ret
end

function table.keypos(t, p)
    local ret
    for i,n in ipairs(t) do
        if i == p then
            ret = n
            break
        end
    end
    return ret
end

function table.keyfirst(t)
    return table.keypos(t, 1)
end

function table.keylast(t)
    return table.keypos(t, table.getn(t))
end

function string.trim(s)
    -- from http://lua-users.org/wiki/StringTrim
    return (s:gsub("^%s*(.-)%s*$", "%1"))
end
-- }}}

-- vim: foldmethod=marker