aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/mbyte.c
diff options
context:
space:
mode:
authorBjörn Linse <bjorn.linse@gmail.com>2019-03-16 20:41:10 +0100
committerGitHub <noreply@github.com>2019-03-16 20:41:10 +0100
commit5c836d2ef8b6b2a8ad1ea7e4d7e1bf8dd9b1b93d (patch)
tree675dd587937e8661708385e39128ed7b88f9d59f /src/nvim/mbyte.c
parent11a481f711ee2d58c1157e9917779ea424ba3a45 (diff)
parentbe8ebba325451b387c0aedacfcda6c53e6c51188 (diff)
downloadrneovim-5c836d2ef8b6b2a8ad1ea7e4d7e1bf8dd9b1b93d.tar.gz
rneovim-5c836d2ef8b6b2a8ad1ea7e4d7e1bf8dd9b1b93d.tar.bz2
rneovim-5c836d2ef8b6b2a8ad1ea7e4d7e1bf8dd9b1b93d.zip
Merge pull request #9607 from bfredl/wildpum
UI: deprecate redundant ext_wildmenu events and allow TUI popupmenu for cmdline
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r--src/nvim/mbyte.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c
index 5ed2b4c564..6c34cacb8d 100644
--- a/src/nvim/mbyte.c
+++ b/src/nvim/mbyte.c
@@ -555,6 +555,24 @@ size_t mb_string2cells(const char_u *str)
return clen;
}
+/// Get the number of cells occupied by string `str` with maximum length `size`
+///
+/// @param str The source string, may not be NULL, must be a NUL-terminated
+/// string.
+/// @param size maximum length of string. It will terminate on earlier NUL.
+/// @return The number of cells occupied by string `str`
+size_t mb_string2cells_len(const char_u *str, size_t size)
+{
+ size_t clen = 0;
+
+ for (const char_u *p = str; *p != NUL && p < str+size;
+ p += utf_ptr2len_len(p, size+(p-str))) {
+ clen += utf_ptr2cells(p);
+ }
+
+ return clen;
+}
+
/// Convert a UTF-8 byte sequence to a wide character
///
/// If the sequence is illegal or truncated by a NUL then the first byte is