diff options
author | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-06-28 23:31:21 +0300 |
---|---|---|
committer | Kaarle Ritvanen <kaarle.ritvanen@datakunkku.fi> | 2013-09-04 15:24:08 +0300 |
commit | 25ffc62a5b2c9a65e5c1689d5351adcf8cbef7e2 (patch) | |
tree | 7703761a8c13778b4aa6ef07d64628e760d6ba6f /acf/path.lua | |
parent | 63942c3e11107bb1f3f5d874a2f3b694bb510f39 (diff) | |
download | aconf-25ffc62a5b2c9a65e5c1689d5351adcf8cbef7e2.tar.bz2 aconf-25ffc62a5b2c9a65e5c1689d5351adcf8cbef7e2.tar.xz |
eliminate deprecated module style
Diffstat (limited to 'acf/path.lua')
-rw-r--r-- | acf/path.lua | 51 |
1 files changed, 26 insertions, 25 deletions
diff --git a/acf/path.lua b/acf/path.lua index be7387e..4df0350 100644 --- a/acf/path.lua +++ b/acf/path.lua @@ -3,22 +3,20 @@ Copyright (c) 2012-2013 Kaarle Ritvanen See LICENSE file for license details --]] -module(..., package.seeall) +local M = {} local map = require('acf.util').map local up = {} -wildcard = {} -local special = {['..']=up, ['*']=wildcard} +M.wildcard = {} +local special = {['..']=up, ['*']=M.wildcard} -function is_absolute(path) - return string.sub(path, 1, 1) == '/' -end +function M.is_absolute(path) return string.sub(path, 1, 1) == '/' end -function escape(comp) +function M.escape(comp) for symbol, item in pairs(special) do if comp == item then return symbol end end @@ -28,18 +26,18 @@ function escape(comp) end -function rawjoin(p1, p2, ...) +function M.rawjoin(p1, p2, ...) if not p2 then return p1 end - if not is_absolute(p2) then p2 = '/'..p2 end - return rawjoin((p1 == '/' and '' or p1)..p2, ...) + if not M.is_absolute(p2) then p2 = '/'..p2 end + return M.rawjoin((p1 == '/' and '' or p1)..p2, ...) end -function join(parent, ...) - return rawjoin(parent, unpack(map(escape, {...}))) +function M.join(parent, ...) + return M.rawjoin(parent, unpack(map(M.escape, {...}))) end -function split(path) +function M.split(path) local res = {} local comp = '' local escaped @@ -72,19 +70,19 @@ function split(path) end -function is_unique(path) - for _, comp in ipairs(split(path)) do - if comp == wildcard then return false end +function M.is_unique(path) + for _, comp in ipairs(M.split(path)) do + if comp == M.wildcard then return false end end return true end -function to_absolute(path, base) - if not is_absolute(path) then +function M.to_absolute(path, base) + if not M.is_absolute(path) then path = base..(base ~= '/' and '/' or '')..path end - local comps = split(path) + local comps = M.split(path) local i = 1 while i <= #comps do if comps[i] == up then @@ -94,17 +92,20 @@ function to_absolute(path, base) i = i - 1 else i = i + 1 end end - return join('/', unpack(comps)) + return M.join('/', unpack(comps)) end -function parent(path) - local comps = split(path) +function M.parent(path) + local comps = M.split(path) table.remove(comps) - return join('/', unpack(comps)) + return M.join('/', unpack(comps)) end -function name(path) - local comps = split(path) +function M.name(path) + local comps = M.split(path) return comps[#comps] end + + +return M |