diff options
author | Hans Hagen <pragma@wxs.nl> | 2010-01-15 15:49:00 +0100 |
---|---|---|
committer | Hans Hagen <pragma@wxs.nl> | 2010-01-15 15:49:00 +0100 |
commit | c3fb9b7d537059ec737147e65049e54585a9f777 (patch) | |
tree | cec01e1e2d069136b4c3dc2e858f6332224da05a /scripts/context/stubs/mswin/luatools.lua | |
parent | 45d11a2f318b118a2592b9db7eb530a4cf613a00 (diff) | |
download | context-c3fb9b7d537059ec737147e65049e54585a9f777.tar.gz |
beta 2010.01.15 15:49
Diffstat (limited to 'scripts/context/stubs/mswin/luatools.lua')
-rw-r--r-- | scripts/context/stubs/mswin/luatools.lua | 36 |
1 files changed, 31 insertions, 5 deletions
diff --git a/scripts/context/stubs/mswin/luatools.lua b/scripts/context/stubs/mswin/luatools.lua index 5fcc30d3c..f9b855f74 100644 --- a/scripts/context/stubs/mswin/luatools.lua +++ b/scripts/context/stubs/mswin/luatools.lua @@ -2367,22 +2367,48 @@ local fragment = hash * lpeg.Cs((escaped+(1- endofstring))^0 local parser = lpeg.Ct(scheme * authority * path * query * fragment) +-- todo: reconsider Ct as we can as well have five return values (saves a table) +-- so we can have two parsers, one with and one without + function url.split(str) return (type(str) == "string" and lpegmatch(parser,str)) or str end +-- todo: cache them + function url.hashed(str) local s = url.split(str) + local somescheme = s[1] ~= "" return { - scheme = (s[1] ~= "" and s[1]) or "file", + scheme = (somescheme and s[1]) or "file", authority = s[2], - path = s[3], - query = s[4], - fragment = s[5], - original = str + path = s[3], + query = s[4], + fragment = s[5], + original = str, + noscheme = not somescheme, } end +function url.hasscheme(str) + return not url.split(str).nosheme +end + +function url.addscheme(str,scheme) + return (url.hasscheme(str) and str) or ((scheme or "file:///") .. str) +end + +function url.construct(hash) + local fullurl = hash.sheme .. "://".. hash.authority .. hash.path + if hash.query then + fullurl = fullurl .. "?".. hash.query + end + if hash.fragment then + fullurl = fullurl .. "?".. hash.fragment + end + return fullurl +end + function url.filename(filename) local t = url.hashed(filename) return (t.scheme == "file" and (gsub(t.path,"^/([a-zA-Z])([:|])/)","%1:"))) or filename |