diff options
author | Daniel Hahler <git@thequod.de> | 2019-06-09 19:06:48 +0200 |
---|---|---|
committer | Daniel Hahler <git@thequod.de> | 2019-08-07 14:21:23 +0200 |
commit | 664b6adebe8b3d12505683a1b7e96d6a2225b86c (patch) | |
tree | 863d354236e3583630b83c4aaed5dd41cdbf8bd3 | |
parent | 1117592f6472c72a71f911009c27e361fcf1eef5 (diff) | |
download | rneovim-664b6adebe8b3d12505683a1b7e96d6a2225b86c.tar.gz rneovim-664b6adebe8b3d12505683a1b7e96d6a2225b86c.tar.bz2 rneovim-664b6adebe8b3d12505683a1b7e96d6a2225b86c.zip |
move ins_bytes, ins_bytes_len
-rw-r--r-- | src/nvim/change.c | 46 | ||||
-rw-r--r-- | src/nvim/misc1.c | 31 |
2 files changed, 21 insertions, 56 deletions
diff --git a/src/nvim/change.c b/src/nvim/change.c index 85051a25c9..18d7af5099 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -477,35 +477,31 @@ unchanged(buf_T *buf, int ff) * Insert string "p" at the cursor position. Stops at a NUL byte. * Handles Replace mode and multi-byte characters. */ - void -ins_bytes(char_u *p) +void ins_bytes(char_u *p) { - ins_bytes_len(p, (int)STRLEN(p)); + ins_bytes_len(p, STRLEN(p)); } -/* - * Insert string "p" with length "len" at the cursor position. - * Handles Replace mode and multi-byte characters. - */ - void -ins_bytes_len(char_u *p, int len) +/// Insert string "p" with length "len" at the cursor position. +/// Handles Replace mode and multi-byte characters. +void ins_bytes_len(char_u *p, size_t len) { - int i; - int n; - - if (has_mbyte) - for (i = 0; i < len; i += n) - { - if (enc_utf8) - // avoid reading past p[len] - n = utfc_ptr2len_len(p + i, len - i); - else - n = (*mb_ptr2len)(p + i); - ins_char_bytes(p + i, n); - } - else - for (i = 0; i < len; ++i) - ins_char(p[i]); + if (has_mbyte) { + size_t n; + for (size_t i = 0; i < len; i += n) { + if (enc_utf8) { + // avoid reading past p[len] + n = (size_t)utfc_ptr2len_len(p + i, (int)(len - i)); + } else { + n = (size_t)(*mb_ptr2len)(p + i); + } + ins_char_bytes(p + i, n); + } + } else { + for (size_t i = 0; i < len; i++) { + ins_char(p[i]); + } + } } /* diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 2ddfbc75ab..76c861e97c 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -1380,37 +1380,6 @@ int plines_m_win(win_T *wp, linenr_T first, linenr_T last) return count; } -/* - * Insert string "p" at the cursor position. Stops at a NUL byte. - * Handles Replace mode and multi-byte characters. - */ -void ins_bytes(char_u *p) -{ - ins_bytes_len(p, STRLEN(p)); -} - -/// Insert string "p" with length "len" at the cursor position. -/// Handles Replace mode and multi-byte characters. -void ins_bytes_len(char_u *p, size_t len) -{ - if (has_mbyte) { - size_t n; - for (size_t i = 0; i < len; i += n) { - if (enc_utf8) { - // avoid reading past p[len] - n = (size_t)utfc_ptr2len_len(p + i, (int)(len - i)); - } else { - n = (size_t)(*mb_ptr2len)(p + i); - } - ins_char_bytes(p + i, n); - } - } else { - for (size_t i = 0; i < len; i++) { - ins_char(p[i]); - } - } -} - /// Insert or replace a single character at the cursor position. /// When in REPLACE or VREPLACE mode, replace any existing character. /// Caller must have prepared for undo. |