diff options
author | Justin M. Keyes <justinkz@gmail.com> | 2018-06-09 09:32:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-06-09 09:32:49 +0200 |
commit | b94b59e4e88411ba7c7802827c872c1ffb896169 (patch) | |
tree | 533d9cc9530fd786faff6769c7225d89ad618bca /src/nvim/api/buffer.c | |
parent | aaece7849259185b116081641890764b6d459376 (diff) | |
download | rneovim-b94b59e4e88411ba7c7802827c872c1ffb896169.tar.gz rneovim-b94b59e4e88411ba7c7802827c872c1ffb896169.tar.bz2 rneovim-b94b59e4e88411ba7c7802827c872c1ffb896169.zip |
refactor: buf_collect_lines (#8509)
Move redundant common logic into a function.
Diffstat (limited to 'src/nvim/api/buffer.c')
-rw-r--r-- | src/nvim/api/buffer.c | 20 |
1 files changed, 3 insertions, 17 deletions
diff --git a/src/nvim/api/buffer.c b/src/nvim/api/buffer.c index 215859a499..e1fe7617ff 100644 --- a/src/nvim/api/buffer.c +++ b/src/nvim/api/buffer.c @@ -238,23 +238,9 @@ ArrayOf(String) nvim_buf_get_lines(uint64_t channel_id, rv.size = (size_t)(end - start); rv.items = xcalloc(sizeof(Object), rv.size); - for (size_t i = 0; i < rv.size; i++) { - int64_t lnum = start + (int64_t)i; - - if (lnum >= MAXLNUM) { - api_set_error(err, kErrorTypeValidation, "Line index is too high"); - goto end; - } - - const char *bufstr = (char *)ml_get_buf(buf, (linenr_T)lnum, false); - Object str = STRING_OBJ(cstr_to_string(bufstr)); - - // Vim represents NULs as NLs, but this may confuse clients. - if (channel_id != VIML_INTERNAL_CALL) { - strchrsub(str.data.string.data, '\n', '\0'); - } - - rv.items[i] = str; + if (!buf_collect_lines(buf, rv.size, start, + (channel_id != VIML_INTERNAL_CALL), &rv, err)) { + goto end; } end: |