diff options
author | zeertzjq <zeertzjq@outlook.com> | 2022-05-12 22:59:09 +0800 |
---|---|---|
committer | zeertzjq <zeertzjq@outlook.com> | 2022-05-12 23:07:35 +0800 |
commit | 274f260806efe0008cde0fd1c3bc64e7655eb89f (patch) | |
tree | bf105c808694a6bbba6a866d95cab3780c994b30 /src/nvim/mbyte.c | |
parent | 8fba428bc6f36ae038a9286517e15b33257a1359 (diff) | |
download | rneovim-274f260806efe0008cde0fd1c3bc64e7655eb89f.tar.gz rneovim-274f260806efe0008cde0fd1c3bc64e7655eb89f.tar.bz2 rneovim-274f260806efe0008cde0fd1c3bc64e7655eb89f.zip |
vim-patch:8.2.4919: can add invalid bytes with :spellgood
Problem: Can add invalid bytes with :spellgood.
Solution: Check for a valid word string.
https://github.com/vim/vim/commit/7c824682d2028432ee082703ef0ab399867a089b
Diffstat (limited to 'src/nvim/mbyte.c')
-rw-r--r-- | src/nvim/mbyte.c | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 1d65529b75..37b4af5172 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -1992,6 +1992,31 @@ theend: convert_setup(&vimconv, NULL, NULL); } +/// @return true if string "s" is a valid utf-8 string. +/// When "end" is NULL stop at the first NUL. +/// When "end" is positive stop there. +bool utf_valid_string(const char_u *s, const char_u *end) +{ + const char_u *p = s; + + while (end == NULL ? *p != NUL : p < end) { + int l = utf8len_tab_zero[*p]; + if (l == 0) { + return false; // invalid lead byte + } + if (end != NULL && p + l > end) { + return false; // incomplete byte sequence + } + p++; + while (--l > 0) { + if ((*p++ & 0xc0) != 0x80) { + return false; // invalid trail byte + } + } + } + return true; +} + /* * If the cursor moves on an trail byte, set the cursor on the lead byte. * Thus it moves left if necessary. |