Skip to content

Instantly share code, notes, and snippets.

@fur-q
Last active August 29, 2015 14:02
Show Gist options
  • Save fur-q/9d5c27b21ed3d4da1205 to your computer and use it in GitHub Desktop.
Save fur-q/9d5c27b21ed3d4da1205 to your computer and use it in GitHub Desktop.
local function parse_url(url)
local out = {}
url = string.gsub(url, "#(.*)$", function(f)
out.fragment = f
return ""
end)
url = string.gsub(url, "^([%w][%w.+-]*):", function(s)
out.scheme = s
return ""
end)
url = string.gsub(url, "^//([^/]*)", function(n)
out.authority = n
return ""
end)
url = string.gsub(url, "%?(.*)", function(q)
out.query = q
return ""
end)
url = string.gsub(url, ";(.*)", function(p)
out.params = p
return ""
end)
if not (out.scheme or out.authority) then
return false
end
out.path = url == "" and "/" or url
return out
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment