diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/eval.c | 3 | ||||
-rw-r--r-- | src/nvim/eval/encode.c | 16 | ||||
-rw-r--r-- | src/nvim/testdir/test_blob.vim | 15 |
3 files changed, 24 insertions, 10 deletions
diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 35c3b1b876..596ed19ff9 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -4089,6 +4089,9 @@ static int eval7( if (blob != NULL) { ga_append(&blob->bv_ga, (hex2nr(*bp) << 4) + hex2nr(*(bp + 1))); } + if (bp[2] == '.' && ascii_isxdigit(bp[3])) { + bp++; + } } if (blob != NULL) { tv_blob_set_ret(rettv, blob); diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index b6b37fce84..1c2274c410 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -324,20 +324,22 @@ int encode_read_from_list(ListReaderState *const state, char *const buf, const blob_T *const blob_ = (blob); \ const int len_ = (len); \ if (len_ == 0) { \ - ga_concat(gap, "[]"); \ + ga_concat(gap, "0z"); \ } else { \ - ga_grow(gap, 1 + len_ * 5); \ - ga_append(gap, '['); \ + /* Allocate space for "0z", the two hex chars per byte, and a */ \ + /* "." separator after every eight hex chars. */ \ + /* Example: "0z00112233.44556677.8899" */ \ + ga_grow(gap, 2 + 2 * len_ + (len_ - 1) / 4); \ + ga_concat(gap, "0z"); \ char numbuf[NUMBUFLEN]; \ for (int i_ = 0; i_ < len_; i_++) { \ - if (i_ > 0) { \ - ga_append(gap, ','); \ + if (i_ > 0 && (i_ & 3) == 0) { \ + ga_append(gap, '.'); \ } \ - vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "0x%02X", \ + vim_snprintf((char *)numbuf, ARRAY_SIZE(numbuf), "%02X", \ (int)tv_blob_get(blob_, i_)); \ ga_concat(gap, numbuf); \ } \ - ga_append(gap, ']'); \ } \ } while (0) diff --git a/src/nvim/testdir/test_blob.vim b/src/nvim/testdir/test_blob.vim index b2b5ddcfd6..dec37f0f10 100644 --- a/src/nvim/testdir/test_blob.vim +++ b/src/nvim/testdir/test_blob.vim @@ -26,6 +26,12 @@ func Test_blob_create() call assert_fails('let b = 0z12345', 'E973:') call assert_equal(0z, v:_null_blob) + + let b = 0z001122.33445566.778899.aabbcc.dd + call assert_equal(0z00112233445566778899aabbccdd, b) + call assert_fails('let b = 0z1.1') + call assert_fails('let b = 0z.') + call assert_fails('let b = 0z001122.') endfunc " assignment to a blob @@ -91,10 +97,13 @@ func Test_blob_get() endfunc func Test_blob_to_string() - let b = 0zDEADBEEF - call assert_equal('[0xDE,0xAD,0xBE,0xEF]', string(b)) + let b = 0z00112233445566778899aabbccdd + call assert_equal('0z00112233.44556677.8899AABB.CCDD', string(b)) + call assert_equal(b, eval(string(b))) + call remove(b, 4, -1) + call assert_equal('0z00112233', string(b)) call remove(b, 0, 3) - call assert_equal('[]', string(b)) + call assert_equal('0z', string(b)) endfunc func Test_blob_compare() |