aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/uri.lua
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/lua/vim/uri.lua')
-rw-r--r--runtime/lua/vim/uri.lua36
1 files changed, 19 insertions, 17 deletions
diff --git a/runtime/lua/vim/uri.lua b/runtime/lua/vim/uri.lua
index 11b661cd1a..d6b0b7410e 100644
--- a/runtime/lua/vim/uri.lua
+++ b/runtime/lua/vim/uri.lua
@@ -3,7 +3,6 @@
-- https://tools.ietf.org/html/rfc2732
-- https://tools.ietf.org/html/rfc2396
-
local uri_decode
do
local schar = string.char
@@ -14,7 +13,7 @@ do
return schar(tonumber(hex, 16))
end
uri_decode = function(str)
- return str:gsub("%%([a-fA-F0-9][a-fA-F0-9])", hex_to_char)
+ return str:gsub('%%([a-fA-F0-9][a-fA-F0-9])', hex_to_char)
end
end
@@ -23,33 +22,36 @@ do
local PATTERNS = {
--- RFC 2396
-- https://tools.ietf.org/html/rfc2396#section-2.2
- rfc2396 = "^A-Za-z0-9%-_.!~*'()";
+ rfc2396 = "^A-Za-z0-9%-_.!~*'()",
--- RFC 2732
-- https://tools.ietf.org/html/rfc2732
- rfc2732 = "^A-Za-z0-9%-_.!~*'()[]";
+ rfc2732 = "^A-Za-z0-9%-_.!~*'()[]",
--- RFC 3986
-- https://tools.ietf.org/html/rfc3986#section-2.2
- rfc3986 = "^A-Za-z0-9%-._~!$&'()*+,;=:@/";
+ rfc3986 = "^A-Za-z0-9%-._~!$&'()*+,;=:@/",
}
local sbyte, tohex = string.byte
if jit then
- tohex = require'bit'.tohex
+ tohex = require('bit').tohex
else
- tohex = function(b) return string.format("%02x", b) end
+ tohex = function(b)
+ return string.format('%02x', b)
+ end
end
---@private
local function percent_encode_char(char)
- return "%"..tohex(sbyte(char), 2)
+ return '%' .. tohex(sbyte(char), 2)
end
uri_encode = function(text, rfc)
- if not text then return end
+ if not text then
+ return
+ end
local pattern = PATTERNS[rfc] or PATTERNS.rfc3986
- return text:gsub("(["..pattern.."])", percent_encode_char)
+ return text:gsub('([' .. pattern .. '])', percent_encode_char)
end
end
-
---@private
local function is_windows_file_uri(uri)
return uri:match('^file:/+[a-zA-Z]:') ~= nil
@@ -59,16 +61,16 @@ end
---@param path string Path to file
---@return string URI
local function uri_from_fname(path)
- local volume_path, fname = path:match("^([a-zA-Z]:)(.*)")
+ local volume_path, fname = path:match('^([a-zA-Z]:)(.*)')
local is_windows = volume_path ~= nil
if is_windows then
- path = volume_path..uri_encode(fname:gsub("\\", "/"))
+ path = volume_path .. uri_encode(fname:gsub('\\', '/'))
else
path = uri_encode(path)
end
- local uri_parts = {"file://"}
+ local uri_parts = { 'file://' }
if is_windows then
- table.insert(uri_parts, "/")
+ table.insert(uri_parts, '/')
end
table.insert(uri_parts, path)
return table.concat(uri_parts)
@@ -82,11 +84,11 @@ local WINDOWS_URI_SCHEME_PATTERN = '^([a-zA-Z]+[a-zA-Z0-9.+-]*):[a-zA-Z]:.*'
---@return string URI
local function uri_from_bufnr(bufnr)
local fname = vim.api.nvim_buf_get_name(bufnr)
- local volume_path = fname:match("^([a-zA-Z]:).*")
+ local volume_path = fname:match('^([a-zA-Z]:).*')
local is_windows = volume_path ~= nil
local scheme
if is_windows then
- fname = fname:gsub("\\", "/")
+ fname = fname:gsub('\\', '/')
scheme = fname:match(WINDOWS_URI_SCHEME_PATTERN)
else
scheme = fname:match(URI_SCHEME_PATTERN)