1234567891011121314151617181920212223242526272829303132333435363738394041424344454647 |
- -- {{{ 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
|