summaryrefslogtreecommitdiff
path: root/script/src/3rd/lua-uri/uri/file/win32.lua
diff options
context:
space:
mode:
author最萌小汐 <sumneko@hotmail.com>2019-11-22 23:26:32 +0800
committer最萌小汐 <sumneko@hotmail.com>2019-11-22 23:26:32 +0800
commitd0ff66c9abe9d6abbca12fd811e0c3cb69c1033a (patch)
treebb34518d70b85de7656dbdbe958dfa221a3ff3b3 /script/src/3rd/lua-uri/uri/file/win32.lua
parent0a2c2ad15e1ec359171fb0dd4c72e57c5b66e9ba (diff)
downloadlua-language-server-d0ff66c9abe9d6abbca12fd811e0c3cb69c1033a.zip
整理一下目录结构
Diffstat (limited to 'script/src/3rd/lua-uri/uri/file/win32.lua')
-rw-r--r--script/src/3rd/lua-uri/uri/file/win32.lua34
1 files changed, 34 insertions, 0 deletions
diff --git a/script/src/3rd/lua-uri/uri/file/win32.lua b/script/src/3rd/lua-uri/uri/file/win32.lua
new file mode 100644
index 00000000..d4e40243
--- /dev/null
+++ b/script/src/3rd/lua-uri/uri/file/win32.lua
@@ -0,0 +1,34 @@
+local M = { _NAME = "uri.file.win32" }
+local URI = require "uri"
+local Util = require "uri._util"
+
+function M.filesystem_path (uri)
+ local host = uri:host()
+ local path = Util.uri_decode(uri:path())
+ if host ~= "" then path = "//" .. host .. path end
+ if path:find("^/[A-Za-z]|/") or path:find("^/[A-Za-z]|$") then
+ path = path:gsub("|", ":", 1)
+ end
+ if path:find("^/[A-Za-z]:/") then
+ path = path:sub(2)
+ elseif path:find("^/[A-Za-z]:$") then
+ path = path:sub(2) .. "/"
+ end
+ path = path:gsub("/", "\\")
+ return path
+end
+
+function M.make_file_uri (path)
+ path = path:gsub("\\", "/")
+ if path:find("^[A-Za-z]:$") then path = path .. "/" end
+ local _, _, host, hostpath = path:find("^//([A-Za-z0-9.]+)/(.*)$")
+ host = host or ""
+ hostpath = hostpath or path
+ hostpath = hostpath:gsub("//+", "/")
+ hostpath = Util.uri_encode(hostpath, "^A-Za-z0-9%-._~!$&'()*+,;=@/")
+ if not hostpath:find("^/") then hostpath = "/" .. hostpath end
+ return assert(URI:new("file://" .. host .. hostpath))
+end
+
+return M
+-- vi:ts=4 sw=4 expandtab