comparison src/mbyte.c @ 34431:cffcacc1502a v9.1.0137

patch 9.1.0137: <Del> in cmdline mode doesn't delete composing chars Commit: https://github.com/vim/vim/commit/ff2b79d23956263ab0120623c37e0b4498be01db Author: zeertzjq <zeertzjq@outlook.com> Date: Mon Feb 26 20:38:36 2024 +0100 patch 9.1.0137: <Del> in cmdline mode doesn't delete composing chars Problem: <Del> in cmdline mode doesn't delete composing chars Solution: Use mb_head_off() and mb_ptr2len() (zeertzjq) closes: #14095 Signed-off-by: zeertzjq <zeertzjq@outlook.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
author Christian Brabandt <cb@256bit.org>
date Mon, 26 Feb 2024 20:45:04 +0100
parents d2ad8733db75
children 9e093c96dff6
comparison
equal deleted inserted replaced
34430:8d14e400cd20 34431:cffcacc1502a
4186 * character. Can start anywhere in a stream of bytes. 4186 * character. Can start anywhere in a stream of bytes.
4187 */ 4187 */
4188 int 4188 int
4189 mb_off_next(char_u *base, char_u *p) 4189 mb_off_next(char_u *base, char_u *p)
4190 { 4190 {
4191 int i; 4191 int head_off = (*mb_head_off)(base, p);
4192 int j; 4192
4193 4193 if (head_off == 0)
4194 if (enc_utf8) 4194 return 0;
4195 { 4195
4196 if (*p < 0x80) // be quick for ASCII 4196 return (*mb_ptr2len)(p - head_off) - head_off;
4197 return 0;
4198
4199 // Find the next character that isn't 10xx.xxxx
4200 for (i = 0; (p[i] & 0xc0) == 0x80; ++i)
4201 ;
4202 if (i > 0)
4203 {
4204 // Check for illegal sequence.
4205 for (j = 0; p - j > base; ++j)
4206 if ((p[-j] & 0xc0) != 0x80)
4207 break;
4208 if (utf8len_tab[p[-j]] != i + j)
4209 return 0;
4210 }
4211 return i;
4212 }
4213
4214 // Only need to check if we're on a trail byte, it doesn't matter if we
4215 // want the offset to the next or current character.
4216 return (*mb_head_off)(base, p);
4217 } 4197 }
4218 4198
4219 /* 4199 /*
4220 * Return the offset from "p" to the last byte of the character it points 4200 * Return the offset from "p" to the last byte of the character it points
4221 * into. Can start anywhere in a stream of bytes. 4201 * into. Can start anywhere in a stream of bytes.