diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2019-08-28 01:56:02 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-08-28 01:56:02 +0200 |
commit | 82d52b229df711b710862ce772603ea55113a32e (patch) | |
tree | c097dd598d961b9090a682cf8267ca615d42b592 /src/nvim/api/private/helpers.c | |
parent | 3c9c64d9dd486598f36c597da1eaffebb3bf4cef (diff) | |
parent | 3157baed83b7e94f2ff92e6fd97e85dab41a1c94 (diff) | |
download | rneovim-82d52b229df711b710862ce772603ea55113a32e.tar.gz rneovim-82d52b229df711b710862ce772603ea55113a32e.tar.bz2 rneovim-82d52b229df711b710862ce772603ea55113a32e.zip |
Merge #4448 'paste: redesign'
fix #3447
fix #3566
fix #7066
fix #7212
fix #7273
fix #7455
fix #10415
NA vim-patches:
vim-patch:8.1.1198
vim-patch:8.1.0224
vim-patch:8.0.1299
vim-patch:8.0.0569
vim-patch:8.0.0303
vim-patch:8.0.0296
vim-patch:8.0.0244
vim-patch:8.0.0238
vim-patch:8.0.0232
vim-patch:8.0.0231
vim-patch:8.0.0230
vim-patch:8.0.0210
Diffstat (limited to 'src/nvim/api/private/helpers.c')
-rw-r--r-- | src/nvim/api/private/helpers.c | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 6b05d1ac0a..3443f85e20 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -745,6 +745,35 @@ String ga_take_string(garray_T *ga) return str; } +/// Creates "readfile()-style" ArrayOf(String). +/// +/// - NUL bytes are replaced with NL (form-feed). +/// - If last line ends with NL an extra empty list item is added. +Array string_to_array(const String input) +{ + Array ret = ARRAY_DICT_INIT; + for (size_t i = 0; i < input.size; i++) { + const char *start = input.data + i; + const char *end = xmemscan(start, NL, input.size - i); + const size_t line_len = (size_t)(end - start); + i += line_len; + + String s = { + .size = line_len, + .data = xmemdupz(start, line_len), + }; + memchrsub(s.data, NUL, NL, line_len); + ADD(ret, STRING_OBJ(s)); + // If line ends at end-of-buffer, add empty final item. + // This is "readfile()-style", see also ":help channel-lines". + if (i + 1 == input.size && end[0] == NL) { + ADD(ret, STRING_OBJ(cchar_to_string(NUL))); + } + } + + return ret; +} + /// Set, tweak, or remove a mapping in a mode. Acts as the implementation for /// functions like @ref nvim_buf_set_keymap. /// |