mirror of
https://github.com/tpope/vim-rhubarb.git
synced 2025-12-07 04:34:27 +08:00
Use native json support when available
This commit is contained in:
@@ -75,6 +75,9 @@ function! s:credentials() abort
|
||||
endfunction
|
||||
|
||||
function! rhubarb#json_parse(string) abort
|
||||
if exists('*json_decode')
|
||||
return json_decode(a:string)
|
||||
endif
|
||||
let [null, false, true] = ['', 0, 1]
|
||||
let stripped = substitute(a:string,'\C"\(\\.\|[^"\\]\)*"','','g')
|
||||
if stripped !~# "[^,:{}\\[\\]0-9.\\-+Eaeflnr-u \n\r\t]"
|
||||
@@ -87,6 +90,9 @@ function! rhubarb#json_parse(string) abort
|
||||
endfunction
|
||||
|
||||
function! rhubarb#json_generate(object) abort
|
||||
if exists('*json_encode')
|
||||
return json_encode(a:object)
|
||||
endif
|
||||
if type(a:object) == type('')
|
||||
return '"' . substitute(a:object, "[\001-\031\"\\\\]", '\=printf("\\u%04x", char2nr(submatch(0)))', 'g') . '"'
|
||||
elseif type(a:object) == type([])
|
||||
|
||||
Reference in New Issue
Block a user