File: uri.vim

package info (click to toggle)
vim-ale 4.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 8,764 kB
  • sloc: sh: 499; python: 311; perl: 31; makefile: 4; xml: 4; javascript: 1
file content (43 lines) | stat: -rw-r--r-- 913 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
function! s:EncodeChar(char) abort
    let l:result = ''

    for l:index in range(strlen(a:char))
        let l:result .= printf('%%%02x', char2nr(a:char[l:index]))
    endfor

    return l:result
endfunction

function! ale#uri#Encode(value) abort
    return substitute(
    \   a:value,
    \   '\([^a-zA-Z0-9\\/$\-_.!*''(),]\)',
    \   '\=s:EncodeChar(submatch(1))',
    \   'g'
    \)
endfunction

function! ale#uri#Decode(value) abort
    return substitute(
    \   a:value,
    \   '%\(\x\x\)',
    \   '\=printf("%c", str2nr(submatch(1), 16))',
    \   'g'
    \)
endfunction

let s:uri_handlers = {
\   'jdt': {
\       'OpenURILink': function('ale#uri#jdt#OpenJDTLink'),
\   }
\}

function! ale#uri#GetURIHandler(uri) abort
    for l:scheme in keys(s:uri_handlers)
        if a:uri =~# '^'.l:scheme.'://'
            return s:uri_handlers[scheme]
        endif
    endfor

    return v:null
endfunction