Why Gemfury? Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Debian packages RPM packages NuGet packages

Repository URL to install this package:

Details    
hd-community-waf / usr / local / share / lua / 5.1 / resty / woothee / util.lua
Size: Mime:
local _M = { }

local dataset = require('resty.woothee.dataset')

function _M.update_map(target, source)
  target = target or {}
  source = source or {}

  for key, val in pairs(source) do
    if key == dataset.KEY_LABEL or key == dataset.KEY_TYPE then
      -- pass
    elseif source[key] and string.len(source[key]) > 0 then
      target[key] = source[key] or ''
    end
  end
end

function _M.update_category(target, category)
  target[dataset.ATTRIBUTE_CATEGORY] = category
end

function _M.update_version(target, version)
  target[dataset.ATTRIBUTE_VERSION] = version
end

function _M.update_os(target, os)
  target[dataset.ATTRIBUTE_OS] = os
end

function _M.update_os_version(target, version)
  target[dataset.ATTRIBUTE_OS_VERSION] = version
end

function _M.check_regex(str, regex)
    local found = false
    local match = {}
    for k, v in string.gmatch(str, regex) do
        found = true
        table.insert(match, k)
        if v and type(v) == "string" then
            table.insert(match, v)
        end
    end

    if found then
      return match, nil
    end

    return nil, nil
end

function _M.check_regex_single(str, regex)
  local m, err = string.match(str, regex)
  if m then
      return { m }, nil
    end

  return nil, nil 
end
return _M