aboutsummaryrefslogtreecommitdiff
path: root/runtime/autoload/msgpack.vim
diff options
context:
space:
mode:
Diffstat (limited to 'runtime/autoload/msgpack.vim')
-rw-r--r--runtime/autoload/msgpack.vim50
1 files changed, 24 insertions, 26 deletions
diff --git a/runtime/autoload/msgpack.vim b/runtime/autoload/msgpack.vim
index 18dcd1e6a6..fb438def4f 100644
--- a/runtime/autoload/msgpack.vim
+++ b/runtime/autoload/msgpack.vim
@@ -361,7 +361,7 @@ endfunction
let s:MSGPACK_STANDARD_TYPES = {
\type(0): 'integer',
\type(0.0): 'float',
- \type(''): 'binary',
+ \type(''): 'string',
\type([]): 'array',
\type({}): 'map',
\type(v:true): 'boolean',
@@ -412,9 +412,15 @@ endfunction
""
" Dump |msgpack-special-dict| that represents a string. If any additional
" parameter is given then it dumps binary string.
-function s:msgpack_dump_string(v, ...) abort
- let ret = [a:0 ? '"' : '="']
- for v in a:v._VAL
+function s:msgpack_dump_string(v) abort
+ if type(a:v) == type({})
+ let val = a:v
+ else
+ let val = {'_VAL': split(a:v, "\n", 1)}
+ end
+
+ let ret = ['"']
+ for v in val._VAL
call add(
\ret,
\substitute(
@@ -427,16 +433,6 @@ function s:msgpack_dump_string(v, ...) abort
endfunction
""
-" Dump binary string.
-function s:msgpack_dump_binary(v) abort
- if type(a:v) == type({})
- return s:msgpack_dump_string(a:v, 1)
- else
- return s:msgpack_dump_string({'_VAL': split(a:v, "\n", 1)}, 1)
- endif
-endfunction
-
-""
" Dump array value.
function s:msgpack_dump_array(v) abort
let val = type(a:v) == type({}) ? a:v._VAL : a:v
@@ -449,7 +445,7 @@ function s:msgpack_dump_map(v) abort
let ret = ['{']
if msgpack#special_type(a:v) is 0
for [k, v] in items(a:v)
- let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n", 1)}),
+ let ret += [s:msgpack_dump_string({'_VAL': split(k, "\n")}),
\': ',
\msgpack#string(v),
\', ']
@@ -479,7 +475,7 @@ endfunction
" Dump extension value.
function s:msgpack_dump_ext(v) abort
return printf('+(%i)%s', a:v._VAL[0],
- \s:msgpack_dump_string({'_VAL': a:v._VAL[1]}, 1))
+ \s:msgpack_dump_string({'_VAL': a:v._VAL[1]}))
endfunction
""
@@ -619,9 +615,7 @@ function msgpack#eval(s, special_objs) abort
throw '"-invalid:Invalid string: ' . s
endif
call add(expr, '{''_TYPE'': v:msgpack_types.')
- if empty(match[1])
- call add(expr, 'binary')
- elseif match[1] is# '='
+ if empty(match[1]) || match[1] is# '='
call add(expr, 'string')
else
call add(expr, 'ext')
@@ -772,7 +766,7 @@ function msgpack#equal(a, b)
let a = aspecial is 0 ? a:a : a:a._VAL
let b = bspecial is 0 ? a:b : a:b._VAL
return msgpack#equal(a, b)
- elseif atype is# 'binary'
+ elseif atype is# 'string'
let a = (aspecial is 0 ? split(a:a, "\n", 1) : a:a._VAL)
let b = (bspecial is 0 ? split(a:b, "\n", 1) : a:b._VAL)
return a ==# b
@@ -787,13 +781,17 @@ function msgpack#equal(a, b)
" Non-special mapping cannot have non-string keys
return 0
endif
- if (empty(k._VAL)
- \|| k._VAL ==# [""]
- \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
- " Non-special mapping cannot have zero byte in key or an empty key
- return 0
+ if type(k) == type({})
+ if (empty(k._VAL)
+ \|| k._VAL ==# [""]
+ \|| !empty(filter(copy(k._VAL), 'stridx(v:val, "\n") != -1')))
+ " Non-special mapping cannot have zero byte in key or an empty key
+ return 0
+ endif
+ let kstr = join(k._VAL, "\n")
+ else
+ let kstr = k
endif
- let kstr = join(k._VAL, "\n")
if !has_key(akeys, kstr)
" Protects from both missing and duplicate keys
return 0