diff options
-rw-r--r-- | acf/error.lua | 2 | ||||
-rw-r--r-- | acf/loader.lua | 2 | ||||
-rw-r--r-- | acf/model/field.lua | 6 | ||||
-rw-r--r-- | acf/model/init.lua | 4 | ||||
-rw-r--r-- | acf/model/net.lua | 4 | ||||
-rw-r--r-- | acf/model/node.lua | 4 | ||||
-rw-r--r-- | acf/path.lua | 10 | ||||
-rw-r--r-- | acf/persistence/backends/augeas.lua | 10 | ||||
-rw-r--r-- | acf/persistence/backends/files.lua | 12 | ||||
-rw-r--r-- | server.lua | 4 |
10 files changed, 29 insertions, 29 deletions
diff --git a/acf/error.lua b/acf/error.lua index 7157d37..82fa6d7 100644 --- a/acf/error.lua +++ b/acf/error.lua @@ -48,7 +48,7 @@ function M.ErrorDict:collect(func, ...) xpcall( function() return func(unpack(arg)) end, function(err) - local _, _, data = string.find(err, '.-: (.+)') + local _, _, data = err:find('.-: (.+)') local success, res = pcall(json.decode, data) if success and type(res) == 'table' then return res end return data..'\n'..debug.traceback() diff --git a/acf/loader.lua b/acf/loader.lua index ff82246..13b2db0 100644 --- a/acf/loader.lua +++ b/acf/loader.lua @@ -15,7 +15,7 @@ return function(subdir) local res = {} for _, modfile in ipairs(posix.dir(pth.join(unpack(comps)))) do if stringy.endswith(modfile, '.lua') then - local name = string.sub(modfile, 1, -5) + local name = modfile:sub(1, -5) res[name] = require(table.concat(comps, '.')..'.'..name) end end diff --git a/acf/model/field.lua b/acf/model/field.lua index d4e934c..362c7ab 100644 --- a/acf/model/field.lua +++ b/acf/model/field.lua @@ -32,9 +32,7 @@ end function M.Member:auto_ui_name(name) if not name then return end - return string.gsub( - string.upper(string.sub(name, 1, 1))..string.sub(name, 2), '-', ' ' - ) + return (name:sub(1, 1):upper()..name:sub(2)):gsub('-', ' ') end function M.Member:meta(context) @@ -129,7 +127,7 @@ end function M.String:validate(context, value) super(self, M.String):validate(context, value) - if self['max-length'] and string.len(value) > self['max-length'] then + if self['max-length'] and value:len() > self['max-length'] then raise(context.path, 'Maximum length exceeded') end end diff --git a/acf/model/init.lua b/acf/model/init.lua index 9d09204..0254fce 100644 --- a/acf/model/init.lua +++ b/acf/model/init.lua @@ -112,7 +112,7 @@ function M.Reference:_validate(context, value) if not stringy.startswith(value, prefix) then raise(path, 'Reference out of scope ('..scope..')') end - value = string.sub(value, string.len(prefix) + 1, -1) + value = value:sub(prefix:len() + 1, -1) end -- assume one-level ref for now @@ -158,7 +158,7 @@ end function M.Collection:auto_ui_name(name) if not name then return end - if string.sub(name, -1, -1) ~= 's' then name = name..'s' end + if name:sub(-1, -1) ~= 's' then name = name..'s' end return super(self, M.Collection):auto_ui_name(name) end diff --git a/acf/model/net.lua b/acf/model/net.lua index e5c1836..ae82f1e 100644 --- a/acf/model/net.lua +++ b/acf/model/net.lua @@ -31,7 +31,7 @@ function M.IPv4Address:validate(context, value) if tonumber(octet) > 255 then return true end end end - if test(string.match(value, '^(%d+)%.(%d+)%.(%d+)%.(%d+)$')) then + if test(value:match('^(%d+)%.(%d+)%.(%d+)%.(%d+)$')) then raise(context.path, 'Invalid IPv4 address') end end @@ -63,7 +63,7 @@ function M.IPv6Address:validate(context, value) if comp == '' then if short then invalid() end short = true - elseif not string.match(comp, '^%x%x?%x?%x?$') then invalid() end + elseif not comp:match('^%x%x?%x?%x?$') then invalid() end end if ( short and #comps == 3 and comps[2] == '' diff --git a/acf/model/node.lua b/acf/model/node.lua index b708112..0b02e80 100644 --- a/acf/model/node.lua +++ b/acf/model/node.lua @@ -162,9 +162,7 @@ function M.Collection:init(context, params) mt.meta.type = 'collection' mt.meta.members = field:meta() - mt.meta['ui-member'] = params.ui_member or string.gsub( - mt.meta['ui-name'], 's$', '' - ) + mt.meta['ui-member'] = params.ui_member or mt.meta['ui-name']:gsub('s$', '') function mt.mmeta(name) local res = util.copy(mt.meta.members) diff --git a/acf/path.lua b/acf/path.lua index 4df0350..d824141 100644 --- a/acf/path.lua +++ b/acf/path.lua @@ -13,7 +13,7 @@ M.wildcard = {} local special = {['..']=up, ['*']=M.wildcard} -function M.is_absolute(path) return string.sub(path, 1, 1) == '/' end +function M.is_absolute(path) return path:sub(1, 1) == '/' end function M.escape(comp) @@ -21,7 +21,7 @@ function M.escape(comp) if comp == item then return symbol end end if type(comp) == 'number' then return tostring(comp) end - local res = string.gsub(comp, '([\\/])', '\\%1') + local res = comp:gsub('([\\/])', '\\%1') return (special[res] or tonumber(res)) and '\\'..res or res end @@ -49,7 +49,7 @@ function M.split(path) end while true do - local prefix, sep, suffix = string.match(path, '([^\\/]*)([\\/])(.*)') + local prefix, sep, suffix = path:match('([^\\/]*)([\\/])(.*)') if not prefix then merge(comp..path) return res @@ -57,9 +57,9 @@ function M.split(path) comp = comp..prefix if sep == '\\' then - comp = comp..string.sub(suffix, 1, 1) + comp = comp..suffix:sub(1, 1) escaped = true - path = string.sub(suffix, 2, -1) + path = suffix:sub(2, -1) else merge(comp) comp = '' diff --git a/acf/persistence/backends/augeas.lua b/acf/persistence/backends/augeas.lua index ec13531..4cf623a 100644 --- a/acf/persistence/backends/augeas.lua +++ b/acf/persistence/backends/augeas.lua @@ -13,7 +13,7 @@ local copy = util.copy local function aug_path(path) return pth.join('/files', unpack(path)) end local function strip_name(name) - return type(name) == 'string' and string.match(name, '^[^][/=)%s]+') or name + return type(name) == 'string' and name:match('^[^][/=)%s]+') or name end local function ipath(path, index) return path..'['..index..']' end @@ -26,7 +26,11 @@ function backend:init() self.aug = require('augeas').init() end function backend:find(path, leaf) util.map( function(comp) - assert(comp == strip_name(comp) and not string.match(comp, '^%.+$')) + assert( + comp == strip_name(comp) and ( + type(comp) == 'number' or not comp:match('^%.+$') + ) + ) end, path ) @@ -107,7 +111,7 @@ function backend:set(mods) local ord = order(pth.join('/', unpack(path))) for _, sibling in ipairs(self.aug:match(pth.parent(mpath)..'/*')) do - if order(string.sub(strip_name(sibling), 7, -1)) > ord then + if order(strip_name(sibling):sub(7, -1)) > ord then self.aug:insert(sibling, pth.name(mpath), true) break end diff --git a/acf/persistence/backends/files.lua b/acf/persistence/backends/files.lua index b14ed10..7d03e12 100644 --- a/acf/persistence/backends/files.lua +++ b/acf/persistence/backends/files.lua @@ -17,9 +17,9 @@ local function get_scope(top) return end - return stringy.startswith(top.scope, '/files/') and string.sub( - top.scope, 7, -1 - ) or nil + return stringy.startswith( + top.scope, '/files/' + ) and top.scope:sub(7, -1) or nil end @@ -47,9 +47,9 @@ function backend:get(path, top) assert(scope) scope = scope..'/' - local slen = string.len(scope) - assert(string.sub(target, 1, slen) == scope) - return string.sub(target, slen + 1, -1) + local slen = scope:len() + assert(target:sub(1, slen) == scope) + return target:sub(slen + 1, -1) elseif t == 'directory' then local res = {} @@ -118,11 +118,11 @@ return function(env) function() if stringy.startswith(path, '/meta/') then if method ~= 'GET' then return 405 end - return 200, nil, txn:meta(string.sub(path, 6, -1)) + return 200, nil, txn:meta(path:sub(6, -1)) end if stringy.startswith(path, '/config/') then - path = string.sub(path, 8, -1) + path = path:sub(8, -1) local parent, name, res if path ~= '/' then |