refactor: replace char_u variables and functions with char

Work on https://github.com/neovim/neovim/issues/459
This commit is contained in:
Dundar Goc 2022-05-04 22:35:50 +02:00
parent d9ec57e16a
commit 2a378e6e82
51 changed files with 508 additions and 506 deletions

View File

@ -584,7 +584,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer
String c = opts->conceal.data.string; String c = opts->conceal.data.string;
decor.conceal = true; decor.conceal = true;
if (c.size) { if (c.size) {
decor.conceal_char = utf_ptr2char((const char_u *)c.data); decor.conceal_char = utf_ptr2char(c.data);
} }
} else if (HAS_KEY(opts->conceal)) { } else if (HAS_KEY(opts->conceal)) {
api_set_error(err, kErrorTypeValidation, "conceal is not a String"); api_set_error(err, kErrorTypeValidation, "conceal is not a String");

View File

@ -654,9 +654,9 @@ void modify_keymap(uint64_t channel_id, Buffer buffer, bool is_unmap, String mod
int mode_val; // integer value of the mapping mode, to be passed to do_map() int mode_val; // integer value of the mapping mode, to be passed to do_map()
char *p = (mode.size) ? mode.data : "m"; char *p = (mode.size) ? mode.data : "m";
if (STRNCMP(p, "!", 2) == 0) { if (STRNCMP(p, "!", 2) == 0) {
mode_val = get_map_mode((char_u **)&p, true); // mapmode-ic mode_val = get_map_mode(&p, true); // mapmode-ic
} else { } else {
mode_val = get_map_mode((char_u **)&p, false); mode_val = get_map_mode(&p, false);
if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING) if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING)
&& mode.size > 0) { && mode.size > 0) {
// get_map_mode() treats unrecognized mode shortnames as ":map". // get_map_mode() treats unrecognized mode shortnames as ":map".
@ -1128,7 +1128,7 @@ ArrayOf(Dictionary) keymap_array(String mode, buf_T *buf, bool from_lua)
// Convert the string mode to the integer mode // Convert the string mode to the integer mode
// that is stored within each mapblock // that is stored within each mapblock
char_u *p = (char_u *)mode.data; char *p = mode.data;
int int_mode = get_map_mode(&p, 0); int int_mode = get_map_mode(&p, 0);
// Determine the desired buffer value // Determine the desired buffer value
@ -1666,11 +1666,11 @@ int init_sign_text(char **sign_text, char *text)
// Count cells and check for non-printable chars // Count cells and check for non-printable chars
int cells = 0; int cells = 0;
for (s = text; s < endp; s += utfc_ptr2len((char_u *)s)) { for (s = text; s < endp; s += utfc_ptr2len(s)) {
if (!vim_isprintc(utf_ptr2char((char_u *)s))) { if (!vim_isprintc(utf_ptr2char(s))) {
break; break;
} }
cells += utf_ptr2cells((char_u *)s); cells += utf_ptr2cells(s);
} }
// Currently must be empty, one or two display cells // Currently must be empty, one or two display cells
if (s != endp || cells > 2) { if (s != endp || cells > 2) {

View File

@ -665,7 +665,7 @@ static void remote_ui_raw_line(UI *ui, Integer grid, Integer row, Integer startc
remote_ui_cursor_goto(ui, row, startcol + i); remote_ui_cursor_goto(ui, row, startcol + i);
remote_ui_highlight_set(ui, attrs[i]); remote_ui_highlight_set(ui, attrs[i]);
remote_ui_put(ui, (const char *)chunk[i]); remote_ui_put(ui, (const char *)chunk[i]);
if (utf_ambiguous_width(utf_ptr2char(chunk[i]))) { if (utf_ambiguous_width(utf_ptr2char((char *)chunk[i]))) {
data->client_col = -1; // force cursor update data->client_col = -1; // force cursor update
} }
} }

View File

@ -2287,12 +2287,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error *
if (HAS_KEY(opts->fillchar)) { if (HAS_KEY(opts->fillchar)) {
if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0 if (opts->fillchar.type != kObjectTypeString || opts->fillchar.data.string.size == 0
|| ((size_t)utf_ptr2len((char_u *)opts->fillchar.data.string.data) || ((size_t)utf_ptr2len(opts->fillchar.data.string.data)
!= opts->fillchar.data.string.size)) { != opts->fillchar.data.string.size)) {
api_set_error(err, kErrorTypeValidation, "fillchar must be a single character"); api_set_error(err, kErrorTypeValidation, "fillchar must be a single character");
return result; return result;
} }
fillchar = utf_ptr2char((char_u *)opts->fillchar.data.string.data); fillchar = utf_ptr2char(opts->fillchar.data.string.data);
} }
if (HAS_KEY(opts->highlights)) { if (HAS_KEY(opts->highlights)) {

View File

@ -3456,7 +3456,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
wp->w_cursor.coladd = 0; wp->w_cursor.coladd = 0;
byteval = 0; byteval = 0;
} else { } else {
byteval = utf_ptr2char(line_ptr + wp->w_cursor.col); byteval = utf_ptr2char((char *)line_ptr + wp->w_cursor.col);
} }
int groupdepth = 0; int groupdepth = 0;
@ -3616,7 +3616,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
long n = 0; long n = 0;
while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) { while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) {
group_len -= ptr2cells(t + n); group_len -= ptr2cells(t + n);
n += utfc_ptr2len(t + n); n += utfc_ptr2len((char *)t + n);
} }
// } // }
@ -4176,7 +4176,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
if (l > maxwid) { if (l > maxwid) {
while (l >= maxwid) { while (l >= maxwid) {
l -= ptr2cells(t); l -= ptr2cells(t);
t += utfc_ptr2len(t); t += utfc_ptr2len((char *)t);
} }
// Early out if there isn't enough room for the truncation marker // Early out if there isn't enough room for the truncation marker
@ -4374,7 +4374,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
// Note: Only advance the pointer if the next // Note: Only advance the pointer if the next
// character will fit in the available output space // character will fit in the available output space
trunc_p += utfc_ptr2len(trunc_p); trunc_p += utfc_ptr2len((char *)trunc_p);
} }
// Ignore any items in the statusline that occur after // Ignore any items in the statusline that occur after
@ -4396,7 +4396,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
long trunc_len = 0; long trunc_len = 0;
while (width >= maxwidth) { while (width >= maxwidth) {
width -= ptr2cells(trunc_p + trunc_len); width -= ptr2cells(trunc_p + trunc_len);
trunc_len += utfc_ptr2len(trunc_p + trunc_len); trunc_len += utfc_ptr2len((char *)trunc_p + trunc_len);
} }
// } // }

View File

@ -599,7 +599,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
if (vcol > new_vcol && oldp[col + oldlen] == TAB) { if (vcol > new_vcol && oldp[col + oldlen] == TAB) {
break; break;
} }
oldlen += (size_t)utfc_ptr2len(oldp + col + oldlen); oldlen += (size_t)utfc_ptr2len((char *)oldp + col + oldlen);
// Deleted a bit too much, insert spaces. // Deleted a bit too much, insert spaces.
if (vcol > new_vcol) { if (vcol > new_vcol) {
newlen += (size_t)(vcol - new_vcol); newlen += (size_t)(vcol - new_vcol);
@ -608,7 +608,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
curwin->w_p_list = old_list; curwin->w_p_list = old_list;
} else if (oldp[col] != NUL) { } else if (oldp[col] != NUL) {
// normal replace // normal replace
oldlen = (size_t)utfc_ptr2len(oldp + col); oldlen = (size_t)utfc_ptr2len((char *)oldp + col);
} }
@ -655,7 +655,7 @@ void ins_char_bytes(char_u *buf, size_t charlen)
if (p_sm && (State & INSERT) if (p_sm && (State & INSERT)
&& msg_silent == 0 && msg_silent == 0
&& !ins_compl_active()) { && !ins_compl_active()) {
showmatch(utf_ptr2char(buf)); showmatch(utf_ptr2char((char *)buf));
} }
if (!p_ri || (State & REPLACE_FLAG)) { if (!p_ri || (State & REPLACE_FLAG)) {
@ -715,7 +715,7 @@ int del_chars(long count, int fixpos)
int bytes = 0; int bytes = 0;
char_u *p = get_cursor_pos_ptr(); char_u *p = get_cursor_pos_ptr();
for (long i = 0; i < count && *p != NUL; i++) { for (long i = 0; i < count && *p != NUL; i++) {
int l = utfc_ptr2len(p); int l = utfc_ptr2len((char *)p);
bytes += l; bytes += l;
p += l; p += l;
} }
@ -756,7 +756,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
// If 'delcombine' is set and deleting (less than) one character, only // If 'delcombine' is set and deleting (less than) one character, only
// delete the last combining character. // delete the last combining character.
if (p_deco && use_delcombine if (p_deco && use_delcombine
&& utfc_ptr2len(oldp + col) >= count) { && utfc_ptr2len((char *)oldp + col) >= count) {
int cc[MAX_MCO]; int cc[MAX_MCO];
(void)utfc_ptr2char(oldp + col, cc); (void)utfc_ptr2char(oldp + col, cc);
@ -765,7 +765,7 @@ int del_bytes(colnr_T count, bool fixpos_arg, bool use_delcombine)
int n = col; int n = col;
do { do {
col = n; col = n;
count = utf_ptr2len(oldp + n); count = utf_ptr2len((char *)oldp + n);
n += count; n += count;
} while (utf_composinglike(oldp + col, oldp + n)); } while (utf_composinglike(oldp + col, oldp + n));
fixpos = false; fixpos = false;
@ -1436,7 +1436,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
int l; int l;
for (i = 0; i < lead_len && p[i] != NUL; i += l) { for (i = 0; i < lead_len && p[i] != NUL; i += l) {
l = utfc_ptr2len(p + i); l = utfc_ptr2len((char *)p + i);
if (vim_strnsize(p, i + l) > repl_size) { if (vim_strnsize(p, i + l) > repl_size) {
break; break;
} }
@ -1459,7 +1459,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
lead_len--; lead_len--;
memmove(p, p + 1, (size_t)(leader + lead_len - p)); memmove(p, p + 1, (size_t)(leader + lead_len - p));
} else { } else {
int l = utfc_ptr2len(p); int l = utfc_ptr2len((char *)p);
if (l > 1) { if (l > 1) {
if (ptr2cells(p) > 1) { if (ptr2cells(p) > 1) {
@ -1565,7 +1565,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment)
} }
if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) {
while ((*p_extra == ' ' || *p_extra == '\t') while ((*p_extra == ' ' || *p_extra == '\t')
&& !utf_iscomposing(utf_ptr2char(p_extra + 1))) { && !utf_iscomposing(utf_ptr2char((char *)p_extra + 1))) {
if (REPLACE_NORMAL(State)) { if (REPLACE_NORMAL(State)) {
replace_push(*p_extra); replace_push(*p_extra);
} }

View File

@ -275,7 +275,7 @@ void trans_characters(char_u *buf, int bufsize)
while (*buf != 0) { while (*buf != 0) {
int trs_len; // length of trs[] int trs_len; // length of trs[]
// Assume a multi-byte character doesn't need translation. // Assume a multi-byte character doesn't need translation.
if ((trs_len = utfc_ptr2len(buf)) > 1) { if ((trs_len = utfc_ptr2len((char *)buf)) > 1) {
len -= trs_len; len -= trs_len;
} else { } else {
trs = transchar_byte(*buf); trs = transchar_byte(*buf);
@ -311,7 +311,7 @@ size_t transstr_len(const char *const s, bool untab)
size_t len = 0; size_t len = 0;
while (*p) { while (*p) {
const size_t l = (size_t)utfc_ptr2len((const char_u *)p); const size_t l = (size_t)utfc_ptr2len(p);
if (l > 1) { if (l > 1) {
int pcc[MAX_MCO + 1]; int pcc[MAX_MCO + 1];
pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]); pcc[0] = utfc_ptr2char((const char_u *)p, &pcc[1]);
@ -354,7 +354,7 @@ size_t transstr_buf(const char *const s, char *const buf, const size_t len, bool
char *const buf_e = buf_p + len - 1; char *const buf_e = buf_p + len - 1;
while (*p != NUL && buf_p < buf_e) { while (*p != NUL && buf_p < buf_e) {
const size_t l = (size_t)utfc_ptr2len((const char_u *)p); const size_t l = (size_t)utfc_ptr2len(p);
if (l > 1) { if (l > 1) {
if (buf_p + l > buf_e) { if (buf_p + l > buf_e) {
break; // Exceeded `buf` size. break; // Exceeded `buf` size.
@ -424,7 +424,7 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
int i; int i;
int len = orglen; int len = orglen;
#define GA_CHAR(i) ((char_u *)ga.ga_data)[i] #define GA_CHAR(i) ((char *)ga.ga_data)[i]
#define GA_PTR(i) ((char_u *)ga.ga_data + (i)) #define GA_PTR(i) ((char_u *)ga.ga_data + (i))
#define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i]) #define STR_CHAR(i) (buf == NULL ? GA_CHAR(i) : buf[i])
#define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + (i)) #define STR_PTR(i) (buf == NULL ? GA_PTR(i) : buf + (i))
@ -453,8 +453,8 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
// Make each character lower case. // Make each character lower case.
i = 0; i = 0;
while (STR_CHAR(i) != NUL) { while (STR_CHAR(i) != NUL) {
int c = utf_ptr2char(STR_PTR(i)); int c = utf_ptr2char((char *)STR_PTR(i));
int olen = utf_ptr2len(STR_PTR(i)); int olen = utf_ptr2len((char *)STR_PTR(i));
int lc = mb_tolower(c); int lc = mb_tolower(c);
// Only replace the character when it is not an invalid // Only replace the character when it is not an invalid
@ -492,7 +492,7 @@ char_u *str_foldcase(char_u *str, int orglen, char_u *buf, int buflen)
} }
// skip to next multi-byte char // skip to next multi-byte char
i += utfc_ptr2len(STR_PTR(i)); i += utfc_ptr2len((char *)STR_PTR(i));
} }
@ -693,7 +693,7 @@ int ptr2cells(const char_u *p)
{ {
// For UTF-8 we need to look at more bytes if the first byte is >= 0x80. // For UTF-8 we need to look at more bytes if the first byte is >= 0x80.
if (*p >= 0x80) { if (*p >= 0x80) {
return utf_ptr2cells(p); return utf_ptr2cells((char *)p);
} }
// For DBCS we can tell the cell count from the first byte. // For DBCS we can tell the cell count from the first byte.
@ -727,7 +727,7 @@ int vim_strnsize(char_u *s, int len)
assert(s != NULL); assert(s != NULL);
int size = 0; int size = 0;
while (*s != NUL && --len >= 0) { while (*s != NUL && --len >= 0) {
int l = utfc_ptr2len(s); int l = utfc_ptr2len((char *)s);
size += ptr2cells(s); size += ptr2cells(s);
s += l; s += l;
len -= l - 1; len -= l - 1;
@ -806,7 +806,7 @@ bool vim_iswordp_buf(const char_u *const p, buf_T *const buf)
int c = *p; int c = *p;
if (MB_BYTE2LEN(c) > 1) { if (MB_BYTE2LEN(c) > 1) {
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
} }
return vim_iswordc_buf(c, buf); return vim_iswordc_buf(c, buf);
} }
@ -957,7 +957,7 @@ void getvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *en
// For utf-8, if the byte is >= 0x80, need to look at // For utf-8, if the byte is >= 0x80, need to look at
// further bytes to find the cell width. // further bytes to find the cell width.
if (c >= 0x80) { if (c >= 0x80) {
incr = utf_ptr2cells(ptr); incr = utf_ptr2cells((char *)ptr);
} else { } else {
incr = g_chartab[c] & CT_CELL_MASK; incr = g_chartab[c] & CT_CELL_MASK;
} }
@ -1070,7 +1070,7 @@ void getvvcol(win_T *wp, pos_T *pos, colnr_T *start, colnr_T *cursor, colnr_T *e
char_u *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false); char_u *ptr = ml_get_buf(wp->w_buffer, pos->lnum, false);
if (pos->col < (colnr_T)STRLEN(ptr)) { if (pos->col < (colnr_T)STRLEN(ptr)) {
int c = utf_ptr2char(ptr + pos->col); int c = utf_ptr2char((char *)ptr + pos->col);
if ((c != TAB) && vim_isprintc(c)) { if ((c != TAB) && vim_isprintc(c)) {
endadd = (colnr_T)(char2cells(c) - 1); endadd = (colnr_T)(char2cells(c) - 1);
if (coladd > endadd) { if (coladd > endadd) {

View File

@ -459,7 +459,7 @@ bool leftcol_changed(void)
int gchar_cursor(void) int gchar_cursor(void)
{ {
return utf_ptr2char(get_cursor_pos_ptr()); return utf_ptr2char((char *)get_cursor_pos_ptr());
} }
/// Write a character at the current cursor position. /// Write a character at the current cursor position.

View File

@ -750,10 +750,10 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din)
c = NUL; c = NUL;
} else { } else {
// xdiff doesn't support ignoring case, fold-case the text. // xdiff doesn't support ignoring case, fold-case the text.
c = utf_ptr2char(s); c = utf_ptr2char((char *)s);
c = utf_fold(c); c = utf_fold(c);
} }
const int orig_len = utfc_ptr2len(s); const int orig_len = utfc_ptr2len((char *)s);
if (utf_char2bytes(c, cbuf) != orig_len) { if (utf_char2bytes(c, cbuf) != orig_len) {
// TODO(Bram): handle byte length difference // TODO(Bram): handle byte length difference
memmove(ptr + len, s, (size_t)orig_len); memmove(ptr + len, s, (size_t)orig_len);
@ -1937,15 +1937,15 @@ static bool diff_equal_entry(diff_T *dp, int idx1, int idx2)
// ignoring case) return true and set "len" to the number of bytes. // ignoring case) return true and set "len" to the number of bytes.
static bool diff_equal_char(const char_u *const p1, const char_u *const p2, int *const len) static bool diff_equal_char(const char_u *const p1, const char_u *const p2, int *const len)
{ {
const int l = utfc_ptr2len(p1); const int l = utfc_ptr2len((char *)p1);
if (l != utfc_ptr2len(p2)) { if (l != utfc_ptr2len((char *)p2)) {
return false; return false;
} }
if (l > 1) { if (l > 1) {
if (STRNCMP(p1, p2, l) != 0 if (STRNCMP(p1, p2, l) != 0
&& (!(diff_flags & DIFF_ICASE) && (!(diff_flags & DIFF_ICASE)
|| utf_fold(utf_ptr2char(p1)) != utf_fold(utf_ptr2char(p2)))) { || utf_fold(utf_ptr2char((char *)p1)) != utf_fold(utf_ptr2char((char *)p2)))) {
return false; return false;
} }
*len = l; *len = l;

View File

@ -440,7 +440,7 @@ static void insert_enter(InsertState *s)
if (s->ptr[1] == NUL) { if (s->ptr[1] == NUL) {
curwin->w_cursor.col++; curwin->w_cursor.col++;
} else { } else {
s->i = utfc_ptr2len(s->ptr); s->i = utfc_ptr2len((char *)s->ptr);
if (s->ptr[s->i] == NUL) { if (s->ptr[s->i] == NUL) {
curwin->w_cursor.col += s->i; curwin->w_cursor.col += s->i;
} }
@ -727,7 +727,7 @@ static int insert_execute(VimState *state, int key)
if (str != NULL) { if (str != NULL) {
for (p = str; *p != NUL; MB_PTR_ADV(p)) { for (p = str; *p != NUL; MB_PTR_ADV(p)) {
ins_compl_addleader(utf_ptr2char(p)); ins_compl_addleader(utf_ptr2char((char *)p));
} }
xfree(str); xfree(str);
} else { } else {
@ -1332,7 +1332,7 @@ normalchar:
if (*str != NUL && stop_arrow() != FAIL) { if (*str != NUL && stop_arrow() != FAIL) {
// Insert the new value of v:char literally. // Insert the new value of v:char literally.
for (p = str; *p != NUL; MB_PTR_ADV(p)) { for (p = str; *p != NUL; MB_PTR_ADV(p)) {
s->c = utf_ptr2char(p); s->c = utf_ptr2char((char *)p);
if (s->c == CAR || s->c == K_KENTER || s->c == NL) { if (s->c == CAR || s->c == K_KENTER || s->c == NL) {
ins_eol(s->c); ins_eol(s->c);
} else { } else {
@ -1891,7 +1891,7 @@ void change_indent(int type, int amount, int round, int replaced, int call_chang
while (vcol <= (int)curwin->w_virtcol) { while (vcol <= (int)curwin->w_virtcol) {
last_vcol = vcol; last_vcol = vcol;
if (new_cursor_col >= 0) { if (new_cursor_col >= 0) {
new_cursor_col += utfc_ptr2len(ptr + new_cursor_col); new_cursor_col += utfc_ptr2len((char *)ptr + new_cursor_col);
} else { } else {
new_cursor_col++; new_cursor_col++;
} }
@ -2061,7 +2061,7 @@ static bool del_char_after_col(int limit_col)
// composing character. // composing character.
mb_adjust_cursor(); mb_adjust_cursor();
while (curwin->w_cursor.col < (colnr_T)limit_col) { while (curwin->w_cursor.col < (colnr_T)limit_col) {
int l = utf_ptr2len(get_cursor_pos_ptr()); int l = utf_ptr2len((char *)get_cursor_pos_ptr());
if (l == 0) { // end of line if (l == 0) { // end of line
break; break;
@ -2566,8 +2566,8 @@ static void ins_compl_longest_match(compl_T *match)
p = compl_leader; p = compl_leader;
s = match->cp_str; s = match->cp_str;
while (*p != NUL) { while (*p != NUL) {
c1 = utf_ptr2char(p); c1 = utf_ptr2char((char *)p);
c2 = utf_ptr2char(s); c2 = utf_ptr2char((char *)s);
if ((match->cp_flags & CP_ICASE) if ((match->cp_flags & CP_ICASE)
? (mb_tolower(c1) != mb_tolower(c2)) ? (mb_tolower(c1) != mb_tolower(c2))
@ -3108,7 +3108,7 @@ static void ins_compl_files(int count, char_u **files, int thesaurus, int flags,
// different classes, only separate words // different classes, only separate words
// with single-byte non-word characters. // with single-byte non-word characters.
while (*ptr != NUL) { while (*ptr != NUL) {
const int l = utfc_ptr2len(ptr); const int l = utfc_ptr2len((char *)ptr);
if (l < 2 && !vim_iswordc(*ptr)) { if (l < 2 && !vim_iswordc(*ptr)) {
break; break;
@ -3150,7 +3150,7 @@ char_u *find_word_start(char_u *ptr)
FUNC_ATTR_PURE FUNC_ATTR_PURE
{ {
while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) { while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) {
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
} }
return ptr; return ptr;
} }
@ -3165,7 +3165,7 @@ char_u *find_word_end(char_u *ptr)
const int start_class = mb_get_class(ptr); const int start_class = mb_get_class(ptr);
if (start_class > 1) { if (start_class > 1) {
while (*ptr != NUL) { while (*ptr != NUL) {
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
if (mb_get_class(ptr) != start_class) { if (mb_get_class(ptr) != start_class) {
break; break;
} }
@ -3602,7 +3602,7 @@ static void ins_compl_addfrommatch(void)
} }
} }
p += len; p += len;
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
ins_compl_addleader(c); ins_compl_addleader(c);
} }
@ -5251,10 +5251,10 @@ static int ins_complete(int c, bool enable_pum)
char_u *p = line + startcol; char_u *p = line + startcol;
MB_PTR_BACK(line, p); MB_PTR_BACK(line, p);
while (p > line && vim_isfilec(utf_ptr2char(p))) { while (p > line && vim_isfilec(utf_ptr2char((char *)p))) {
MB_PTR_BACK(line, p); MB_PTR_BACK(line, p);
} }
if (p == line && vim_isfilec(utf_ptr2char(p))) { if (p == line && vim_isfilec(utf_ptr2char((char *)p))) {
startcol = 0; startcol = 0;
} else { } else {
startcol = (int)(p - line) + 1; startcol = (int)(p - line) + 1;
@ -5590,7 +5590,7 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len)
*dest++ = *src; *dest++ = *src;
} }
// Copy remaining bytes of a multibyte character. // Copy remaining bytes of a multibyte character.
const int mb_len = utfc_ptr2len(src) - 1; const int mb_len = utfc_ptr2len((char *)src) - 1;
if (mb_len > 0 && len >= mb_len) { if (mb_len > 0 && len >= mb_len) {
for (int i = 0; i < mb_len; i++) { for (int i = 0; i < mb_len; i++) {
len--; len--;
@ -5759,9 +5759,8 @@ static void insert_special(int c, int allow_modmask, int ctrlv)
*/ */
#define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^') #define ISSPECIAL(c) ((c) < ' ' || (c) >= DEL || (c) == '0' || (c) == '^')
#define WHITECHAR(cc) ( \ #define WHITECHAR(cc) (ascii_iswhite(cc) \
ascii_iswhite(cc) \ && !utf_iscomposing(utf_ptr2char((char *)get_cursor_pos_ptr() + 1)))
&& !utf_iscomposing(utf_ptr2char(get_cursor_pos_ptr() + 1)))
/// ///
/// "flags": INSCHAR_FORMAT - force formatting /// "flags": INSCHAR_FORMAT - force formatting
@ -6903,7 +6902,7 @@ int oneright(void)
// Adjust for multi-wide char (excluding TAB) // Adjust for multi-wide char (excluding TAB)
ptr = get_cursor_pos_ptr(); ptr = get_cursor_pos_ptr();
coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char(ptr))) ? coladvance(getviscol() + ((*ptr != TAB && vim_isprintc(utf_ptr2char((char *)ptr))) ?
ptr2cells(ptr) : 1)); ptr2cells(ptr) : 1));
curwin->w_set_curswant = true; curwin->w_set_curswant = true;
// Return OK if the cursor moved, FAIL otherwise (at window edge). // Return OK if the cursor moved, FAIL otherwise (at window edge).
@ -6916,7 +6915,7 @@ int oneright(void)
return FAIL; // already at the very end return FAIL; // already at the very end
} }
l = utfc_ptr2len(ptr); l = utfc_ptr2len((char *)ptr);
// move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' // move "l" bytes right, but don't end up on the NUL, unless 'virtualedit'
// contains "onemore". // contains "onemore".
@ -6957,7 +6956,7 @@ int oneleft(void)
// Adjust for multi-wide char (not a TAB) // Adjust for multi-wide char (not a TAB)
ptr = get_cursor_pos_ptr(); ptr = get_cursor_pos_ptr();
if (*ptr != TAB && vim_isprintc(utf_ptr2char(ptr)) if (*ptr != TAB && vim_isprintc(utf_ptr2char((char *)ptr))
&& ptr2cells(ptr) > 1) { && ptr2cells(ptr) > 1) {
curwin->w_cursor.coladd = 0; curwin->w_cursor.coladd = 0;
} }
@ -7249,7 +7248,7 @@ void replace_push(int c)
*/ */
int replace_push_mb(char_u *p) int replace_push_mb(char_u *p)
{ {
int l = utfc_ptr2len(p); int l = utfc_ptr2len((char *)p);
int j; int j;
for (j = l - 1; j >= 0; --j) { for (j = l - 1; j >= 0; --j) {
@ -7337,7 +7336,7 @@ static void mb_replace_pop_ins(int cc)
for (i = 1; i < n; i++) { for (i = 1; i < n; i++) {
buf[i] = (char_u)replace_pop(); buf[i] = (char_u)replace_pop();
} }
if (utf_iscomposing(utf_ptr2char(buf))) { if (utf_iscomposing(utf_ptr2char((char *)buf))) {
ins_bytes_len(buf, (size_t)n); ins_bytes_len(buf, (size_t)n);
} else { } else {
// Not a composing char, put it back. // Not a composing char, put it back.
@ -7403,7 +7402,7 @@ static void replace_do_bs(int limit_col)
vcol = start_vcol; vcol = start_vcol;
for (i = 0; i < ins_len; i++) { for (i = 0; i < ins_len; i++) {
vcol += win_chartabsize(curwin, p + i, vcol); vcol += win_chartabsize(curwin, p + i, vcol);
i += utfc_ptr2len(p) - 1; i += utfc_ptr2len((char *)p) - 1;
} }
vcol -= start_vcol; vcol -= start_vcol;
@ -8796,7 +8795,7 @@ static void ins_right(void)
if (virtual_active()) { if (virtual_active()) {
oneright(); oneright();
} else { } else {
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
} }
revins_legal++; revins_legal++;
@ -9305,7 +9304,7 @@ int ins_copychar(linenr_T lnum)
ptr = prev_ptr; ptr = prev_ptr;
} }
c = utf_ptr2char(ptr); c = utf_ptr2char((char *)ptr);
if (c == NUL) { if (c == NUL) {
vim_beep(BO_COPY); vim_beep(BO_COPY);
} }

View File

@ -2656,7 +2656,7 @@ bool next_for_item(void *fi_void, char *arg)
} }
if (fi->fi_string != NULL) { if (fi->fi_string != NULL) {
const int len = utfc_ptr2len((char_u *)fi->fi_string + fi->fi_byte_idx); const int len = utfc_ptr2len(fi->fi_string + fi->fi_byte_idx);
if (len == 0) { if (len == 0) {
return false; return false;
} }
@ -7681,7 +7681,7 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx)
char *t = str; char *t = str;
int count; int count;
for (count = 0; *t != NUL && t <= str + byteidx; count++) { for (count = 0; *t != NUL && t <= str + byteidx; count++) {
t += utfc_ptr2len((char_u *)t); t += utfc_ptr2len(t);
} }
// In insert mode, when the cursor is at the end of a non-empty line, // In insert mode, when the cursor is at the end of a non-empty line,
@ -7714,7 +7714,7 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx)
// Convert the character offset to a byte offset // Convert the character offset to a byte offset
char *t = str; char *t = str;
while (*t != NUL && --charidx > 0) { while (*t != NUL && --charidx > 0) {
t += utfc_ptr2len((char_u *)t); t += utfc_ptr2len(t);
} }
return t - str; return t - str;
@ -10409,7 +10409,7 @@ char *do_string_sub(char *str, char *pat, char *sub, typval_T *expr, char *flags
if (regmatch.startp[0] == regmatch.endp[0]) { if (regmatch.startp[0] == regmatch.endp[0]) {
if ((char_u *)zero_width == regmatch.startp[0]) { if ((char_u *)zero_width == regmatch.startp[0]) {
// avoid getting stuck on a match with an empty string // avoid getting stuck on a match with an empty string
int i = utfc_ptr2len((char_u *)tail); int i = utfc_ptr2len(tail);
memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i); memmove((char_u *)ga.ga_data + ga.ga_len, tail, (size_t)i);
ga.ga_len += i; ga.ga_len += i;
tail += i; tail += i;

View File

@ -375,7 +375,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
"inside string: %.*s"), LENP(p, e)); "inside string: %.*s"), LENP(p, e));
goto parse_json_string_fail; goto parse_json_string_fail;
} }
const int ch = utf_ptr2char((char_u *)p); const int ch = utf_ptr2char(p);
// All characters above U+007F are encoded using two or more bytes // All characters above U+007F are encoded using two or more bytes
// and thus cannot possibly be equal to *p. But utf_ptr2char({0xFF, // and thus cannot possibly be equal to *p. But utf_ptr2char({0xFF,
// 0}) will return 0xFF, even though 0xFF cannot start any UTF-8 // 0}) will return 0xFF, even though 0xFF cannot start any UTF-8
@ -392,7 +392,7 @@ static inline int parse_json_string(const char *const buf, const size_t buf_len,
goto parse_json_string_fail; goto parse_json_string_fail;
} }
const size_t ch_len = (size_t)utf_char2len(ch); const size_t ch_len = (size_t)utf_char2len(ch);
assert(ch_len == (size_t)(ch ? utf_ptr2len((char_u *)p) : 1)); assert(ch_len == (size_t)(ch ? utf_ptr2len(p) : 1));
len += ch_len; len += ch_len;
p += ch_len; p += ch_len;
} }

View File

@ -611,8 +611,8 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const
#define ENCODE_RAW(ch) \ #define ENCODE_RAW(ch) \
(ch >= 0x20 && utf_printable(ch)) (ch >= 0x20 && utf_printable(ch))
for (size_t i = 0; i < utf_len;) { for (size_t i = 0; i < utf_len;) {
const int ch = utf_ptr2char((char_u *)utf_buf + i); const int ch = utf_ptr2char(utf_buf + i);
const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len((char_u *)utf_buf + i))); const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len(utf_buf + i)));
assert(shift > 0); assert(shift > 0);
i += shift; i += shift;
switch (ch) { switch (ch) {
@ -651,11 +651,11 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const
ga_append(gap, '"'); ga_append(gap, '"');
ga_grow(gap, (int)str_len); ga_grow(gap, (int)str_len);
for (size_t i = 0; i < utf_len;) { for (size_t i = 0; i < utf_len;) {
const int ch = utf_ptr2char((char_u *)utf_buf + i); const int ch = utf_ptr2char(utf_buf + i);
const size_t shift = (ch == 0 ? 1 : ((size_t)utf_char2len(ch))); const size_t shift = (ch == 0 ? 1 : ((size_t)utf_char2len(ch)));
assert(shift > 0); assert(shift > 0);
// Is false on invalid unicode, but this should already be handled. // Is false on invalid unicode, but this should already be handled.
assert(ch == 0 || shift == ((size_t)utf_ptr2len((char_u *)utf_buf + i))); assert(ch == 0 || shift == ((size_t)utf_ptr2len(utf_buf + i)));
switch (ch) { switch (ch) {
case BS: case BS:
case TAB: case TAB:

View File

@ -733,9 +733,9 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
return; return;
} }
if (comp) { if (comp) {
t += utf_ptr2len((const char_u *)t); t += utf_ptr2len(t);
} else { } else {
t += utfc_ptr2len((const char_u *)t); t += utfc_ptr2len(t);
} }
} }
rettv->vval.v_number = (varnumber_T)(t - str); rettv->vval.v_number = (varnumber_T)(t - str);
@ -894,7 +894,7 @@ static void f_char2nr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
} }
} }
rettv->vval.v_number = utf_ptr2char((const char_u *)tv_get_string(&argvars[0])); rettv->vval.v_number = utf_ptr2char(tv_get_string(&argvars[0]));
} }
/// Get the current cursor column and store it in 'rettv'. /// Get the current cursor column and store it in 'rettv'.
@ -925,7 +925,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol)
if (curwin->w_cursor.coladd >= if (curwin->w_cursor.coladd >=
(colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) {
int l; int l;
if (*p != NUL && p[(l = utfc_ptr2len(p))] == NUL) { if (*p != NUL && p[(l = utfc_ptr2len((char *)p))] == NUL) {
col += l; col += l;
} }
} }
@ -968,7 +968,7 @@ static void f_charidx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
return; return;
} }
int (*ptr2len)(const char_u *); int (*ptr2len)(const char *);
if (countcc) { if (countcc) {
ptr2len = utf_ptr2len; ptr2len = utf_ptr2len;
} else { } else {
@ -981,7 +981,7 @@ static void f_charidx(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (*p == NUL) { if (*p == NUL) {
return; return;
} }
p += ptr2len((const char_u *)p); p += ptr2len(p);
} }
rettv->vval.v_number = len > 0 ? len - 1 : 0; rettv->vval.v_number = len > 0 ? len - 1 : 0;
@ -5691,7 +5691,7 @@ static void get_maparg(typval_T *argvars, typval_T *rettv, int exact)
return; return;
} }
mode = get_map_mode((char_u **)&which, 0); mode = get_map_mode((char **)&which, 0);
char_u *keys_simplified char_u *keys_simplified
= replace_termcodes(keys, STRLEN(keys), &keys_buf, flags, &did_simplify, CPO_TO_CPO_FLAGS); = replace_termcodes(keys, STRLEN(keys), &keys_buf, flags, &did_simplify, CPO_TO_CPO_FLAGS);
@ -5894,7 +5894,7 @@ static void find_some_match(typval_T *const argvars, typval_T *const rettv,
idx++; idx++;
} else { } else {
startcol = (colnr_T)(regmatch.startp[0] startcol = (colnr_T)(regmatch.startp[0]
+ utfc_ptr2len(regmatch.startp[0]) - str); + utfc_ptr2len((char *)regmatch.startp[0]) - str);
if (startcol > (colnr_T)len || str + startcol <= regmatch.startp[0]) { if (startcol > (colnr_T)len || str + startcol <= regmatch.startp[0]) {
match = false; match = false;
break; break;
@ -8062,7 +8062,7 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
} else { } else {
ScreenGrid *grid = &default_grid; ScreenGrid *grid = &default_grid;
screenchar_adjust_grid(&grid, &row, &col); screenchar_adjust_grid(&grid, &row, &col);
c = utf_ptr2char(grid->chars[grid->line_offset[row] + col]); c = utf_ptr2char((char *)grid->chars[grid->line_offset[row] + col]);
} }
rettv->vval.v_number = c; rettv->vval.v_number = c;
} }
@ -8660,7 +8660,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (csearch != NULL) { if (csearch != NULL) {
int pcc[MAX_MCO]; int pcc[MAX_MCO];
const int c = utfc_ptr2char(csearch, pcc); const int c = utfc_ptr2char(csearch, pcc);
set_last_csearch(c, csearch, utfc_ptr2len(csearch)); set_last_csearch(c, csearch, utfc_ptr2len((char *)csearch));
} }
di = tv_dict_find(d, S_LEN("forward")); di = tv_dict_find(d, S_LEN("forward"));
@ -9796,7 +9796,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr)
col = 0; col = 0;
} else { } else {
// Don't get stuck at the same match. // Don't get stuck at the same match.
col = utfc_ptr2len(regmatch.endp[0]); col = utfc_ptr2len((char *)regmatch.endp[0]);
} }
str = (const char *)regmatch.endp[0]; str = (const char *)regmatch.endp[0];
} }
@ -9856,8 +9856,8 @@ static void f_str2list(typval_T *argvars, typval_T *rettv, FunPtr fptr)
tv_list_alloc_ret(rettv, kListLenUnknown); tv_list_alloc_ret(rettv, kListLenUnknown);
const char_u *p = (const char_u *)tv_get_string(&argvars[0]); const char_u *p = (const char_u *)tv_get_string(&argvars[0]);
for (; *p != NUL; p += utf_ptr2len(p)) { for (; *p != NUL; p += utf_ptr2len((char *)p)) {
tv_list_append_number(rettv->vval.v_list, utf_ptr2char(p)); tv_list_append_number(rettv->vval.v_list, utf_ptr2char((char *)p));
} }
} }
@ -9976,11 +9976,11 @@ static void f_strgetchar(typval_T *argvars, typval_T *rettv, FunPtr fptr)
while (charidx >= 0 && byteidx < len) { while (charidx >= 0 && byteidx < len) {
if (charidx == 0) { if (charidx == 0) {
rettv->vval.v_number = utf_ptr2char((const char_u *)str + byteidx); rettv->vval.v_number = utf_ptr2char(str + byteidx);
break; break;
} }
charidx--; charidx--;
byteidx += utf_ptr2len((const char_u *)str + byteidx); byteidx += utf_ptr2len(str + byteidx);
} }
} }
@ -10085,7 +10085,7 @@ static void f_strcharpart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (!error) { if (!error) {
if (nchar > 0) { if (nchar > 0) {
while (nchar > 0 && (size_t)nbyte < slen) { while (nchar > 0 && (size_t)nbyte < slen) {
nbyte += utf_ptr2len((const char_u *)p + nbyte); nbyte += utf_ptr2len(p + nbyte);
nchar--; nchar--;
} }
} else { } else {
@ -10101,7 +10101,7 @@ static void f_strcharpart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (off < 0) { if (off < 0) {
len += 1; len += 1;
} else { } else {
len += utf_ptr2len((const char_u *)p + off); len += utf_ptr2len(p + off);
} }
charlen--; charlen--;
} }
@ -10164,7 +10164,7 @@ static void f_strpart(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// length in characters // length in characters
for (off = n; off < (int)slen && len > 0; len--) { for (off = n; off < (int)slen && len > 0; len--) {
off += utfc_ptr2len((char_u *)p + off); off += utfc_ptr2len(p + off);
} }
len = off - n; len = off - n;
} }
@ -10935,16 +10935,16 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
bool first = true; bool first = true;
while (*in_str != NUL) { while (*in_str != NUL) {
const char *cpstr = in_str; const char *cpstr = in_str;
const int inlen = utfc_ptr2len((const char_u *)in_str); const int inlen = utfc_ptr2len(in_str);
int cplen = inlen; int cplen = inlen;
int idx = 0; int idx = 0;
int fromlen; int fromlen;
for (const char *p = fromstr; *p != NUL; p += fromlen) { for (const char *p = fromstr; *p != NUL; p += fromlen) {
fromlen = utfc_ptr2len((const char_u *)p); fromlen = utfc_ptr2len(p);
if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) { if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) {
int tolen; int tolen;
for (p = tostr; *p != NUL; p += tolen) { for (p = tostr; *p != NUL; p += tolen) {
tolen = utfc_ptr2len((const char_u *)p); tolen = utfc_ptr2len(p);
if (idx-- == 0) { if (idx-- == 0) {
cplen = tolen; cplen = tolen;
cpstr = (char *)p; cpstr = (char *)p;
@ -10966,7 +10966,7 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
first = false; first = false;
int tolen; int tolen;
for (const char *p = tostr; *p != NUL; p += tolen) { for (const char *p = tostr; *p != NUL; p += tolen) {
tolen = utfc_ptr2len((const char_u *)p); tolen = utfc_ptr2len(p);
idx--; idx--;
} }
if (idx != 0) { if (idx != 0) {
@ -11029,14 +11029,14 @@ static void f_trim(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if (dir == 0 || dir == 1) { if (dir == 0 || dir == 1) {
// Trim leading characters // Trim leading characters
while (*head != NUL) { while (*head != NUL) {
c1 = utf_ptr2char(head); c1 = utf_ptr2char((char *)head);
if (mask == NULL) { if (mask == NULL) {
if (c1 > ' ' && c1 != 0xa0) { if (c1 > ' ' && c1 != 0xa0) {
break; break;
} }
} else { } else {
for (p = mask; *p != NUL; MB_PTR_ADV(p)) { for (p = mask; *p != NUL; MB_PTR_ADV(p)) {
if (c1 == utf_ptr2char(p)) { if (c1 == utf_ptr2char((char *)p)) {
break; break;
} }
} }
@ -11054,14 +11054,14 @@ static void f_trim(typval_T *argvars, typval_T *rettv, FunPtr fptr)
for (; tail > head; tail = prev) { for (; tail > head; tail = prev) {
prev = tail; prev = tail;
MB_PTR_BACK(head, prev); MB_PTR_BACK(head, prev);
c1 = utf_ptr2char(prev); c1 = utf_ptr2char((char *)prev);
if (mask == NULL) { if (mask == NULL) {
if (c1 > ' ' && c1 != 0xa0) { if (c1 > ' ' && c1 != 0xa0) {
break; break;
} }
} else { } else {
for (p = mask; *p != NUL; MB_PTR_ADV(p)) { for (p = mask; *p != NUL; MB_PTR_ADV(p)) {
if (c1 == utf_ptr2char(p)) { if (c1 == utf_ptr2char((char *)p)) {
break; break;
} }
} }

View File

@ -850,7 +850,7 @@ void ex_retab(exarg_T *eap)
emsg(_(e_resulting_text_too_long)); emsg(_(e_resulting_text_too_long));
break; break;
} }
col += utfc_ptr2len((char_u *)ptr + col); col += utfc_ptr2len(ptr + col);
} }
if (new_line == NULL) { // out of memory if (new_line == NULL) { // out of memory
break; break;
@ -3785,7 +3785,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle
skip_match = true; skip_match = true;
} else { } else {
// search for a match at next column // search for a match at next column
matchcol += utfc_ptr2len((char_u *)sub_firstline + matchcol); matchcol += utfc_ptr2len(sub_firstline + matchcol);
} }
// match will be pushed to preview_lines, bring it into a proper state // match will be pushed to preview_lines, bring it into a proper state
current_match.start.col = matchcol; current_match.start.col = matchcol;
@ -4179,7 +4179,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle
p1 = new_start - 1; p1 = new_start - 1;
} }
} else { } else {
p1 += utfc_ptr2len((char_u *)p1) - 1; p1 += utfc_ptr2len(p1) - 1;
} }
} }
size_t new_endcol = STRLEN(new_start); size_t new_endcol = STRLEN(new_start);
@ -5464,7 +5464,7 @@ void fix_help_buffer(void)
// illegal byte sequence is found. // illegal byte sequence is found.
if ((char_u)(*s) >= 0x80 && this_utf != kFalse) { if ((char_u)(*s) >= 0x80 && this_utf != kFalse) {
this_utf = kTrue; this_utf = kTrue;
const int l = utf_ptr2len((char_u *)s); const int l = utf_ptr2len(s);
if (l == 1) { if (l == 1) {
this_utf = kFalse; this_utf = kFalse;
} }
@ -5613,7 +5613,7 @@ static void helptags_one(char *dir, const char *ext, const char *tagfname, bool
for (s = (char *)IObuff; *s != NUL; s++) { for (s = (char *)IObuff; *s != NUL; s++) {
if ((char_u)(*s) >= 0x80) { if ((char_u)(*s) >= 0x80) {
this_utf8 = kTrue; this_utf8 = kTrue;
const int l = utf_ptr2len((char_u *)s); const int l = utf_ptr2len(s);
if (l == 1) { if (l == 1) {
// Illegal UTF-8 byte sequence. // Illegal UTF-8 byte sequence.
this_utf8 = kFalse; this_utf8 = kFalse;

View File

@ -3381,7 +3381,7 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff)
xp->xp_pattern = (char *)skipwhite((const char_u *)arg); xp->xp_pattern = (char *)skipwhite((const char_u *)arg);
p = (const char *)xp->xp_pattern; p = (const char *)xp->xp_pattern;
while (*p != NUL) { while (*p != NUL) {
c = utf_ptr2char((const char_u *)p); c = utf_ptr2char(p);
if (c == '\\' && p[1] != NUL) { if (c == '\\' && p[1] != NUL) {
p++; p++;
} else if (c == '`') { } else if (c == '`') {
@ -3399,11 +3399,11 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff)
|| ascii_iswhite(c)) { || ascii_iswhite(c)) {
len = 0; // avoid getting stuck when space is in 'isfname' len = 0; // avoid getting stuck when space is in 'isfname'
while (*p != NUL) { while (*p != NUL) {
c = utf_ptr2char((const char_u *)p); c = utf_ptr2char(p);
if (c == '`' || vim_isfilec_or_wc(c)) { if (c == '`' || vim_isfilec_or_wc(c)) {
break; break;
} }
len = (size_t)utfc_ptr2len((const char_u *)p); len = (size_t)utfc_ptr2len(p);
MB_PTR_ADV(p); MB_PTR_ADV(p);
} }
if (in_quote) { if (in_quote) {
@ -6030,7 +6030,7 @@ static char *uc_split_args(char *arg, size_t *lenp)
} }
len += 3; // "," len += 3; // ","
} else { } else {
const int charlen = utfc_ptr2len((char_u *)p); const int charlen = utfc_ptr2len(p);
len += charlen; len += charlen;
p += charlen; p += charlen;
@ -8167,7 +8167,7 @@ static void do_exmap(exarg_T *eap, int isabbrev)
{ {
int mode; int mode;
char *cmdp = eap->cmd; char *cmdp = eap->cmd;
mode = get_map_mode((char_u **)&cmdp, eap->forceit || isabbrev); mode = get_map_mode(&cmdp, eap->forceit || isabbrev);
switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'), switch (do_map((*cmdp == 'n') ? 2 : (*cmdp == 'u'),
(char_u *)eap->arg, mode, isabbrev)) { (char_u *)eap->arg, mode, isabbrev)) {
@ -8828,7 +8828,7 @@ static void ex_normal(exarg_T *eap)
// Count the number of characters to be escaped. // Count the number of characters to be escaped.
for (p = eap->arg; *p != NUL; p++) { for (p = eap->arg; *p != NUL; p++) {
for (l = utfc_ptr2len((char_u *)p) - 1; l > 0; l--) { for (l = utfc_ptr2len(p) - 1; l > 0; l--) {
if (*++p == (char)K_SPECIAL) { // trailbyte K_SPECIAL if (*++p == (char)K_SPECIAL) { // trailbyte K_SPECIAL
len += 2; len += 2;
} }
@ -8839,7 +8839,7 @@ static void ex_normal(exarg_T *eap)
len = 0; len = 0;
for (p = eap->arg; *p != NUL; p++) { for (p = eap->arg; *p != NUL; p++) {
arg[len++] = *p; arg[len++] = *p;
for (l = utfc_ptr2len((char_u *)p) - 1; l > 0; l--) { for (l = utfc_ptr2len(p) - 1; l > 0; l--) {
arg[len++] = *++p; arg[len++] = *++p;
if (*p == (char)K_SPECIAL) { if (*p == (char)K_SPECIAL) {
arg[len++] = (char)KS_SPECIAL; arg[len++] = (char)KS_SPECIAL;

View File

@ -1780,7 +1780,7 @@ static int command_line_handle_key(CommandLineState *s)
} }
if (mb_get_class(p) != i) { if (mb_get_class(p) != i) {
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
} }
} }
@ -1964,7 +1964,7 @@ static int command_line_handle_key(CommandLineState *s)
} }
ccline.cmdspos += cells; ccline.cmdspos += cells;
ccline.cmdpos += utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos); ccline.cmdpos += utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos);
} while ((s->c == K_S_RIGHT || s->c == K_C_RIGHT } while ((s->c == K_S_RIGHT || s->c == K_C_RIGHT
|| (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL)))
&& ccline.cmdbuff[ccline.cmdpos] != ' '); && ccline.cmdbuff[ccline.cmdpos] != ' ');
@ -2039,7 +2039,7 @@ static int command_line_handle_key(CommandLineState *s)
// Count ">" for double-wide char that doesn't fit. // Count ">" for double-wide char that doesn't fit.
correct_screencol(ccline.cmdpos, cells, &ccline.cmdspos); correct_screencol(ccline.cmdpos, cells, &ccline.cmdspos);
ccline.cmdpos += utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1; ccline.cmdpos += utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos) - 1;
ccline.cmdspos += cells; ccline.cmdspos += cells;
} }
return command_line_not_changed(s); return command_line_not_changed(s);
@ -2571,7 +2571,7 @@ static int cmd_screencol(int bytepos)
} }
for (int i = 0; i < ccline.cmdlen && i < bytepos; for (int i = 0; i < ccline.cmdlen && i < bytepos;
i += utfc_ptr2len(ccline.cmdbuff + i)) { i += utfc_ptr2len((char *)ccline.cmdbuff + i)) {
int c = cmdline_charsize(i); int c = cmdline_charsize(i);
// Count ">" for double-wide multi-byte char that doesn't fit. // Count ">" for double-wide multi-byte char that doesn't fit.
correct_screencol(i, c, &col); correct_screencol(i, c, &col);
@ -2590,8 +2590,8 @@ static int cmd_screencol(int bytepos)
/// character that doesn't fit, so that a ">" must be displayed. /// character that doesn't fit, so that a ">" must be displayed.
static void correct_screencol(int idx, int cells, int *col) static void correct_screencol(int idx, int cells, int *col)
{ {
if (utfc_ptr2len(ccline.cmdbuff + idx) > 1 if (utfc_ptr2len((char *)ccline.cmdbuff + idx) > 1
&& utf_ptr2cells(ccline.cmdbuff + idx) > 1 && utf_ptr2cells((char *)ccline.cmdbuff + idx) > 1
&& (*col) % Columns + cells > Columns) { && (*col) % Columns + cells > Columns) {
(*col)++; (*col)++;
} }
@ -2996,7 +2996,7 @@ static void draw_cmdline(int start, int len)
if (cmdline_star > 0) { if (cmdline_star > 0) {
for (int i = 0; i < len; i++) { for (int i = 0; i < len; i++) {
msg_putchar('*'); msg_putchar('*');
i += utfc_ptr2len(ccline.cmdbuff + start + i) - 1; i += utfc_ptr2len((char *)ccline.cmdbuff + start + i) - 1;
} }
} else if (p_arshape && !p_tbidi && len > 0) { } else if (p_arshape && !p_tbidi && len > 0) {
bool do_arabicshape = false; bool do_arabicshape = false;
@ -3029,7 +3029,7 @@ static void draw_cmdline(int start, int len)
} }
int newlen = 0; int newlen = 0;
if (utf_iscomposing(utf_ptr2char(ccline.cmdbuff + start))) { if (utf_iscomposing(utf_ptr2char((char *)ccline.cmdbuff + start))) {
// Prepend a space to draw the leading composing char on. // Prepend a space to draw the leading composing char on.
arshape_buf[0] = ' '; arshape_buf[0] = ' ';
newlen = 1; newlen = 1;
@ -3055,7 +3055,7 @@ static void draw_cmdline(int start, int len)
if (i + mb_l >= start + len) { if (i + mb_l >= start + len) {
nc = NUL; nc = NUL;
} else { } else {
nc = utf_ptr2char(p + mb_l); nc = utf_ptr2char((char *)p + mb_l);
} }
} else { } else {
// Displaying from left to right. // Displaying from left to right.
@ -3261,7 +3261,7 @@ void unputcmdline(void)
if (ccline.cmdlen == ccline.cmdpos && !ui_has(kUICmdline)) { if (ccline.cmdlen == ccline.cmdpos && !ui_has(kUICmdline)) {
msg_putchar(' '); msg_putchar(' ');
} else { } else {
draw_cmdline(ccline.cmdpos, utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos)); draw_cmdline(ccline.cmdpos, utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos));
} }
msg_no_more = false; msg_no_more = false;
cursorcmd(); cursorcmd();
@ -3297,13 +3297,13 @@ void put_on_cmdline(char_u *str, int len, int redraw)
} else { } else {
// Count nr of characters in the new string. // Count nr of characters in the new string.
m = 0; m = 0;
for (i = 0; i < len; i += utfc_ptr2len(str + i)) { for (i = 0; i < len; i += utfc_ptr2len((char *)str + i)) {
m++; m++;
} }
// Count nr of bytes in cmdline that are overwritten by these // Count nr of bytes in cmdline that are overwritten by these
// characters. // characters.
for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0;
i += utfc_ptr2len(ccline.cmdbuff + i)) { i += utfc_ptr2len((char *)ccline.cmdbuff + i)) {
m--; m--;
} }
if (i < ccline.cmdlen) { if (i < ccline.cmdlen) {
@ -3321,17 +3321,17 @@ void put_on_cmdline(char_u *str, int len, int redraw)
// When the inserted text starts with a composing character, // When the inserted text starts with a composing character,
// backup to the character before it. There could be two of them. // backup to the character before it. There could be two of them.
i = 0; i = 0;
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos);
while (ccline.cmdpos > 0 && utf_iscomposing(c)) { while (ccline.cmdpos > 0 && utf_iscomposing(c)) {
i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1;
ccline.cmdpos -= i; ccline.cmdpos -= i;
len += i; len += i;
c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos);
} }
if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) { if (i == 0 && ccline.cmdpos > 0 && arabic_maycombine(c)) {
// Check the previous character for Arabic combining pair. // Check the previous character for Arabic combining pair.
i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1;
if (arabic_combine(utf_ptr2char(ccline.cmdbuff + ccline.cmdpos - i), c)) { if (arabic_combine(utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos - i), c)) {
ccline.cmdpos -= i; ccline.cmdpos -= i;
len += i; len += i;
} else { } else {
@ -3379,7 +3379,7 @@ void put_on_cmdline(char_u *str, int len, int redraw)
if (ccline.cmdspos + c < m) { if (ccline.cmdspos + c < m) {
ccline.cmdspos += c; ccline.cmdspos += c;
} }
c = utfc_ptr2len(ccline.cmdbuff + ccline.cmdpos) - 1; c = utfc_ptr2len((char *)ccline.cmdbuff + ccline.cmdpos) - 1;
if (c > len - i - 1) { if (c > len - i - 1) {
c = len - i - 1; c = len - i - 1;
} }
@ -3464,7 +3464,7 @@ static bool cmdline_paste(int regname, bool literally, bool remcr)
// Locate start of last word in the cmd buffer. // Locate start of last word in the cmd buffer.
for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) { for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) {
len = utf_head_off(ccline.cmdbuff, w - 1) + 1; len = utf_head_off(ccline.cmdbuff, w - 1) + 1;
if (!vim_iswordc(utf_ptr2char(w - len))) { if (!vim_iswordc(utf_ptr2char((char *)w - len))) {
break; break;
} }
w -= len; w -= len;
@ -4025,10 +4025,10 @@ char_u *ExpandOne(expand_T *xp, char_u *str, char_u *orig, int options, int mode
size_t len = 0; size_t len = 0;
for (size_t mb_len; xp->xp_files[0][len]; len += mb_len) { for (size_t mb_len; xp->xp_files[0][len]; len += mb_len) {
mb_len = (size_t)utfc_ptr2len((char_u *)&xp->xp_files[0][len]); mb_len = (size_t)utfc_ptr2len(&xp->xp_files[0][len]);
int c0 = utf_ptr2char((char_u *)&xp->xp_files[0][len]); int c0 = utf_ptr2char(&xp->xp_files[0][len]);
for (i = 1; i < xp->xp_numfiles; i++) { for (i = 1; i < xp->xp_numfiles; i++) {
int ci = utf_ptr2char((char_u *)&xp->xp_files[i][len]); int ci = utf_ptr2char(&xp->xp_files[i][len]);
if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES if (p_fic && (xp->xp_context == EXPAND_DIRECTORIES
|| xp->xp_context == EXPAND_FILES || xp->xp_context == EXPAND_FILES

View File

@ -1111,8 +1111,8 @@ static bool ff_wc_equal(char_u *s1, char_u *s2)
} }
for (i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) { for (i = 0, j = 0; s1[i] != NUL && s2[j] != NUL;) {
c1 = utf_ptr2char(s1 + i); c1 = utf_ptr2char((char *)s1 + i);
c2 = utf_ptr2char(s2 + j); c2 = utf_ptr2char((char *)s2 + j);
if ((p_fic ? mb_tolower(c1) != mb_tolower(c2) : c1 != c2) if ((p_fic ? mb_tolower(c1) != mb_tolower(c2) : c1 != c2)
&& (prev1 != '*' || prev2 != '*')) { && (prev1 != '*' || prev2 != '*')) {
@ -1121,8 +1121,8 @@ static bool ff_wc_equal(char_u *s1, char_u *s2)
prev2 = prev1; prev2 = prev1;
prev1 = c1; prev1 = c1;
i += utfc_ptr2len(s1 + i); i += utfc_ptr2len((char *)s1 + i);
j += utfc_ptr2len(s2 + j); j += utfc_ptr2len((char *)s2 + j);
} }
return s1[i] == s2[j]; return s1[i] == s2[j];
} }

View File

@ -1377,7 +1377,7 @@ retry:
} else { } else {
len = utf_head_off(ptr, p); len = utf_head_off(ptr, p);
p -= len; p -= len;
u8c = utf_ptr2char(p); u8c = utf_ptr2char((char *)p);
if (len == 0) { if (len == 0) {
// Not a valid UTF-8 character, retry with // Not a valid UTF-8 character, retry with
// another fenc when possible, otherwise just // another fenc when possible, otherwise just
@ -3982,7 +3982,7 @@ static int buf_write_bytes(struct bw_info *ip)
break; break;
} }
if (n > 1) { if (n > 1) {
c = utf_ptr2char(ip->bw_rest); c = utf_ptr2char((char *)ip->bw_rest);
} else { } else {
c = ip->bw_rest[0]; c = ip->bw_rest[0];
} }
@ -4010,7 +4010,7 @@ static int buf_write_bytes(struct bw_info *ip)
break; break;
} }
if (n > 1) { if (n > 1) {
c = utf_ptr2char(buf + wlen); c = utf_ptr2char((char *)buf + wlen);
} else { } else {
c = buf[wlen]; c = buf[wlen];
} }

View File

@ -1798,10 +1798,10 @@ char_u *get_foldtext(win_T *wp, linenr_T lnum, linenr_T lnume, foldinfo_T foldin
// Replace unprintable characters, if there are any. But // Replace unprintable characters, if there are any. But
// replace a TAB with a space. // replace a TAB with a space.
for (p = text; *p != NUL; p++) { for (p = text; *p != NUL; p++) {
int len = utfc_ptr2len(p); int len = utfc_ptr2len((char *)p);
if (len > 1) { if (len > 1) {
if (!vim_isprintc(utf_ptr2char(p))) { if (!vim_isprintc(utf_ptr2char((char *)p))) {
break; break;
} }
p += len - 1; p += len - 1;

View File

@ -700,7 +700,7 @@ static int read_redo(bool init, bool old_redo)
buf[i] = (char_u)c; buf[i] = (char_u)c;
if (i == n - 1) { // last byte of a character if (i == n - 1) { // last byte of a character
if (n != 1) { if (n != 1) {
c = utf_ptr2char(buf); c = utf_ptr2char((char *)buf);
} }
break; break;
} }
@ -1624,7 +1624,7 @@ int vgetc(void)
} }
} }
no_mapping--; no_mapping--;
c = utf_ptr2char(buf); c = utf_ptr2char((char *)buf);
} }
if (vgetc_char == 0) { if (vgetc_char == 0) {
@ -1935,7 +1935,7 @@ static int handle_mapping(int *keylenp, bool *timedout, int *mapdepth)
char_u *p1 = mp->m_keys; char_u *p1 = mp->m_keys;
char_u *p2 = (char_u *)mb_unescape((const char **)&p1); char_u *p2 = (char_u *)mb_unescape((const char **)&p1);
if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len(p2)) { if (p2 != NULL && MB_BYTE2LEN(tb_c1) > utfc_ptr2len((char *)p2)) {
mlen = 0; mlen = 0;
} }
@ -2450,7 +2450,7 @@ static int vgetorpeek(bool advance)
curwin->w_wcol = vcol; curwin->w_wcol = vcol;
} }
vcol += lbr_chartabsize(ptr, ptr + col, vcol); vcol += lbr_chartabsize(ptr, ptr + col, vcol);
col += utfc_ptr2len(ptr + col); col += utfc_ptr2len((char *)ptr + col);
} }
curwin->w_wrow = curwin->w_cline_row curwin->w_wrow = curwin->w_cline_row
+ curwin->w_wcol / curwin->w_width_inner; + curwin->w_wcol / curwin->w_width_inner;
@ -2471,7 +2471,7 @@ static int vgetorpeek(bool advance)
// of a double-wide character. // of a double-wide character.
ptr = get_cursor_line_ptr(); ptr = get_cursor_line_ptr();
col -= utf_head_off(ptr, ptr + col); col -= utf_head_off(ptr, ptr + col);
if (utf_ptr2cells(ptr + col) > 1) { if (utf_ptr2cells((char *)ptr + col) > 1) {
curwin->w_wcol--; curwin->w_wcol--;
} }
} }
@ -3137,7 +3137,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T
const int first = vim_iswordp(lhs); const int first = vim_iswordp(lhs);
int last = first; int last = first;
p = lhs + utfc_ptr2len(lhs); p = lhs + utfc_ptr2len((char *)lhs);
n = 1; n = 1;
while (p < lhs + len) { while (p < lhs + len) {
n++; // nr of (multi-byte) chars n++; // nr of (multi-byte) chars
@ -3145,7 +3145,7 @@ int buf_do_map(int maptype, MapArguments *args, int mode, bool is_abbrev, buf_T
if (same == -1 && last != first) { if (same == -1 && last != first) {
same = n - 1; // count of same char type same = n - 1; // count of same char type
} }
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
} }
if (last && n > 2 && same >= 0 && same < n - 1) { if (last && n > 2 && same >= 0 && same < n - 1) {
retval = 1; retval = 1;
@ -3543,14 +3543,14 @@ static void validate_maphash(void)
/* /*
* Get the mapping mode from the command name. * Get the mapping mode from the command name.
*/ */
int get_map_mode(char_u **cmdp, bool forceit) int get_map_mode(char **cmdp, bool forceit)
{ {
char_u *p; char *p;
int modec; int modec;
int mode; int mode;
p = *cmdp; p = *cmdp;
modec = *p++; modec = (uint8_t)(*p++);
if (modec == 'i') { if (modec == 'i') {
mode = INSERT; // :imap mode = INSERT; // :imap
} else if (modec == 'l') { } else if (modec == 'l') {
@ -3597,7 +3597,7 @@ void map_clear_mode(char_u *cmdp, char_u *arg, int forceit, int abbr)
return; return;
} }
mode = get_map_mode(&cmdp, forceit); mode = get_map_mode((char **)&cmdp, forceit);
map_clear_int(curbuf, mode, map_clear_int(curbuf, mode,
local, local,
abbr); abbr);
@ -3894,7 +3894,7 @@ char_u *set_context_in_map_cmd(expand_T *xp, char_u *cmd, char_u *arg, bool forc
xp->xp_context = EXPAND_NOTHING; xp->xp_context = EXPAND_NOTHING;
} else { } else {
if (isunmap) { if (isunmap) {
expand_mapmodes = get_map_mode(&cmd, forceit || isabbrev); expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev);
} else { } else {
expand_mapmodes = INSERT + CMDLINE; expand_mapmodes = INSERT + CMDLINE;
if (!isabbrev) { if (!isabbrev) {
@ -4117,7 +4117,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol)
while (p > ptr + mincol) { while (p > ptr + mincol) {
p = mb_prevptr(ptr, p); p = mb_prevptr(ptr, p);
if (ascii_isspace(*p) || (!vim_abbr && is_id != vim_iswordp(p))) { if (ascii_isspace(*p) || (!vim_abbr && is_id != vim_iswordp(p))) {
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
break; break;
} }
++clen; ++clen;
@ -4310,8 +4310,8 @@ char_u *vim_strsave_escape_ks(char_u *p)
} else { } else {
// Add character, possibly multi-byte to destination, escaping // Add character, possibly multi-byte to destination, escaping
// K_SPECIAL. Be careful, it can be an illegal byte! // K_SPECIAL. Be careful, it can be an illegal byte!
d = add_char2buf(utf_ptr2char(s), d); d = add_char2buf(utf_ptr2char((char *)s), d);
s += utf_ptr2len(s); s += utf_ptr2len((char *)s);
} }
} }
*d = NUL; *d = NUL;

View File

@ -589,7 +589,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const
int page_line = 0 - prt_header_height(); int page_line = 0 - prt_header_height();
mch_print_start_line(true, page_line); mch_print_start_line(true, page_line);
for (char_u *p = tbuf; *p != NUL;) { for (char_u *p = tbuf; *p != NUL;) {
const int l = utfc_ptr2len(p); const int l = utfc_ptr2len((char *)p);
assert(l >= 0); assert(l >= 0);
if (mch_print_text_out(p, (size_t)l)) { if (mch_print_text_out(p, (size_t)l)) {
page_line++; page_line++;
@ -896,7 +896,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
* Loop over the columns until the end of the file line or right margin. * Loop over the columns until the end of the file line or right margin.
*/ */
for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) { for (col = ppos->column; line[col] != NUL && !need_break; col += outputlen) {
if ((outputlen = utfc_ptr2len(line + col)) < 1) { if ((outputlen = utfc_ptr2len((char *)line + col)) < 1) {
outputlen = 1; outputlen = 1;
} }
// syntax highlighting stuff. // syntax highlighting stuff.
@ -949,7 +949,7 @@ static colnr_T hardcopy_line(prt_settings_T *psettings, int page_line, prt_pos_T
need_break = 1; need_break = 1;
} else { } else {
need_break = mch_print_text_out(line + col, (size_t)outputlen); need_break = mch_print_text_out(line + col, (size_t)outputlen);
print_pos += utf_ptr2cells(line + col); print_pos += utf_ptr2cells((char *)line + col);
} }
} }
@ -3002,7 +3002,7 @@ int mch_print_text_out(char_u *const textp, size_t len)
} }
} }
if (prt_out_mbyte) { if (prt_out_mbyte) {
const bool half_width = (utf_ptr2cells(p) == 1); const bool half_width = (utf_ptr2cells((char *)p) == 1);
if (half_width) { if (half_width) {
char_width /= 2; char_width /= 2;
} }

View File

@ -144,7 +144,7 @@ int get_keystroke(MultiQueue *events)
continue; continue;
} }
buf[len >= buflen ? buflen - 1 : len] = NUL; buf[len >= buflen ? buflen - 1 : len] = NUL;
n = utf_ptr2char(buf); n = utf_ptr2char((char *)buf);
break; break;
} }
xfree(buf); xfree(buf);

View File

@ -719,10 +719,10 @@ int find_special_key(const char_u **const srcp, const size_t src_len, int *const
// Special case for a double-quoted string // Special case for a double-quoted string
off = l = 2; off = l = 2;
} else { } else {
l = utfc_ptr2len(last_dash + 1); l = utfc_ptr2len((char *)last_dash + 1);
} }
if (modifiers != 0 && last_dash[l + 1] == '>') { if (modifiers != 0 && last_dash[l + 1] == '>') {
key = utf_ptr2char(last_dash + off); key = utf_ptr2char((char *)last_dash + off);
} else { } else {
key = get_special_key_code(last_dash + off); key = get_special_key_code(last_dash + off);
if (!(flags & FSK_KEEP_X_KEY)) { if (!(flags & FSK_KEEP_X_KEY)) {

View File

@ -95,10 +95,10 @@
// MB_PTR_ADV(): advance a pointer to the next character, taking care of // MB_PTR_ADV(): advance a pointer to the next character, taking care of
// multi-byte characters if needed. Skip over composing chars. // multi-byte characters if needed. Skip over composing chars.
#define MB_PTR_ADV(p) (p += utfc_ptr2len((char_u *)p)) #define MB_PTR_ADV(p) (p += utfc_ptr2len((char *)p))
// Advance multi-byte pointer, do not skip over composing chars. // Advance multi-byte pointer, do not skip over composing chars.
#define MB_CPTR_ADV(p) (p += utf_ptr2len(p)) #define MB_CPTR_ADV(p) (p += utf_ptr2len((char *)p))
// MB_PTR_BACK(): backup a pointer to the previous character, taking care of // MB_PTR_BACK(): backup a pointer to the previous character, taking care of
// multi-byte characters if needed. Only use with "p" > "s" ! // multi-byte characters if needed. Only use with "p" > "s" !

View File

@ -1579,7 +1579,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp)
// double-wide character. // double-wide character.
if (lp->coladd == 1 if (lp->coladd == 1
&& p[lp->col] != TAB && p[lp->col] != TAB
&& vim_isprintc(utf_ptr2char(p + lp->col)) && vim_isprintc(utf_ptr2char((char *)p + lp->col))
&& ptr2cells(p + lp->col) > 1) { && ptr2cells(p + lp->col) > 1) {
lp->coladd = 0; lp->coladd = 0;
} }

View File

@ -93,7 +93,7 @@ static int match_add(win_T *wp, const char *const grp, const char *const pat, in
m->match.rmm_maxcol = 0; m->match.rmm_maxcol = 0;
m->conceal_char = 0; m->conceal_char = 0;
if (conceal_char != NULL) { if (conceal_char != NULL) {
m->conceal_char = utf_ptr2char((const char_u *)conceal_char); m->conceal_char = utf_ptr2char(conceal_char);
} }
// Set up position matches // Set up position matches
@ -447,7 +447,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_
shl->lnum = 0; shl->lnum = 0;
break; break;
} }
matchcol += utfc_ptr2len(ml); matchcol += utfc_ptr2len((char *)ml);
} else { } else {
matchcol = shl->rm.endpos[0].col; matchcol = shl->rm.endpos[0].col;
} }
@ -634,7 +634,7 @@ bool prepare_search_hl_line(win_T *wp, linenr_T lnum, colnr_T mincol, char_u **l
// Highlight one character for an empty match. // Highlight one character for an empty match.
if (shl->startcol == shl->endcol) { if (shl->startcol == shl->endcol) {
if ((*line)[shl->endcol] != NUL) { if ((*line)[shl->endcol] != NUL) {
shl->endcol += utfc_ptr2len(*line + shl->endcol); shl->endcol += utfc_ptr2len((char *)(*line) + shl->endcol);
} else { } else {
shl->endcol++; shl->endcol++;
} }
@ -688,7 +688,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
if (shl->startcol != MAXCOL if (shl->startcol != MAXCOL
&& col >= shl->startcol && col >= shl->startcol
&& col < shl->endcol) { && col < shl->endcol) {
int next_col = col + utfc_ptr2len(*line + col); int next_col = col + utfc_ptr2len((char *)(*line) + col);
if (shl->endcol < next_col) { if (shl->endcol < next_col) {
shl->endcol = next_col; shl->endcol = next_col;
@ -736,7 +736,7 @@ int update_search_hl(win_T *wp, linenr_T lnum, colnr_T col, char_u **line, match
if (shl->startcol == shl->endcol) { if (shl->startcol == shl->endcol) {
// highlight empty match, try again after it // highlight empty match, try again after it
shl->endcol += utfc_ptr2len(*line + shl->endcol); shl->endcol += utfc_ptr2len((char *)(*line) + shl->endcol);
} }
// Loop to check if the match starts at the // Loop to check if the match starts at the

View File

@ -430,7 +430,7 @@ int mb_get_class_tab(const char_u *p, const uint64_t *const chartab)
} }
return 1; return 1;
} }
return utf_class_tab(utf_ptr2char(p), chartab); return utf_class_tab(utf_ptr2char((char *)p), chartab);
} }
/* /*
@ -512,12 +512,12 @@ int utf_char2cells(int c)
/// Return the number of display cells character at "*p" occupies. /// Return the number of display cells character at "*p" occupies.
/// This doesn't take care of unprintable characters, use ptr2cells() for that. /// This doesn't take care of unprintable characters, use ptr2cells() for that.
int utf_ptr2cells(const char_u *p) int utf_ptr2cells(const char *p)
{ {
int c; int c;
// Need to convert to a character number. // Need to convert to a character number.
if (*p >= 0x80) { if ((uint8_t)(*p) >= 0x80) {
c = utf_ptr2char(p); c = utf_ptr2char(p);
// An illegal byte is displayed as <xx>. // An illegal byte is displayed as <xx>.
if (utf_ptr2len(p) == 1 || c == NUL) { if (utf_ptr2len(p) == 1 || c == NUL) {
@ -543,9 +543,9 @@ int utf_ptr2cells_len(const char_u *p, int size)
if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) { if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) {
return 1; // truncated return 1; // truncated
} }
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
// An illegal byte is displayed as <xx>. // An illegal byte is displayed as <xx>.
if (utf_ptr2len(p) == 1 || c == NUL) { if (utf_ptr2len((char *)p) == 1 || c == NUL) {
return 4; return 4;
} }
// If the char is ASCII it must be an overlong sequence. // If the char is ASCII it must be an overlong sequence.
@ -566,8 +566,8 @@ size_t mb_string2cells(const char *str)
{ {
size_t clen = 0; size_t clen = 0;
for (const char_u *p = (char_u *)str; *p != NUL; p += utfc_ptr2len(p)) { for (const char_u *p = (char_u *)str; *p != NUL; p += utfc_ptr2len((char *)p)) {
clen += utf_ptr2cells(p); clen += utf_ptr2cells((char *)p);
} }
return clen; return clen;
@ -586,7 +586,7 @@ size_t mb_string2cells_len(const char_u *str, size_t size)
for (const char_u *p = str; *p != NUL && p < str + size; for (const char_u *p = str; *p != NUL && p < str + size;
p += utfc_ptr2len_len(p, size + (p - str))) { p += utfc_ptr2len_len(p, size + (p - str))) {
clen += utf_ptr2cells(p); clen += utf_ptr2cells((char *)p);
} }
return clen; return clen;
@ -602,9 +602,10 @@ size_t mb_string2cells_len(const char_u *str, size_t size)
/// @param[in] p String to convert. /// @param[in] p String to convert.
/// ///
/// @return Unicode codepoint or byte value. /// @return Unicode codepoint or byte value.
int utf_ptr2char(const char_u *const p) int utf_ptr2char(const char *const p_in)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{ {
uint8_t *p = (uint8_t *)p_in;
if (p[0] < 0x80) { // Be quick for ASCII. if (p[0] < 0x80) { // Be quick for ASCII.
return p[0]; return p[0];
} }
@ -679,7 +680,7 @@ static int utf_safe_read_char_adv(const char_u **s, size_t *n)
// We have a multibyte sequence and it isn't truncated by buffer // We have a multibyte sequence and it isn't truncated by buffer
// limits so utf_ptr2char() is safe to use. Or the first byte is // limits so utf_ptr2char() is safe to use. Or the first byte is
// illegal (k=0), and it's also safe to use utf_ptr2char(). // illegal (k=0), and it's also safe to use utf_ptr2char().
c = utf_ptr2char(*s); c = utf_ptr2char((char *)(*s));
// On failure, utf_ptr2char() returns the first byte, so here we // On failure, utf_ptr2char() returns the first byte, so here we
// check equality with the first byte. The only non-ASCII character // check equality with the first byte. The only non-ASCII character
@ -706,8 +707,8 @@ int mb_ptr2char_adv(const char_u **const pp)
{ {
int c; int c;
c = utf_ptr2char(*pp); c = utf_ptr2char((char *)(*pp));
*pp += utfc_ptr2len(*pp); *pp += utfc_ptr2len((char *)(*pp));
return c; return c;
} }
@ -719,8 +720,8 @@ int mb_cptr2char_adv(const char_u **pp)
{ {
int c; int c;
c = utf_ptr2char(*pp); c = utf_ptr2char((char *)(*pp));
*pp += utf_ptr2len(*pp); *pp += utf_ptr2len((char *)(*pp));
return c; return c;
} }
@ -733,14 +734,14 @@ bool utf_composinglike(const char_u *p1, const char_u *p2)
{ {
int c2; int c2;
c2 = utf_ptr2char(p2); c2 = utf_ptr2char((char *)p2);
if (utf_iscomposing(c2)) { if (utf_iscomposing(c2)) {
return true; return true;
} }
if (!arabic_maycombine(c2)) { if (!arabic_maycombine(c2)) {
return false; return false;
} }
return arabic_combine(utf_ptr2char(p1), c2); return arabic_combine(utf_ptr2char((char *)p1), c2);
} }
/// Convert a UTF-8 string to a wide character /// Convert a UTF-8 string to a wide character
@ -758,21 +759,21 @@ int utfc_ptr2char(const char_u *p, int *pcc)
int cc; int cc;
int i = 0; int i = 0;
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
len = utf_ptr2len(p); len = utf_ptr2len((char *)p);
// Only accept a composing char when the first char isn't illegal. // Only accept a composing char when the first char isn't illegal.
if ((len > 1 || *p < 0x80) if ((len > 1 || *p < 0x80)
&& p[len] >= 0x80 && p[len] >= 0x80
&& utf_composinglike(p, p + len)) { && utf_composinglike(p, p + len)) {
cc = utf_ptr2char(p + len); cc = utf_ptr2char((char *)p + len);
for (;;) { for (;;) {
pcc[i++] = cc; pcc[i++] = cc;
if (i == MAX_MCO) { if (i == MAX_MCO) {
break; break;
} }
len += utf_ptr2len(p + len); len += utf_ptr2len((char *)p + len);
if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) { if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char((char *)p + len))) {
break; break;
} }
} }
@ -800,14 +801,14 @@ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen)
int len = utf_ptr2len_len(p, maxlen); int len = utf_ptr2len_len(p, maxlen);
// Is it safe to use utf_ptr2char()? // Is it safe to use utf_ptr2char()?
bool safe = len > 1 && len <= maxlen; bool safe = len > 1 && len <= maxlen;
int c = safe ? utf_ptr2char(p) : *p; int c = safe ? utf_ptr2char((char *)p) : *p;
// Only accept a composing char when the first char isn't illegal. // Only accept a composing char when the first char isn't illegal.
if ((safe || c < 0x80) && len < maxlen && p[len] >= 0x80) { if ((safe || c < 0x80) && len < maxlen && p[len] >= 0x80) {
for (; i < MAX_MCO; i++) { for (; i < MAX_MCO; i++) {
int len_cc = utf_ptr2len_len(p + len, maxlen - len); int len_cc = utf_ptr2len_len(p + len, maxlen - len);
safe = len_cc > 1 && len_cc <= maxlen - len; safe = len_cc > 1 && len_cc <= maxlen - len;
if (!safe || (pcc[i] = utf_ptr2char(p + len)) < 0x80 if (!safe || (pcc[i] = utf_ptr2char((char *)p + len)) < 0x80
|| !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) { || !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) {
break; break;
} }
@ -830,9 +831,10 @@ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen)
/// ///
/// @return Sequence length, 0 for empty string and 1 for non-UTF-8 byte /// @return Sequence length, 0 for empty string and 1 for non-UTF-8 byte
/// sequence. /// sequence.
int utf_ptr2len(const char_u *const p) int utf_ptr2len(const char *const p_in)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
uint8_t *p = (uint8_t *)p_in;
if (*p == NUL) { if (*p == NUL) {
return 0; return 0;
} }
@ -889,10 +891,11 @@ int utf_ptr2len_len(const char_u *p, int size)
/// Return the number of bytes occupied by a UTF-8 character in a string /// Return the number of bytes occupied by a UTF-8 character in a string
/// ///
/// This includes following composing characters. /// This includes following composing characters.
int utfc_ptr2len(const char_u *const p) int utfc_ptr2len(const char *const p_in)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{ {
uint8_t b0 = (uint8_t)(*p); uint8_t *p = (uint8_t *)p_in;
uint8_t b0 = *p;
if (b0 == NUL) { if (b0 == NUL) {
return 0; return 0;
@ -902,7 +905,7 @@ int utfc_ptr2len(const char_u *const p)
} }
// Skip over first UTF-8 char, stopping at a NUL byte. // Skip over first UTF-8 char, stopping at a NUL byte.
int len = utf_ptr2len(p); int len = utf_ptr2len((char *)p);
// Check for illegal byte. // Check for illegal byte.
if (len == 1 && b0 >= 0x80) { if (len == 1 && b0 >= 0x80) {
@ -919,7 +922,7 @@ int utfc_ptr2len(const char_u *const p)
// Skip over composing char. // Skip over composing char.
prevlen = len; prevlen = len;
len += utf_ptr2len(p + len); len += utf_ptr2len((char *)p + len);
} }
} }
@ -1510,7 +1513,7 @@ void mb_utflen(const char_u *s, size_t len, size_t *codepoints, size_t *codeunit
clen = utf_ptr2len_len(s + i, len - i); clen = utf_ptr2len_len(s + i, len - i);
// NB: gets the byte value of invalid sequence bytes. // NB: gets the byte value of invalid sequence bytes.
// we only care whether the char fits in the BMP or not // we only care whether the char fits in the BMP or not
int c = (clen > 1) ? utf_ptr2char(s + i) : s[i]; int c = (clen > 1) ? utf_ptr2char((char *)s + i) : s[i];
count++; count++;
if (c > 0xFFFF) { if (c > 0xFFFF) {
extra++; extra++;
@ -1532,7 +1535,7 @@ ssize_t mb_utf_index_to_bytes(const char_u *s, size_t len, size_t index, bool us
clen = utf_ptr2len_len(s + i, len - i); clen = utf_ptr2len_len(s + i, len - i);
// NB: gets the byte value of invalid sequence bytes. // NB: gets the byte value of invalid sequence bytes.
// we only care whether the char fits in the BMP or not // we only care whether the char fits in the BMP or not
int c = (clen > 1) ? utf_ptr2char(s + i) : s[i]; int c = (clen > 1) ? utf_ptr2char((char *)s + i) : s[i];
count++; count++;
if (use_utf16_units && c > 0xFFFF) { if (use_utf16_units && c > 0xFFFF) {
count++; count++;
@ -1590,7 +1593,7 @@ void show_utf8(void)
// Get the byte length of the char under the cursor, including composing // Get the byte length of the char under the cursor, including composing
// characters. // characters.
line = get_cursor_pos_ptr(); line = get_cursor_pos_ptr();
len = utfc_ptr2len(line); len = utfc_ptr2len((char *)line);
if (len == 0) { if (len == 0) {
msg("NUL"); msg("NUL");
return; return;
@ -1604,7 +1607,7 @@ void show_utf8(void)
STRCPY(IObuff + rlen, "+ "); STRCPY(IObuff + rlen, "+ ");
rlen += 2; rlen += 2;
} }
clen = utf_ptr2len(line + i); clen = utf_ptr2len((char *)line + i);
} }
sprintf((char *)IObuff + rlen, "%02x ", sprintf((char *)IObuff + rlen, "%02x ",
(line[i] == NL) ? NUL : line[i]); // NUL is stored as NL (line[i] == NL) ? NUL : line[i]); // NUL is stored as NL
@ -1654,7 +1657,7 @@ int utf_head_off(const char_u *base, const char_u *p)
break; break;
} }
c = utf_ptr2char(q); c = utf_ptr2char((char *)q);
if (utf_iscomposing(c)) { if (utf_iscomposing(c)) {
continue; continue;
} }
@ -1667,7 +1670,7 @@ int utf_head_off(const char_u *base, const char_u *p)
while (j > base && (*j & 0xc0) == 0x80) { while (j > base && (*j & 0xc0) == 0x80) {
--j; --j;
} }
if (arabic_combine(utf_ptr2char(j), c)) { if (arabic_combine(utf_ptr2char((char *)j), c)) {
continue; continue;
} }
} }
@ -1823,7 +1826,7 @@ bool utf_allow_break(int cc, int ncc)
/// @param[in,out] tp Destination to copy to. /// @param[in,out] tp Destination to copy to.
void mb_copy_char(const char_u **const fp, char_u **const tp) void mb_copy_char(const char_u **const fp, char_u **const tp)
{ {
const size_t l = (size_t)utfc_ptr2len(*fp); const size_t l = (size_t)utfc_ptr2len((char *)(*fp));
memmove(*tp, *fp, l); memmove(*tp, *fp, l);
*tp += l; *tp += l;
@ -1955,9 +1958,9 @@ void utf_find_illegal(void)
while (*p != NUL) { while (*p != NUL) {
// Illegal means that there are not enough trail bytes (checked by // Illegal means that there are not enough trail bytes (checked by
// utf_ptr2len()) or too many of them (overlong sequence). // utf_ptr2len()) or too many of them (overlong sequence).
len = utf_ptr2len(p); len = utf_ptr2len((char *)p);
if (*p >= 0x80 && (len == 1 if (*p >= 0x80 && (len == 1
|| utf_char2len(utf_ptr2char(p)) != len)) { || utf_char2len(utf_ptr2char((char *)p)) != len)) {
if (vimconv.vc_type == CONV_NONE) { if (vimconv.vc_type == CONV_NONE) {
curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr()); curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr());
} else { } else {
@ -1965,7 +1968,7 @@ void utf_find_illegal(void)
len = (int)(p - tofree); len = (int)(p - tofree);
for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) { for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
l = utf_ptr2len(p); l = utf_ptr2len((char *)p);
curwin->w_cursor.col += l; curwin->w_cursor.col += l;
} }
} }
@ -2027,7 +2030,7 @@ void mb_check_adjust_col(void *win_)
// Reset `coladd` when the cursor would be on the right half of a // Reset `coladd` when the cursor would be on the right half of a
// double-wide character. // double-wide character.
if (win->w_cursor.coladd == 1 && p[win->w_cursor.col] != TAB if (win->w_cursor.coladd == 1 && p[win->w_cursor.col] != TAB
&& vim_isprintc(utf_ptr2char(p + win->w_cursor.col)) && vim_isprintc(utf_ptr2char((char *)p + win->w_cursor.col))
&& ptr2cells(p + win->w_cursor.col) > 1) { && ptr2cells(p + win->w_cursor.col) > 1) {
win->w_cursor.coladd = 0; win->w_cursor.coladd = 0;
} }
@ -2057,7 +2060,7 @@ int mb_charlen(const char_u *str)
} }
for (count = 0; *p != NUL; count++) { for (count = 0; *p != NUL; count++) {
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
} }
return count; return count;
@ -2070,7 +2073,7 @@ int mb_charlen_len(const char_u *str, int len)
int count; int count;
for (count = 0; *p != NUL && p < str + len; count++) { for (count = 0; *p != NUL && p < str + len; count++) {
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
} }
return count; return count;
@ -2110,7 +2113,7 @@ const char *mb_unescape(const char **const pp)
// Return a multi-byte character if it's found. An illegal sequence // Return a multi-byte character if it's found. An illegal sequence
// will result in a 1 here. // will result in a 1 here.
if (utf_ptr2len((const char_u *)buf) > 1) { if (utf_ptr2len(buf) > 1) {
*pp = (const char *)str + str_idx + 1; *pp = (const char *)str + str_idx + 1;
return buf; return buf;
} }
@ -2400,7 +2403,7 @@ static char_u *iconv_string(const vimconv_T *const vcp, char_u *str, size_t slen
// conversion from 'encoding' to something else. In other // conversion from 'encoding' to something else. In other
// situations we don't know what to skip anyway. // situations we don't know what to skip anyway.
*to++ = '?'; *to++ = '?';
if (utf_ptr2cells((char_u *)from) > 1) { if (utf_ptr2cells(from) > 1) {
*to++ = '?'; *to++ = '?';
} }
l = utfc_ptr2len_len((const char_u *)from, (int)fromlen); l = utfc_ptr2len_len((const char_u *)from, (int)fromlen);
@ -2616,7 +2619,7 @@ char_u *string_convert_ext(const vimconv_T *const vcp, char_u *ptr, size_t *lenp
} }
*d++ = ptr[i]; *d++ = ptr[i];
} else { } else {
c = utf_ptr2char(ptr + i); c = utf_ptr2char((char *)ptr + i);
if (vcp->vc_type == CONV_TO_LATIN9) { if (vcp->vc_type == CONV_TO_LATIN9) {
switch (c) { switch (c) {
case 0x20ac: case 0x20ac:

View File

@ -1823,7 +1823,7 @@ int gchar_pos(pos_T *pos)
if (pos->col == MAXCOL) { if (pos->col == MAXCOL) {
return NUL; return NUL;
} }
return utf_ptr2char(ml_get_pos(pos)); return utf_ptr2char((char *)ml_get_pos(pos));
} }
/// @param will_change true mark the buffer dirty (chars in the line will be changed) /// @param will_change true mark the buffer dirty (chars in the line will be changed)
@ -4206,7 +4206,7 @@ int inc(pos_T *lp)
if (lp->col != MAXCOL) { if (lp->col != MAXCOL) {
const char_u *const p = ml_get_pos(lp); const char_u *const p = ml_get_pos(lp);
if (*p != NUL) { // still within line, move to next char (may be NUL) if (*p != NUL) { // still within line, move to next char (may be NUL)
const int l = utfc_ptr2len(p); const int l = utfc_ptr2len((char *)p);
lp->col += l; lp->col += l;
return ((p[l] != NUL) ? 0 : 2); return ((p[l] != NUL) ? 0 : 2);

View File

@ -408,7 +408,7 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
} }
len += n; len += n;
buf[e] = s[e]; buf[e] = s[e];
for (n = utfc_ptr2len(s + e); --n > 0;) { for (n = utfc_ptr2len((char *)s + e); --n > 0;) {
if (++e == buflen) { if (++e == buflen) {
break; break;
} }
@ -421,7 +421,7 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
for (;;) { for (;;) {
do { do {
half = half - utf_head_off(s, s + half - 1) - 1; half = half - utf_head_off(s, s + half - 1) - 1;
} while (half > 0 && utf_iscomposing(utf_ptr2char(s + half))); } while (half > 0 && utf_iscomposing(utf_ptr2char((char *)s + half)));
n = ptr2cells(s + half); n = ptr2cells(s + half);
if (len + n > room || half == 0) { if (len + n > room || half == 0) {
break; break;
@ -882,8 +882,8 @@ char_u *msg_may_trunc(bool force, char_u *s)
} }
int n; int n;
for (n = 0; size >= room;) { for (n = 0; size >= room;) {
size -= utf_ptr2cells(s + n); size -= utf_ptr2cells((char *)s + n);
n += utfc_ptr2len(s + n); n += utfc_ptr2len((char *)s + n);
} }
n--; n--;
s += n; s += n;
@ -1480,7 +1480,7 @@ char_u *msg_outtrans_one(char_u *p, int attr)
{ {
int l; int l;
if ((l = utfc_ptr2len(p)) > 1) { if ((l = utfc_ptr2len((char *)p)) > 1) {
msg_outtrans_len_attr(p, l, attr); msg_outtrans_len_attr(p, l, attr);
return p + l; return p + l;
} }
@ -1509,7 +1509,7 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr)
// If the string starts with a composing character first draw a space on // If the string starts with a composing character first draw a space on
// which the composing char can be drawn. // which the composing char can be drawn.
if (utf_iscomposing(utf_ptr2char(msgstr))) { if (utf_iscomposing(utf_ptr2char((char *)msgstr))) {
msg_puts_attr(" ", attr); msg_puts_attr(" ", attr);
} }
@ -1521,10 +1521,10 @@ int msg_outtrans_len_attr(const char_u *msgstr, int len, int attr)
// Don't include composing chars after the end. // Don't include composing chars after the end.
mb_l = utfc_ptr2len_len((char_u *)str, len + 1); mb_l = utfc_ptr2len_len((char_u *)str, len + 1);
if (mb_l > 1) { if (mb_l > 1) {
c = utf_ptr2char((char_u *)str); c = utf_ptr2char(str);
if (vim_isprintc(c)) { if (vim_isprintc(c)) {
// Printable multi-byte char: count the cells. // Printable multi-byte char: count the cells.
retval += utf_ptr2cells((char_u *)str); retval += utf_ptr2cells(str);
} else { } else {
// Unprintable multi-byte char: print the printable chars so // Unprintable multi-byte char: print the printable chars so
// far and the translation of the unprintable char. // far and the translation of the unprintable char.
@ -1624,7 +1624,7 @@ int msg_outtrans_special(const char_u *strstart, bool from, int maxlen)
} }
// Highlight special keys // Highlight special keys
msg_puts_attr(text, (len > 1 msg_puts_attr(text, (len > 1
&& utfc_ptr2len((char_u *)text) <= 1 && utfc_ptr2len(text) <= 1
? attr : 0)); ? attr : 0));
retval += len; retval += len;
} }
@ -1705,7 +1705,7 @@ const char *str2special(const char **const sp, const bool replace_spaces, const
const char *p = mb_unescape(sp); const char *p = mb_unescape(sp);
if (p == NULL) { if (p == NULL) {
const int len = utf_ptr2len((const char_u *)str); const int len = utf_ptr2len(str);
// Check for an illegal byte. // Check for an illegal byte.
if (MB_BYTE2LEN((uint8_t)(*str)) > len) { if (MB_BYTE2LEN((uint8_t)(*str)) > len) {
transchar_nonprint(curbuf, (char_u *)buf, c); transchar_nonprint(curbuf, (char_u *)buf, c);
@ -1717,7 +1717,7 @@ const char *str2special(const char **const sp, const bool replace_spaces, const
} }
// Since 'special' is true the multi-byte character 'c' will be // Since 'special' is true the multi-byte character 'c' will be
// processed by get_special_key_name(). // processed by get_special_key_name().
c = utf_ptr2char((const char_u *)p); c = utf_ptr2char(p);
} else { } else {
*sp = str + 1; *sp = str + 1;
} }
@ -1813,16 +1813,16 @@ void msg_prt_line(char_u *s, int list)
assert(p_extra != NULL); assert(p_extra != NULL);
c = *p_extra++; c = *p_extra++;
} }
} else if ((l = utfc_ptr2len(s)) > 1) { } else if ((l = utfc_ptr2len((char *)s)) > 1) {
col += utf_ptr2cells(s); col += utf_ptr2cells((char *)s);
char buf[MB_MAXBYTES + 1]; char buf[MB_MAXBYTES + 1];
if (l >= MB_MAXBYTES) { if (l >= MB_MAXBYTES) {
xstrlcpy(buf, "?", sizeof(buf)); xstrlcpy(buf, "?", sizeof(buf));
} else if (curwin->w_p_lcs_chars.nbsp != NUL && list } else if (curwin->w_p_lcs_chars.nbsp != NUL && list
&& (utf_ptr2char(s) == 160 && (utf_ptr2char((char *)s) == 160
|| utf_ptr2char(s) == 0x202f)) { || utf_ptr2char((char *)s) == 0x202f)) {
utf_char2bytes(curwin->w_p_lcs_chars.nbsp, (char_u *)buf); utf_char2bytes(curwin->w_p_lcs_chars.nbsp, (char_u *)buf);
buf[utfc_ptr2len((char_u *)buf)] = NUL; buf[utfc_ptr2len(buf)] = NUL;
} else { } else {
memmove(buf, s, (size_t)l); memmove(buf, s, (size_t)l);
buf[l] = NUL; buf[l] = NUL;
@ -1913,7 +1913,7 @@ static char_u *screen_puts_mbyte(char_u *s, int l, int attr)
attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr); attr = hl_combine_attr(HL_ATTR(HLF_MSG), attr);
msg_didout = true; // remember that line is not empty msg_didout = true; // remember that line is not empty
cw = utf_ptr2cells(s); cw = utf_ptr2cells((char *)s);
if (cw > 1 if (cw > 1
&& (cmdmsg_rl ? msg_col <= 1 : msg_col == Columns - 1)) { && (cmdmsg_rl ? msg_col <= 1 : msg_col == Columns - 1)) {
// Doesn't fit, print a highlighted '>' to fill it up. // Doesn't fit, print a highlighted '>' to fill it up.
@ -2116,12 +2116,12 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
&& (*s == '\n' || (cmdmsg_rl && (*s == '\n' || (cmdmsg_rl
? (msg_col <= 1 ? (msg_col <= 1
|| (*s == TAB && msg_col <= 7) || (*s == TAB && msg_col <= 7)
|| (utf_ptr2cells(s) > 1 || (utf_ptr2cells((char *)s) > 1
&& msg_col <= 2)) && msg_col <= 2))
: ((*s != '\r' && msg_col + t_col >= Columns - 1) : ((*s != '\r' && msg_col + t_col >= Columns - 1)
|| (*s == TAB || (*s == TAB
&& msg_col + t_col >= ((Columns - 1) & ~7)) && msg_col + t_col >= ((Columns - 1) & ~7))
|| (utf_ptr2cells(s) > 1 || (utf_ptr2cells((char *)s) > 1
&& msg_col + t_col >= Columns - 2))))) { && msg_col + t_col >= Columns - 2))))) {
// The screen is scrolled up when at the last row (some terminals // The screen is scrolled up when at the last row (some terminals
// scroll automatically, some don't. To avoid problems we scroll // scroll automatically, some don't. To avoid problems we scroll
@ -2151,7 +2151,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
// Avoid including composing chars after the end. // Avoid including composing chars after the end.
l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); l = utfc_ptr2len_len(s, (int)((str + maxlen) - s));
} else { } else {
l = utfc_ptr2len(s); l = utfc_ptr2len((char *)s);
} }
s = screen_puts_mbyte((char_u *)s, l, attr); s = screen_puts_mbyte((char_u *)s, l, attr);
did_last_char = true; did_last_char = true;
@ -2206,7 +2206,7 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
wrap = *s == '\n' wrap = *s == '\n'
|| msg_col + t_col >= Columns || msg_col + t_col >= Columns
|| (utf_ptr2cells(s) > 1 || (utf_ptr2cells((char *)s) > 1
&& msg_col + t_col >= Columns - 1) && msg_col + t_col >= Columns - 1)
; ;
if (t_col > 0 && (wrap || *s == '\r' || *s == '\b' if (t_col > 0 && (wrap || *s == '\r' || *s == '\b'
@ -2243,12 +2243,12 @@ static void msg_puts_display(const char_u *str, int maxlen, int attr, int recurs
} else if (*s == BELL) { // beep (from ":sh") } else if (*s == BELL) { // beep (from ":sh")
vim_beep(BO_SH); vim_beep(BO_SH);
} else if (*s >= 0x20) { // printable char } else if (*s >= 0x20) { // printable char
cw = utf_ptr2cells(s); cw = utf_ptr2cells((char *)s);
if (maxlen >= 0) { if (maxlen >= 0) {
// avoid including composing chars after the end // avoid including composing chars after the end
l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); l = utfc_ptr2len_len(s, (int)((str + maxlen) - s));
} else { } else {
l = utfc_ptr2len(s); l = utfc_ptr2len((char *)s);
} }
// When drawing from right to left or when a double-wide character // When drawing from right to left or when a double-wide character
// doesn't fit, draw a single character here. Otherwise collect // doesn't fit, draw a single character here. Otherwise collect
@ -2609,7 +2609,7 @@ static void t_puts(int *t_col, const char_u *t_s, const char_u *s, int attr)
*t_col = 0; *t_col = 0;
// If the string starts with a composing character don't increment the // If the string starts with a composing character don't increment the
// column position for it. // column position for it.
if (utf_iscomposing(utf_ptr2char(t_s))) { if (utf_iscomposing(utf_ptr2char((char *)t_s))) {
msg_col--; msg_col--;
} }
if (msg_col >= Columns) { if (msg_col >= Columns) {
@ -2645,7 +2645,7 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
} }
while ((maxlen < 0 || s - str < maxlen) && *s != NUL) { while ((maxlen < 0 || s - str < maxlen) && *s != NUL) {
int len = utf_ptr2len((const char_u *)s); int len = utf_ptr2len(s);
if (!(silent_mode && p_verbose == 0)) { if (!(silent_mode && p_verbose == 0)) {
// NL --> CR NL translation (for Unix, not for "--version") // NL --> CR NL translation (for Unix, not for "--version")
p = &buf[0]; p = &buf[0];
@ -2661,7 +2661,7 @@ static void msg_puts_printf(const char *str, const ptrdiff_t maxlen)
} }
} }
int cw = utf_char2cells(utf_ptr2char((const char_u *)s)); int cw = utf_char2cells(utf_ptr2char(s));
// primitive way to compute the current column // primitive way to compute the current column
if (cmdmsg_rl) { if (cmdmsg_rl) {
if (*s == '\r' || *s == '\n') { if (*s == '\r' || *s == '\n') {
@ -3473,10 +3473,10 @@ int do_dialog(int type, char_u *title, char_u *message, char_u *buttons, int dfl
c = mb_tolower(c); c = mb_tolower(c);
retval = 1; retval = 1;
for (i = 0; hotkeys[i]; i++) { for (i = 0; hotkeys[i]; i++) {
if (utf_ptr2char(hotkeys + i) == c) { if (utf_ptr2char((char *)hotkeys + i) == c) {
break; break;
} }
i += utfc_ptr2len(hotkeys + i) - 1; i += utfc_ptr2len((char *)hotkeys + i) - 1;
retval++; retval++;
} }
if (hotkeys[i]) { if (hotkeys[i]) {
@ -3508,10 +3508,10 @@ static int copy_char(const char_u *from, char_u *to, bool lowercase)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_NONNULL_ALL
{ {
if (lowercase) { if (lowercase) {
int c = mb_tolower(utf_ptr2char(from)); int c = mb_tolower(utf_ptr2char((char *)from));
return utf_char2bytes(c, to); return utf_char2bytes(c, to);
} }
int len = utfc_ptr2len(from); int len = utfc_ptr2len((char *)from);
memmove(to, from, (size_t)len); memmove(to, from, (size_t)len);
return len; return len;
} }

View File

@ -702,7 +702,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
vcol = 0; vcol = 0;
while (vcol < offset && *ptr != NUL) { while (vcol < offset && *ptr != NUL) {
vcol += win_chartabsize(curwin, ptr, vcol); vcol += win_chartabsize(curwin, ptr, vcol);
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
} }
ptr_row_offset = ptr; ptr_row_offset = ptr;
@ -713,7 +713,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
ptr_end = ptr_row_offset; ptr_end = ptr_row_offset;
while (vcol < col && *ptr_end != NUL) { while (vcol < col && *ptr_end != NUL) {
vcol += win_chartabsize(curwin, ptr_end, vcol); vcol += win_chartabsize(curwin, ptr_end, vcol);
ptr_end += utfc_ptr2len(ptr_end); ptr_end += utfc_ptr2len((char *)ptr_end);
} }
int matchid; int matchid;
@ -723,8 +723,8 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
vcol = offset; vcol = offset;
#define INCR() nudge++; ptr_end += utfc_ptr2len(ptr_end) #define INCR() nudge++; ptr_end += utfc_ptr2len((char *)ptr_end)
#define DECR() nudge--; ptr_end -= utfc_ptr2len(ptr_end) #define DECR() nudge--; ptr_end -= utfc_ptr2len((char *)ptr_end)
while (ptr < ptr_end && *ptr != NUL) { while (ptr < ptr_end && *ptr != NUL) {
cwidth = win_chartabsize(curwin, ptr, vcol); cwidth = win_chartabsize(curwin, ptr, vcol);
@ -755,7 +755,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
while (prev_matchid == matchid && *ptr != NUL) { while (prev_matchid == matchid && *ptr != NUL) {
INCR(); INCR();
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
matchid = syn_get_concealed_id(wp, lnum, (colnr_T)(ptr - line)); matchid = syn_get_concealed_id(wp, lnum, (colnr_T)(ptr - line));
} }
@ -763,7 +763,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col)
} }
} }
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
} }
return col + nudge; return col + nudge;
@ -798,8 +798,8 @@ int mouse_check_fold(void)
// Remember the character under the mouse, might be one of foldclose or // Remember the character under the mouse, might be one of foldclose or
// foldopen fillchars in the fold column. // foldopen fillchars in the fold column.
if (gp->chars != NULL) { if (gp->chars != NULL) {
mouse_char = utf_ptr2char(gp->chars[gp->line_offset[row] mouse_char = utf_ptr2char((char *)gp->chars[gp->line_offset[row]
+ (unsigned)col]); + (unsigned)col]);
} }
// Check for position outside of the fold column. // Check for position outside of the fold column.

View File

@ -2094,7 +2094,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent)
find_start_of_word(&VIsual); find_start_of_word(&VIsual);
if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) { if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) {
curwin->w_cursor.col += curwin->w_cursor.col +=
utfc_ptr2len(get_cursor_pos_ptr()); utfc_ptr2len((char *)get_cursor_pos_ptr());
} }
find_end_of_word(&curwin->w_cursor); find_end_of_word(&curwin->w_cursor);
} }
@ -2157,7 +2157,7 @@ static void find_end_of_word(pos_T *pos)
} }
cclass = get_mouse_class(line + pos->col); cclass = get_mouse_class(line + pos->col);
while (line[pos->col] != NUL) { while (line[pos->col] != NUL) {
col = pos->col + utfc_ptr2len(line + pos->col); col = pos->col + utfc_ptr2len((char *)line + pos->col);
if (get_mouse_class(line + col) != cclass) { if (get_mouse_class(line + col) != cclass) {
if (*p_sel == 'e') { if (*p_sel == 'e') {
pos->col = col; pos->col = col;
@ -2340,7 +2340,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **te
if (this_class != 0 && (i == 1 || this_class != 1)) { if (this_class != 0 && (i == 1 || this_class != 1)) {
break; break;
} }
col += utfc_ptr2len(ptr + col); col += utfc_ptr2len((char *)ptr + col);
} }
// When starting on a ']' count it, so that we include the '['. // When starting on a ']' count it, so that we include the '['.
@ -2408,7 +2408,7 @@ size_t find_ident_at_pos(win_T *wp, linenr_T lnum, colnr_T startcol, char_u **te
|| ((find_type & FIND_EVAL) || ((find_type & FIND_EVAL)
&& col <= (int)startcol && col <= (int)startcol
&& find_is_eval_item(ptr + col, &col, &bn, FORWARD)))) { && find_is_eval_item(ptr + col, &col, &bn, FORWARD)))) {
col += utfc_ptr2len(ptr + col); col += utfc_ptr2len((char *)ptr + col);
} }
assert(col >= 0); assert(col >= 0);
@ -2585,7 +2585,7 @@ void clear_showcmd(void)
e = ml_get_pos(&VIsual); e = ml_get_pos(&VIsual);
} }
while ((*p_sel != 'e') ? s <= e : s < e) { while ((*p_sel != 'e') ? s <= e : s < e) {
l = utfc_ptr2len(s); l = utfc_ptr2len((char *)s);
if (l == 0) { if (l == 0) {
bytes++; bytes++;
chars++; chars++;
@ -3262,7 +3262,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist)
virtcol -= vim_strsize(get_showbreak_value(curwin)); virtcol -= vim_strsize(get_showbreak_value(curwin));
} }
int c = utf_ptr2char(get_cursor_pos_ptr()); int c = utf_ptr2char((char *)get_cursor_pos_ptr());
if (dir == FORWARD && virtcol < curwin->w_curswant if (dir == FORWARD && virtcol < curwin->w_curswant
&& (curwin->w_curswant <= (colnr_T)width1) && (curwin->w_curswant <= (colnr_T)width1)
&& !vim_isprintc(c) && c > 255) { && !vim_isprintc(c) && c > 255) {
@ -4239,7 +4239,7 @@ static void nv_ident(cmdarg_T *cap)
} }
// When current byte is a part of multibyte character, copy all // When current byte is a part of multibyte character, copy all
// bytes of that character. // bytes of that character.
const size_t len = (size_t)(utfc_ptr2len(ptr) - 1); const size_t len = (size_t)(utfc_ptr2len((char *)ptr) - 1);
for (size_t i = 0; i < len && n > 0; i++, n--) { for (size_t i = 0; i < len && n > 0; i++, n--) {
*p++ = *ptr++; *p++ = *ptr++;
} }
@ -4308,7 +4308,7 @@ bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp)
} }
if (*lenp > 0) { if (*lenp > 0) {
// Correct the length to include all bytes of the last character. // Correct the length to include all bytes of the last character.
*lenp += (size_t)(utfc_ptr2len(*pp + (*lenp - 1)) - 1); *lenp += (size_t)(utfc_ptr2len((char *)(*pp) + (*lenp - 1)) - 1);
} }
} }
reset_VIsual_and_resel(); reset_VIsual_and_resel();
@ -4470,7 +4470,7 @@ static void nv_right(cmdarg_T *cap)
if (virtual_active()) { if (virtual_active()) {
oneright(); oneright();
} else { } else {
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
} }
} }
} }
@ -4521,7 +4521,7 @@ static void nv_left(cmdarg_T *cap)
char_u *cp = get_cursor_pos_ptr(); char_u *cp = get_cursor_pos_ptr();
if (*cp != NUL) { if (*cp != NUL) {
curwin->w_cursor.col += utfc_ptr2len(cp); curwin->w_cursor.col += utfc_ptr2len((char *)cp);
} }
cap->retval |= CA_NO_ADJ_OP_END; cap->retval |= CA_NO_ADJ_OP_END;
} }

View File

@ -381,7 +381,7 @@ static void shift_block(oparg_T *oap, int amount)
colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp;
char_u *old_textstart = bd.textstart; char_u *old_textstart = bd.textstart;
if (bd.startspaces) { if (bd.startspaces) {
if (utfc_ptr2len(bd.textstart) == 1) { if (utfc_ptr2len((char *)bd.textstart) == 1) {
bd.textstart++; bd.textstart++;
} else { } else {
ws_vcol = 0; ws_vcol = 0;
@ -2034,7 +2034,7 @@ static int op_replace(oparg_T *oap, int c)
n = gchar_cursor(); n = gchar_cursor();
if (n != NUL) { if (n != NUL) {
int new_byte_len = utf_char2len(c); int new_byte_len = utf_char2len(c);
int old_byte_len = utfc_ptr2len(get_cursor_pos_ptr()); int old_byte_len = utfc_ptr2len((char *)get_cursor_pos_ptr());
if (new_byte_len > 1 || old_byte_len > 1) { if (new_byte_len > 1 || old_byte_len > 1) {
// This is slow, but it handles replacing a single-byte // This is slow, but it handles replacing a single-byte
@ -2195,7 +2195,7 @@ static int swapchars(int op_type, pos_T *pos, int length)
int did_change = 0; int did_change = 0;
for (int todo = length; todo > 0; todo--) { for (int todo = length; todo > 0; todo--) {
const int len = utfc_ptr2len(ml_get_pos(pos)); const int len = utfc_ptr2len((char *)ml_get_pos(pos));
// we're counting bytes, not characters // we're counting bytes, not characters
if (len > 0) { if (len > 0) {
@ -2256,7 +2256,7 @@ bool swapchar(int op_type, pos_T *pos)
curwin->w_cursor = *pos; curwin->w_cursor = *pos;
// don't use del_char(), it also removes composing chars // don't use del_char(), it also removes composing chars
del_bytes(utf_ptr2len(get_cursor_pos_ptr()), false, false); del_bytes(utf_ptr2len((char *)get_cursor_pos_ptr()), false, false);
ins_char(nc); ins_char(nc);
curwin->w_cursor = sp; curwin->w_cursor = sp;
} else { } else {
@ -3076,7 +3076,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
bool one_past_line = (*cursor_pos == NUL); bool one_past_line = (*cursor_pos == NUL);
bool eol = false; bool eol = false;
if (!one_past_line) { if (!one_past_line) {
eol = (*(cursor_pos + utfc_ptr2len(cursor_pos)) == NUL); eol = (*(cursor_pos + utfc_ptr2len((char *)cursor_pos)) == NUL);
} }
bool ve_allows = (cur_ve_flags == VE_ALL || cur_ve_flags == VE_ONEMORE); bool ve_allows = (cur_ve_flags == VE_ALL || cur_ve_flags == VE_ONEMORE);
@ -3291,7 +3291,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
} }
// move to start of next multi-byte character // move to start of next multi-byte character
curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr());
col++; col++;
} else { } else {
getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2); getvcol(curwin, &curwin->w_cursor, &col, NULL, &endcol2);
@ -3466,7 +3466,7 @@ void do_put(int regname, yankreg_T *reg, int dir, long count, int flags)
// if type is kMTCharWise, FORWARD is the same as BACKWARD on the next // if type is kMTCharWise, FORWARD is the same as BACKWARD on the next
// char // char
if (dir == FORWARD && gchar_cursor() != NUL) { if (dir == FORWARD && gchar_cursor() != NUL) {
int bytelen = utfc_ptr2len(get_cursor_pos_ptr()); int bytelen = utfc_ptr2len((char *)get_cursor_pos_ptr());
// put it on the next of the multi-byte character. // put it on the next of the multi-byte character.
col += bytelen; col += bytelen;
@ -3898,7 +3898,7 @@ void ex_display(exarg_T *eap)
n -= 2; n -= 2;
} }
for (p = yb->y_array[j]; *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { // -V1019 for (p = yb->y_array[j]; *p != NUL && (n -= ptr2cells(p)) >= 0; p++) { // -V1019
clen = utfc_ptr2len(p); clen = utfc_ptr2len((char *)p);
msg_outtrans_len(p, clen); msg_outtrans_len(p, clen);
p += clen - 1; p += clen - 1;
} }
@ -3976,7 +3976,7 @@ static void dis_msg(const char_u *p, bool skip_esc)
while (*p != NUL while (*p != NUL
&& !(*p == ESC && skip_esc && *(p + 1) == NUL) && !(*p == ESC && skip_esc && *(p + 1) == NUL)
&& (n -= ptr2cells(p)) >= 0) { && (n -= ptr2cells(p)) >= 0) {
if ((l = utfc_ptr2len(p)) > 1) { if ((l = utfc_ptr2len((char *)p)) > 1) {
msg_outtrans_len(p, l); msg_outtrans_len(p, l);
p += l; p += l;
} else { } else {
@ -4120,11 +4120,11 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
&& sumsize != 0 && sumsize != 0
&& endcurr1 != TAB && endcurr1 != TAB
&& (!has_format_option(FO_MBYTE_JOIN) && (!has_format_option(FO_MBYTE_JOIN)
|| (utf_ptr2char(curr) < 0x100 && endcurr1 < 0x100)) || (utf_ptr2char((char *)curr) < 0x100 && endcurr1 < 0x100))
&& (!has_format_option(FO_MBYTE_JOIN2) && (!has_format_option(FO_MBYTE_JOIN2)
|| (utf_ptr2char(curr) < 0x100 && !utf_eat_space(endcurr1)) || (utf_ptr2char((char *)curr) < 0x100 && !utf_eat_space(endcurr1))
|| (endcurr1 < 0x100 || (endcurr1 < 0x100
&& !utf_eat_space(utf_ptr2char(curr))))) { && !utf_eat_space(utf_ptr2char((char *)curr))))) {
// don't add a space if the line is ending in a space // don't add a space if the line is ending in a space
if (endcurr1 == ' ') { if (endcurr1 == ' ') {
endcurr1 = endcurr2; endcurr1 = endcurr2;
@ -4151,10 +4151,10 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions
if (insert_space && currsize > 0) { if (insert_space && currsize > 0) {
cend = curr + currsize; cend = curr + currsize;
MB_PTR_BACK(curr, cend); MB_PTR_BACK(curr, cend);
endcurr1 = utf_ptr2char(cend); endcurr1 = utf_ptr2char((char *)cend);
if (cend > curr) { if (cend > curr) {
MB_PTR_BACK(curr, cend); MB_PTR_BACK(curr, cend);
endcurr2 = utf_ptr2char(cend); endcurr2 = utf_ptr2char((char *)cend);
} }
} }
line_breakcheck(); line_breakcheck();
@ -5117,7 +5117,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1)
if (visual) { if (visual) {
while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col]) while (ptr[col] != NUL && length > 0 && !ascii_isdigit(ptr[col])
&& !(do_alpha && ASCII_ISALPHA(ptr[col]))) { && !(do_alpha && ASCII_ISALPHA(ptr[col]))) {
int mb_len = utfc_ptr2len(ptr + col); int mb_len = utfc_ptr2len((char *)ptr + col);
col += mb_len; col += mb_len;
length -= mb_len; length -= mb_len;
@ -5842,7 +5842,7 @@ static varnumber_T line_count_info(char_u *line, varnumber_T *wc, varnumber_T *c
is_word = 1; is_word = 1;
} }
chars++; chars++;
i += utfc_ptr2len(line + i); i += utfc_ptr2len((char *)line + i);
} }
if (is_word) { if (is_word) {
@ -6592,7 +6592,7 @@ void do_pending_operator(cmdarg_T *cap, int old_col, bool gui_yank)
// Include the trailing byte of a multi-byte char. // Include the trailing byte of a multi-byte char.
if (oap->inclusive) { if (oap->inclusive) {
const int l = utfc_ptr2len(ml_get_pos(&oap->end)); const int l = utfc_ptr2len((char *)ml_get_pos(&oap->end));
if (l > 1) { if (l > 1) {
oap->end.col += l - 1; oap->end.col += l - 1;
} }

View File

@ -1502,7 +1502,7 @@ int do_set(char_u *arg, int opt_flags)
) { ) {
arg++; // remove backslash arg++; // remove backslash
} }
i = utfc_ptr2len(arg); i = utfc_ptr2len((char *)arg);
if (i > 1) { if (i > 1) {
// copy multibyte char // copy multibyte char
memmove(s, arg, (size_t)i); memmove(s, arg, (size_t)i);
@ -2664,13 +2664,13 @@ ambw_end:
int x2 = -1; int x2 = -1;
int x3 = -1; int x3 = -1;
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
if (*p != NUL) { if (*p != NUL) {
x2 = *p++; x2 = *p++;
} }
if (*p != NUL) { if (*p != NUL) {
x3 = utf_ptr2char(p); x3 = utf_ptr2char((char *)p);
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
} }
if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) { if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
errmsg = e_invarg; errmsg = e_invarg;
@ -3526,7 +3526,7 @@ static int get_encoded_char_adv(char_u **p)
} }
// TODO(bfredl): use schar_T representation and utfc_ptr2len // TODO(bfredl): use schar_T representation and utfc_ptr2len
int clen = utf_ptr2len(s); int clen = utf_ptr2len((char *)s);
int c = mb_cptr2char_adv((const char_u **)p); int c = mb_cptr2char_adv((const char_u **)p);
if (clen == 1 && c > 127) { // Invalid UTF-8 byte if (clen == 1 && c > 127) { // Invalid UTF-8 byte
return 0; return 0;
@ -7140,7 +7140,7 @@ static void langmap_set(void)
if (p[0] == '\\' && p[1] != NUL) { if (p[0] == '\\' && p[1] != NUL) {
p++; p++;
} }
from = utf_ptr2char(p); from = utf_ptr2char((char *)p);
to = NUL; to = NUL;
if (p2 == NULL) { if (p2 == NULL) {
MB_PTR_ADV(p); MB_PTR_ADV(p);
@ -7148,14 +7148,14 @@ static void langmap_set(void)
if (p[0] == '\\') { if (p[0] == '\\') {
p++; p++;
} }
to = utf_ptr2char(p); to = utf_ptr2char((char *)p);
} }
} else { } else {
if (p2[0] != ',') { if (p2[0] != ',') {
if (p2[0] == '\\') { if (p2[0] == '\\') {
p2++; p2++;
} }
to = utf_ptr2char(p2); to = utf_ptr2char((char *)p2);
} }
} }
if (to == NUL) { if (to == NUL) {

View File

@ -299,7 +299,7 @@ void shorten_dir_len(char_u *str, int trim_len)
skip = true; skip = true;
} }
} }
int l = utfc_ptr2len(s); int l = utfc_ptr2len((char *)s);
while (--l > 0) { while (--l > 0) {
*d++ = *++s; *d++ = *++s;
} }
@ -642,12 +642,12 @@ static size_t do_path_expand(garray_T *gap, const char_u *path, size_t wildoff,
} else if (path_end >= path + wildoff } else if (path_end >= path + wildoff
&& (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL
#ifndef WIN32 #ifndef WIN32
|| (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char(path_end))) || (!p_fic && (flags & EW_ICASE) && mb_isalpha(utf_ptr2char((char *)path_end)))
#endif #endif
)) { )) {
e = p; e = p;
} }
len = (size_t)(utfc_ptr2len(path_end)); len = (size_t)(utfc_ptr2len((char *)path_end));
memcpy(p, path_end, len); memcpy(p, path_end, len);
p += len; p += len;
path_end += len; path_end += len;
@ -1980,8 +1980,8 @@ int pathcmp(const char *p, const char *q, int maxlen)
const char *s = NULL; const char *s = NULL;
for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) { for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) {
c1 = utf_ptr2char((char_u *)p + i); c1 = utf_ptr2char(p + i);
c2 = utf_ptr2char((char_u *)q + j); c2 = utf_ptr2char(q + j);
// End of "p": check if "q" also ends or just has a slash. // End of "p": check if "q" also ends or just has a slash.
if (c1 == NUL) { if (c1 == NUL) {
@ -2016,15 +2016,15 @@ int pathcmp(const char *p, const char *q, int maxlen)
: c1 - c2; // no match : c1 - c2; // no match
} }
i += utfc_ptr2len((char_u *)p + i); i += utfc_ptr2len(p + i);
j += utfc_ptr2len((char_u *)q + j); j += utfc_ptr2len(q + j);
} }
if (s == NULL) { // "i" or "j" ran into "maxlen" if (s == NULL) { // "i" or "j" ran into "maxlen"
return 0; return 0;
} }
c1 = utf_ptr2char((char_u *)s + i); c1 = utf_ptr2char(s + i);
c2 = utf_ptr2char((char_u *)s + i + utfc_ptr2len((char_u *)s + i)); c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i));
// ignore a trailing slash, but not "//" or ":/" // ignore a trailing slash, but not "//" or ":/"
if (c2 == NUL if (c2 == NUL
&& i > 0 && i > 0

View File

@ -521,7 +521,7 @@ void pum_redraw(void)
if (size > pum_width) { if (size > pum_width) {
do { do {
size -= utf_ptr2cells(rt); size -= utf_ptr2cells((char *)rt);
MB_PTR_ADV(rt); MB_PTR_ADV(rt);
} while (size > pum_width); } while (size > pum_width);

View File

@ -392,9 +392,9 @@ static int get_equi_class(char_u **pp)
char_u *p = *pp; char_u *p = *pp;
if (p[1] == '=' && p[2] != NUL) { if (p[1] == '=' && p[2] != NUL) {
l = utfc_ptr2len(p + 2); l = utfc_ptr2len((char *)p + 2);
if (p[l + 2] == '=' && p[l + 3] == ']') { if (p[l + 2] == '=' && p[l + 3] == ']') {
c = utf_ptr2char(p + 2); c = utf_ptr2char((char *)p + 2);
*pp += l + 4; *pp += l + 4;
return c; return c;
} }
@ -416,9 +416,9 @@ static int get_coll_element(char_u **pp)
char_u *p = *pp; char_u *p = *pp;
if (p[0] != NUL && p[1] == '.' && p[2] != NUL) { if (p[0] != NUL && p[1] == '.' && p[2] != NUL) {
l = utfc_ptr2len(p + 2); l = utfc_ptr2len((char *)p + 2);
if (p[l + 2] == '.' && p[l + 3] == ']') { if (p[l + 2] == '.' && p[l + 3] == ']') {
c = utf_ptr2char(p + 2); c = utf_ptr2char((char *)p + 2);
*pp += l + 4; *pp += l + 4;
return c; return c;
} }
@ -449,7 +449,7 @@ static char_u *skip_anyof(char_u *p)
p++; p++;
} }
while (*p != NUL && *p != ']') { while (*p != NUL && *p != ']') {
if ((l = utfc_ptr2len(p)) > 1) { if ((l = utfc_ptr2len((char *)p)) > 1) {
p += l; p += l;
} else if (*p == '-') { } else if (*p == '-') {
p++; p++;
@ -719,13 +719,13 @@ static int peekchr(void)
* Next character can never be (made) magic? * Next character can never be (made) magic?
* Then backslashing it won't do anything. * Then backslashing it won't do anything.
*/ */
curchr = utf_ptr2char(regparse + 1); curchr = utf_ptr2char((char *)regparse + 1);
} }
break; break;
} }
default: default:
curchr = utf_ptr2char(regparse); curchr = utf_ptr2char((char *)regparse);
} }
return curchr; return curchr;
@ -744,7 +744,7 @@ static void skipchr(void)
} }
if (regparse[prevchr_len] != NUL) { if (regparse[prevchr_len] != NUL) {
// Exclude composing chars that utfc_ptr2len does include. // Exclude composing chars that utfc_ptr2len does include.
prevchr_len += utf_ptr2len(regparse + prevchr_len); prevchr_len += utf_ptr2len((char *)regparse + prevchr_len);
} }
regparse += prevchr_len; regparse += prevchr_len;
prev_at_start = at_start; prev_at_start = at_start;
@ -1463,8 +1463,8 @@ static inline char_u *cstrchr(const char_u *const s, const int c)
// expected to be highly optimized. // expected to be highly optimized.
if (c > 0x80) { if (c > 0x80) {
const int folded_c = utf_fold(c); const int folded_c = utf_fold(c);
for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) { for (const char_u *p = s; *p != NUL; p += utfc_ptr2len((char *)p)) {
if (utf_fold(utf_ptr2char(p)) == folded_c) { if (utf_fold(utf_ptr2char((char *)p)) == folded_c) {
return (char_u *)p; return (char_u *)p;
} }
} }
@ -1571,7 +1571,7 @@ char_u *regtilde(char_u *source, int magic, bool preview)
if (*p == '\\' && p[1]) { // skip escaped characters if (*p == '\\' && p[1]) { // skip escaped characters
p++; p++;
} }
p += utfc_ptr2len(p) - 1; p += utfc_ptr2len((char *)p) - 1;
} }
} }
@ -1914,7 +1914,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
c = *src++; c = *src++;
} }
} else { } else {
c = utf_ptr2char(src - 1); c = utf_ptr2char((char *)src - 1);
} }
// Write to buffer, if copy is set. // Write to buffer, if copy is set.
if (func_one != NULL) { if (func_one != NULL) {
@ -1926,13 +1926,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
cc = c; cc = c;
} }
int totlen = utfc_ptr2len(src - 1); int totlen = utfc_ptr2len((char *)src - 1);
if (copy) { if (copy) {
utf_char2bytes(cc, dst); utf_char2bytes(cc, dst);
} }
dst += utf_char2len(cc) - 1; dst += utf_char2len(cc) - 1;
int clen = utf_ptr2len(src - 1); int clen = utf_ptr2len((char *)src - 1);
// If the character length is shorter than "totlen", there // If the character length is shorter than "totlen", there
// are composing characters; copy them as-is. // are composing characters; copy them as-is.
@ -2005,7 +2005,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
} }
dst += 2; dst += 2;
} else { } else {
c = utf_ptr2char(s); c = utf_ptr2char((char *)s);
if (func_one != (fptr_T)NULL) { if (func_one != (fptr_T)NULL) {
// Turbo C complains without the typecast // Turbo C complains without the typecast
@ -2022,7 +2022,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest,
// Copy composing characters separately, one // Copy composing characters separately, one
// at a time. // at a time.
l = utf_ptr2len(s) - 1; l = utf_ptr2len((char *)s) - 1;
s += l; s += l;
len -= l; len -= l;

View File

@ -1895,8 +1895,8 @@ collection:
} else { } else {
// produce a multibyte character, including any // produce a multibyte character, including any
// following composing characters. // following composing characters.
startc = utf_ptr2char(regparse); startc = utf_ptr2char((char *)regparse);
int len = utfc_ptr2len(regparse); int len = utfc_ptr2len((char *)regparse);
if (utf_char2len(startc) != len) { if (utf_char2len(startc) != len) {
// composing chars // composing chars
startc = -1; startc = -1;
@ -1953,11 +1953,11 @@ do_multibyte:
// Need to get composing character too. // Need to get composing character too.
for (;; ) { for (;; ) {
l = utf_ptr2len(regparse); l = utf_ptr2len((char *)regparse);
if (!utf_composinglike(regparse, regparse + l)) { if (!utf_composinglike(regparse, regparse + l)) {
break; break;
} }
regmbc(utf_ptr2char(regparse)); regmbc(utf_ptr2char((char *)regparse));
skipchr(); skipchr();
} }
} }
@ -2403,7 +2403,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
} }
if (OP(scan) == EXACTLY) { if (OP(scan) == EXACTLY) {
r->regstart = utf_ptr2char(OPERAND(scan)); r->regstart = utf_ptr2char((char *)OPERAND(scan));
} else if (OP(scan) == BOW } else if (OP(scan) == BOW
|| OP(scan) == EOW || OP(scan) == EOW
|| OP(scan) == NOTHING || OP(scan) == NOTHING
@ -2411,7 +2411,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags)
|| OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) {
char_u *regnext_scan = regnext(scan); char_u *regnext_scan = regnext(scan);
if (OP(regnext_scan) == EXACTLY) { if (OP(regnext_scan) == EXACTLY) {
r->regstart = utf_ptr2char(OPERAND(regnext_scan)); r->regstart = utf_ptr2char((char *)OPERAND(regnext_scan));
} }
} }
@ -2614,7 +2614,7 @@ regrepeat(
case SIDENT: case SIDENT:
case SIDENT + ADD_NL: case SIDENT + ADD_NL:
while (count < maxcount) { while (count < maxcount) {
if (vim_isIDc(utf_ptr2char(scan)) && (testval || !ascii_isdigit(*scan))) { if (vim_isIDc(utf_ptr2char((char *)scan)) && (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan); MB_PTR_ADV(scan);
} else if (*scan == NUL) { } else if (*scan == NUL) {
if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline
@ -2671,7 +2671,7 @@ regrepeat(
case SFNAME: case SFNAME:
case SFNAME + ADD_NL: case SFNAME + ADD_NL:
while (count < maxcount) { while (count < maxcount) {
if (vim_isfilec(utf_ptr2char(scan)) && (testval || !ascii_isdigit(*scan))) { if (vim_isfilec(utf_ptr2char((char *)scan)) && (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan); MB_PTR_ADV(scan);
} else if (*scan == NUL) { } else if (*scan == NUL) {
if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline
@ -2709,7 +2709,7 @@ regrepeat(
if (got_int) { if (got_int) {
break; break;
} }
} else if (vim_isprintc(utf_ptr2char(scan)) == 1 } else if (vim_isprintc(utf_ptr2char((char *)scan)) == 1
&& (testval || !ascii_isdigit(*scan))) { && (testval || !ascii_isdigit(*scan))) {
MB_PTR_ADV(scan); MB_PTR_ADV(scan);
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
@ -2737,7 +2737,7 @@ do_class:
if (got_int) { if (got_int) {
break; break;
} }
} else if ((l = utfc_ptr2len(scan)) > 1) { } else if ((l = utfc_ptr2len((char *)scan)) > 1) {
if (testval != 0) { if (testval != 0) {
break; break;
} }
@ -2852,18 +2852,18 @@ do_class:
// Safety check (just in case 'encoding' was changed since // Safety check (just in case 'encoding' was changed since
// compiling the program). // compiling the program).
if ((len = utfc_ptr2len(opnd)) > 1) { if ((len = utfc_ptr2len((char *)opnd)) > 1) {
if (rex.reg_ic) { if (rex.reg_ic) {
cf = utf_fold(utf_ptr2char(opnd)); cf = utf_fold(utf_ptr2char((char *)opnd));
} }
while (count < maxcount && utfc_ptr2len(scan) >= len) { while (count < maxcount && utfc_ptr2len((char *)scan) >= len) {
for (i = 0; i < len; i++) { for (i = 0; i < len; i++) {
if (opnd[i] != scan[i]) { if (opnd[i] != scan[i]) {
break; break;
} }
} }
if (i < len && (!rex.reg_ic if (i < len && (!rex.reg_ic
|| utf_fold(utf_ptr2char(scan)) != cf)) { || utf_fold(utf_ptr2char((char *)scan)) != cf)) {
break; break;
} }
scan += len; scan += len;
@ -2894,8 +2894,8 @@ do_class:
} }
} else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) {
scan++; scan++;
} else if ((len = utfc_ptr2len(scan)) > 1) { } else if ((len = utfc_ptr2len((char *)scan)) > 1) {
if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { if ((cstrchr(opnd, utf_ptr2char((char *)scan)) == NULL) == testval) {
break; break;
} }
scan += len; scan += len;
@ -3106,7 +3106,7 @@ static bool regmatch(
if (WITH_NL(op)) { if (WITH_NL(op)) {
op -= ADD_NL; op -= ADD_NL;
} }
c = utf_ptr2char(rex.input); c = utf_ptr2char((char *)rex.input);
switch (op) { switch (op) {
case BOL: case BOL:
if (rex.input != rex.line) { if (rex.input != rex.line) {
@ -3308,7 +3308,7 @@ static bool regmatch(
break; break;
case PRINT: case PRINT:
if (!vim_isprintc(utf_ptr2char(rex.input))) { if (!vim_isprintc(utf_ptr2char((char *)rex.input))) {
status = RA_NOMATCH; status = RA_NOMATCH;
} else { } else {
ADVANCE_REGINPUT(); ADVANCE_REGINPUT();
@ -3316,7 +3316,7 @@ static bool regmatch(
break; break;
case SPRINT: case SPRINT:
if (ascii_isdigit(*rex.input) || !vim_isprintc(utf_ptr2char(rex.input))) { if (ascii_isdigit(*rex.input) || !vim_isprintc(utf_ptr2char((char *)rex.input))) {
status = RA_NOMATCH; status = RA_NOMATCH;
} else { } else {
ADVANCE_REGINPUT(); ADVANCE_REGINPUT();
@ -3507,25 +3507,25 @@ static bool regmatch(
const char_u *opnd = OPERAND(scan); const char_u *opnd = OPERAND(scan);
// Safety check (just in case 'encoding' was changed since // Safety check (just in case 'encoding' was changed since
// compiling the program). // compiling the program).
if ((len = utfc_ptr2len(opnd)) < 2) { if ((len = utfc_ptr2len((char *)opnd)) < 2) {
status = RA_NOMATCH; status = RA_NOMATCH;
break; break;
} }
const int opndc = utf_ptr2char(opnd); const int opndc = utf_ptr2char((char *)opnd);
if (utf_iscomposing(opndc)) { if (utf_iscomposing(opndc)) {
// When only a composing char is given match at any // When only a composing char is given match at any
// position where that composing char appears. // position where that composing char appears.
status = RA_NOMATCH; status = RA_NOMATCH;
for (i = 0; rex.input[i] != NUL; for (i = 0; rex.input[i] != NUL;
i += utf_ptr2len(rex.input + i)) { i += utf_ptr2len((char *)rex.input + i)) {
const int inpc = utf_ptr2char(rex.input + i); const int inpc = utf_ptr2char((char *)rex.input + i);
if (!utf_iscomposing(inpc)) { if (!utf_iscomposing(inpc)) {
if (i > 0) { if (i > 0) {
break; break;
} }
} else if (opndc == inpc) { } else if (opndc == inpc) {
// Include all following composing chars. // Include all following composing chars.
len = i + utfc_ptr2len(rex.input + i); len = i + utfc_ptr2len((char *)rex.input + i);
status = RA_MATCH; status = RA_MATCH;
break; break;
} }
@ -3545,7 +3545,7 @@ static bool regmatch(
case RE_COMPOSING: case RE_COMPOSING:
{ {
// Skip composing characters. // Skip composing characters.
while (utf_iscomposing(utf_ptr2char(rex.input))) { while (utf_iscomposing(utf_ptr2char((char *)rex.input))) {
MB_CPTR_ADV(rex.input); MB_CPTR_ADV(rex.input);
} }
} }
@ -4495,7 +4495,7 @@ static long bt_regexec_both(char_u *line,
// If there is a "must appear" string, look for it. // If there is a "must appear" string, look for it.
if (prog->regmust != NULL) { if (prog->regmust != NULL) {
int c = utf_ptr2char(prog->regmust); int c = utf_ptr2char((char *)prog->regmust);
s = line + col; s = line + col;
// This is used very often, esp. for ":global". Use two versions of // This is used very often, esp. for ":global". Use two versions of
@ -4526,7 +4526,7 @@ static long bt_regexec_both(char_u *line,
// Simplest case: Anchored match need be tried only once. // Simplest case: Anchored match need be tried only once.
if (prog->reganch) { if (prog->reganch) {
int c = utf_ptr2char(rex.line + col); int c = utf_ptr2char((char *)rex.line + col);
if (prog->regstart == NUL if (prog->regstart == NUL
|| prog->regstart == c || prog->regstart == c
|| (rex.reg_ic || (rex.reg_ic
@ -4570,7 +4570,7 @@ static long bt_regexec_both(char_u *line,
if (rex.line[col] == NUL) { if (rex.line[col] == NUL) {
break; break;
} }
col += utfc_ptr2len(rex.line + col); col += utfc_ptr2len((char *)rex.line + col);
// Check for timeout once in a twenty times to avoid overhead. // Check for timeout once in a twenty times to avoid overhead.
if (tm != NULL && ++tm_count == 20) { if (tm != NULL && ++tm_count == 20) {
tm_count = 0; tm_count = 0;

View File

@ -1465,7 +1465,7 @@ static int nfa_regatom(void)
return FAIL; return FAIL;
} }
for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) { for (lp = reg_prev_sub; *lp != NUL; MB_CPTR_ADV(lp)) {
EMIT(utf_ptr2char(lp)); EMIT(utf_ptr2char((char *)lp));
if (lp != reg_prev_sub) { if (lp != reg_prev_sub) {
EMIT(NFA_CONCAT); EMIT(NFA_CONCAT);
} }
@ -1902,7 +1902,7 @@ collection:
// Normal printable char // Normal printable char
if (startc == -1) { if (startc == -1) {
startc = utf_ptr2char(regparse); startc = utf_ptr2char((char *)regparse);
} }
/* Previous char was '-', so this char is end of range. */ /* Previous char was '-', so this char is end of range. */
@ -2007,7 +2007,7 @@ collection:
nfa_do_multibyte: nfa_do_multibyte:
// plen is length of current char with composing chars // plen is length of current char with composing chars
if (utf_char2len(c) != (plen = utfc_ptr2len(old_regparse)) if (utf_char2len(c) != (plen = utfc_ptr2len((char *)old_regparse))
|| utf_iscomposing(c)) { || utf_iscomposing(c)) {
int i = 0; int i = 0;
@ -2025,7 +2025,7 @@ nfa_do_multibyte:
EMIT(NFA_CONCAT); EMIT(NFA_CONCAT);
if ((i += utf_char2len(c)) >= plen) if ((i += utf_char2len(c)) >= plen)
break; break;
c = utf_ptr2char(old_regparse + i); c = utf_ptr2char((char *)old_regparse + i);
} }
EMIT(NFA_COMPOSING); EMIT(NFA_COMPOSING);
regparse = old_regparse + plen; regparse = old_regparse + plen;
@ -5167,17 +5167,17 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
#define PTR2LEN(x) utf_ptr2len(x) #define PTR2LEN(x) utf_ptr2len(x)
colnr_T col = startcol; colnr_T col = startcol;
int regstart_len = PTR2LEN(rex.line + startcol); int regstart_len = PTR2LEN((char *)rex.line + startcol);
for (;;) { for (;;) {
bool match = true; bool match = true;
char_u *s1 = match_text; char_u *s1 = match_text;
char_u *s2 = rex.line + col + regstart_len; // skip regstart char_u *s2 = rex.line + col + regstart_len; // skip regstart
while (*s1) { while (*s1) {
int c1_len = PTR2LEN(s1); int c1_len = PTR2LEN((char *)s1);
int c1 = utf_ptr2char(s1); int c1 = utf_ptr2char((char *)s1);
int c2_len = PTR2LEN(s2); int c2_len = PTR2LEN((char *)s2);
int c2 = utf_ptr2char(s2); int c2 = utf_ptr2char((char *)s2);
if ((c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2))) if ((c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2)))
|| c1_len != c2_len) { || c1_len != c2_len) {
@ -5189,7 +5189,7 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text)
} }
if (match if (match
// check that no composing char follows // check that no composing char follows
&& !utf_iscomposing(utf_ptr2char(s2))) { && !utf_iscomposing(utf_ptr2char((char *)s2))) {
cleanup_subexpr(); cleanup_subexpr();
if (REG_MULTI) { if (REG_MULTI) {
rex.reg_startpos[0].lnum = rex.lnum; rex.reg_startpos[0].lnum = rex.lnum;
@ -5343,8 +5343,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
* Run for each character. * Run for each character.
*/ */
for (;; ) { for (;; ) {
int curc = utf_ptr2char(rex.input); int curc = utf_ptr2char((char *)rex.input);
int clen = utfc_ptr2len(rex.input); int clen = utfc_ptr2len((char *)rex.input);
if (curc == NUL) { if (curc == NUL) {
clen = 0; clen = 0;
go_to_nextline = false; go_to_nextline = false;
@ -5822,7 +5822,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// We don't care about the order of composing characters. // We don't care about the order of composing characters.
// Get them into cchars[] first. // Get them into cchars[] first.
while (len < clen) { while (len < clen) {
mc = utf_ptr2char(rex.input + len); mc = utf_ptr2char((char *)rex.input + len);
cchars[ccount++] = mc; cchars[ccount++] = mc;
len += utf_char2len(mc); len += utf_char2len(mc);
if (ccount == MAX_MCO) { if (ccount == MAX_MCO) {
@ -5987,12 +5987,12 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
break; break;
case NFA_PRINT: // \p case NFA_PRINT: // \p
result = vim_isprintc(utf_ptr2char(rex.input)); result = vim_isprintc(utf_ptr2char((char *)rex.input));
ADD_STATE_IF_MATCH(t->state); ADD_STATE_IF_MATCH(t->state);
break; break;
case NFA_SPRINT: // \P case NFA_SPRINT: // \P
result = !ascii_isdigit(curc) && vim_isprintc(utf_ptr2char(rex.input)); result = !ascii_isdigit(curc) && vim_isprintc(utf_ptr2char((char *)rex.input));
ADD_STATE_IF_MATCH(t->state); ADD_STATE_IF_MATCH(t->state);
break; break;
@ -6346,7 +6346,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// If rex.reg_icombine is not set only skip over the character // If rex.reg_icombine is not set only skip over the character
// itself. When it is set skip over composing characters. // itself. When it is set skip over composing characters.
if (result && !rex.reg_icombine) { if (result && !rex.reg_icombine) {
clen = utf_ptr2len(rex.input); clen = utf_ptr2len((char *)rex.input);
} }
ADD_STATE_IF_MATCH(t->state); ADD_STATE_IF_MATCH(t->state);
@ -6494,7 +6494,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
} else { } else {
// Checking if the required start character matches is // Checking if the required start character matches is
// cheaper than adding a state that won't match. // cheaper than adding a state that won't match.
const int c = utf_ptr2char(rex.input + clen); const int c = utf_ptr2char((char *)rex.input + clen);
if (c != prog->regstart if (c != prog->regstart
&& (!rex.reg_ic && (!rex.reg_ic
|| utf_fold(c) != utf_fold(prog->regstart))) { || utf_fold(c) != utf_fold(prog->regstart))) {

View File

@ -1860,8 +1860,8 @@ static int compute_foldcolumn(win_T *wp, int col)
static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, bool rl, int vcol) static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, bool rl, int vcol)
{ {
const char_u *p = (char_u *)s->p; const char_u *p = (char_u *)s->p;
int cells = utf_ptr2cells(p); int cells = utf_ptr2cells((char *)p);
int c_len = utfc_ptr2len(p); int c_len = utfc_ptr2len((char *)p);
int u8c, u8cc[MAX_MCO]; int u8c, u8cc[MAX_MCO];
if (cells > maxcells) { if (cells > maxcells) {
return -1; return -1;
@ -1888,7 +1888,7 @@ static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, b
if (rl) { if (rl) {
pc = s->prev_c; pc = s->prev_c;
pc1 = s->prev_c1; pc1 = s->prev_c1;
nc = utf_ptr2char(p + c_len); nc = utf_ptr2char((char *)p + c_len);
s->prev_c1 = u8cc[0]; s->prev_c1 = u8cc[0];
} else { } else {
pc = utfc_ptr2char(p + c_len, pcc); pc = utfc_ptr2char(p + c_len, pcc);
@ -2536,7 +2536,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
ptr = prev_ptr; ptr = prev_ptr;
// If the character fits on the screen, don't need to skip it. // If the character fits on the screen, don't need to skip it.
// Except for a TAB. // Except for a TAB.
if (utf_ptr2cells(ptr) >= c || *ptr == TAB) { if (utf_ptr2cells((char *)ptr) >= c || *ptr == TAB) {
n_skip = v - vcol; n_skip = v - vcol;
} }
} }
@ -2960,7 +2960,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
// handle Visual or match highlighting in this line // handle Visual or match highlighting in this line
if (vcol == fromcol if (vcol == fromcol
|| (vcol + 1 == fromcol && n_extra == 0 || (vcol + 1 == fromcol && n_extra == 0
&& utf_ptr2cells(ptr) > 1) && utf_ptr2cells((char *)ptr) > 1)
|| ((int)vcol_prev == fromcol_prev || ((int)vcol_prev == fromcol_prev
&& vcol_prev < vcol // not at margin && vcol_prev < vcol // not at margin
&& vcol < tocol)) { && vcol < tocol)) {
@ -3060,7 +3060,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
mb_c = c; mb_c = c;
// If the UTF-8 character is more than one byte: // If the UTF-8 character is more than one byte:
// Decode it into "mb_c". // Decode it into "mb_c".
mb_l = utfc_ptr2len(p_extra); mb_l = utfc_ptr2len((char *)p_extra);
mb_utf8 = false; mb_utf8 = false;
if (mb_l > n_extra) { if (mb_l > n_extra) {
mb_l = 1; mb_l = 1;
@ -3113,7 +3113,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
mb_c = c; mb_c = c;
// If the UTF-8 character is more than one byte: Decode it // If the UTF-8 character is more than one byte: Decode it
// into "mb_c". // into "mb_c".
mb_l = utfc_ptr2len(ptr); mb_l = utfc_ptr2len((char *)ptr);
mb_utf8 = false; mb_utf8 = false;
if (mb_l > 1) { if (mb_l > 1) {
mb_c = utfc_ptr2char(ptr, u8cc); mb_c = utfc_ptr2char(ptr, u8cc);
@ -3171,7 +3171,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
if (wp->w_p_rl) { if (wp->w_p_rl) {
pc = prev_c; pc = prev_c;
pc1 = prev_c1; pc1 = prev_c1;
nc = utf_ptr2char(ptr + mb_l); nc = utf_ptr2char((char *)ptr + mb_l);
prev_c1 = u8cc[0]; prev_c1 = u8cc[0];
} else { } else {
pc = utfc_ptr2char(ptr + mb_l, pcc); pc = utfc_ptr2char(ptr + mb_l, pcc);
@ -5074,7 +5074,7 @@ void win_redr_status_matches(expand_T *xp, int num_matches, char_u **matches, in
for (; *s != NUL; ++s) { for (; *s != NUL; ++s) {
s += skip_status_match_char(xp, s); s += skip_status_match_char(xp, s);
clen += ptr2cells(s); clen += ptr2cells(s);
if ((l = utfc_ptr2len(s)) > 1) { if ((l = utfc_ptr2len((char *)s)) > 1) {
STRNCPY(buf + len, s, l); // NOLINT(runtime/printf) STRNCPY(buf + len, s, l); // NOLINT(runtime/printf)
s += l - 1; s += l - 1;
len += l; len += l;
@ -5234,8 +5234,8 @@ static void win_redr_status(win_T *wp)
// Find first character that will fit. // Find first character that will fit.
// Going from start to end is much faster for DBCS. // Going from start to end is much faster for DBCS.
for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; for (i = 0; p[i] != NUL && clen >= this_ru_col - 1;
i += utfc_ptr2len(p + i)) { i += utfc_ptr2len((char *)p + i)) {
clen -= utf_ptr2cells(p + i); clen -= utf_ptr2cells((char *)p + i);
} }
len = clen; len = clen;
if (i > 0) { if (i > 0) {
@ -5885,7 +5885,7 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col
if (len > 0) { if (len > 0) {
mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr));
} else { } else {
mbyte_blen = utfc_ptr2len(ptr); mbyte_blen = utfc_ptr2len((char *)ptr);
} }
if (len >= 0) { if (len >= 0) {
u8c = utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)); u8c = utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr));
@ -6508,7 +6508,7 @@ void setcursor(void)
// With 'rightleft' set and the cursor on a double-wide character, // With 'rightleft' set and the cursor on a double-wide character,
// position it on the leftmost column. // position it on the leftmost column.
col = curwin->w_width_inner - curwin->w_wcol col = curwin->w_width_inner - curwin->w_wcol
- ((utf_ptr2cells(get_cursor_pos_ptr()) == 2 - ((utf_ptr2cells((char *)get_cursor_pos_ptr()) == 2
&& vim_isprintc(gchar_cursor())) ? 2 : 1); && vim_isprintc(gchar_cursor())) ? 2 : 1);
} }
@ -7373,8 +7373,8 @@ static void win_redr_ruler(win_T *wp, bool always)
} }
// Truncate at window boundary. // Truncate at window boundary.
o = 0; o = 0;
for (i = 0; buffer[i] != NUL; i += utfc_ptr2len(buffer + i)) { for (i = 0; buffer[i] != NUL; i += utfc_ptr2len((char *)buffer + i)) {
o += utf_ptr2cells(buffer + i); o += utf_ptr2cells((char *)buffer + i);
if (this_ru_col + o > width) { if (this_ru_col + o > width) {
buffer[i] = NUL; buffer[i] = NUL;
break; break;

View File

@ -219,7 +219,7 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET
char_u *rev = xmalloc(len + 1); char_u *rev = xmalloc(len + 1);
size_t rev_i = len; size_t rev_i = len;
for (size_t s_i = 0; s_i < len; s_i++) { for (size_t s_i = 0; s_i < len; s_i++) {
const int mb_len = utfc_ptr2len(s + s_i); const int mb_len = utfc_ptr2len((char *)s + s_i);
rev_i -= mb_len; rev_i -= mb_len;
memmove(rev + rev_i, s + s_i, mb_len); memmove(rev + rev_i, s + s_i, mb_len);
s_i += mb_len - 1; s_i += mb_len - 1;
@ -388,10 +388,10 @@ bool pat_has_uppercase(char_u *pat)
char_u *p = pat; char_u *p = pat;
while (*p != NUL) { while (*p != NUL) {
const int l = utfc_ptr2len(p); const int l = utfc_ptr2len((char *)p);
if (l > 1) { if (l > 1) {
if (mb_isupper(utf_ptr2char(p))) { if (mb_isupper(utf_ptr2char((char *)p))) {
return true; return true;
} }
p += l; p += l;
@ -602,7 +602,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
if ((int)STRLEN(ptr) <= pos->col) { if ((int)STRLEN(ptr) <= pos->col) {
start_char_len = 1; start_char_len = 1;
} else { } else {
start_char_len = utfc_ptr2len(ptr + pos->col); start_char_len = utfc_ptr2len((char *)ptr + pos->col);
} }
} else { } else {
start_char_len = 1; start_char_len = 1;
@ -714,7 +714,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
} }
if (matchcol == matchpos.col && ptr[matchcol] != NUL) { if (matchcol == matchpos.col && ptr[matchcol] != NUL) {
matchcol += utfc_ptr2len(ptr + matchcol); matchcol += utfc_ptr2len((char *)ptr + matchcol);
} }
if (matchcol == 0 && (options & SEARCH_START)) { if (matchcol == 0 && (options & SEARCH_START)) {
@ -799,7 +799,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
// for empty match: advance one char // for empty match: advance one char
if (matchcol == matchpos.col if (matchcol == matchpos.col
&& ptr[matchcol] != NUL) { && ptr[matchcol] != NUL) {
matchcol += utfc_ptr2len(ptr + matchcol); matchcol += utfc_ptr2len((char *)ptr + matchcol);
} }
} else { } else {
// Stop when the match is in a next line. // Stop when the match is in a next line.
@ -808,7 +808,7 @@ int searchit(win_T *win, buf_T *buf, pos_T *pos, pos_T *end_pos, Direction dir,
} }
matchcol = matchpos.col; matchcol = matchpos.col;
if (ptr[matchcol] != NUL) { if (ptr[matchcol] != NUL) {
matchcol += utfc_ptr2len(ptr + matchcol); matchcol += utfc_ptr2len((char *)ptr + matchcol);
} }
} }
if (ptr[matchcol] == NUL if (ptr[matchcol] == NUL
@ -1248,7 +1248,7 @@ int do_search(oparg_T *oap, int dirc, int search_delim, char_u *pat, long count,
// empty for the search_stat feature. // empty for the search_stat feature.
if (!cmd_silent) { if (!cmd_silent) {
msgbuf[0] = dirc; msgbuf[0] = dirc;
if (utf_iscomposing(utf_ptr2char(p))) { if (utf_iscomposing(utf_ptr2char((char *)p))) {
// Use a space to draw the composing char on. // Use a space to draw the composing char on.
msgbuf[1] = ' '; msgbuf[1] = ' ';
memmove(msgbuf + 2, p, STRLEN(p)); memmove(msgbuf + 2, p, STRLEN(p));
@ -1593,7 +1593,7 @@ int searchc(cmdarg_T *cap, int t_cmd)
while (count--) { while (count--) {
for (;;) { for (;;) {
if (dir > 0) { if (dir > 0) {
col += utfc_ptr2len(p + col); col += utfc_ptr2len((char *)p + col);
if (col >= len) { if (col >= len) {
return FAIL; return FAIL;
} }
@ -1709,31 +1709,31 @@ static void find_mps_values(int *initc, int *findc, bool *backwards, bool switch
char_u *ptr = curbuf->b_p_mps; char_u *ptr = curbuf->b_p_mps;
while (*ptr != NUL) { while (*ptr != NUL) {
if (utf_ptr2char(ptr) == *initc) { if (utf_ptr2char((char *)ptr) == *initc) {
if (switchit) { if (switchit) {
*findc = *initc; *findc = *initc;
*initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); *initc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1);
*backwards = true; *backwards = true;
} else { } else {
*findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); *findc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1);
*backwards = false; *backwards = false;
} }
return; return;
} }
char_u *prev = ptr; char_u *prev = ptr;
ptr += utfc_ptr2len(ptr) + 1; ptr += utfc_ptr2len((char *)ptr) + 1;
if (utf_ptr2char(ptr) == *initc) { if (utf_ptr2char((char *)ptr) == *initc) {
if (switchit) { if (switchit) {
*findc = *initc; *findc = *initc;
*initc = utf_ptr2char(prev); *initc = utf_ptr2char((char *)prev);
*backwards = false; *backwards = false;
} else { } else {
*findc = utf_ptr2char(prev); *findc = utf_ptr2char((char *)prev);
*backwards = true; *backwards = true;
} }
return; return;
} }
ptr += utfc_ptr2len(ptr); ptr += utfc_ptr2len((char *)ptr);
if (*ptr == ',') { if (*ptr == ',') {
ptr++; ptr++;
} }
@ -1880,7 +1880,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
--pos.col; --pos.col;
} }
for (;;) { for (;;) {
initc = utf_ptr2char(linep + pos.col); initc = utf_ptr2char((char *)linep + pos.col);
if (initc == NUL) { if (initc == NUL) {
break; break;
} }
@ -1889,7 +1889,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
if (findc) { if (findc) {
break; break;
} }
pos.col += utfc_ptr2len(linep + pos.col); pos.col += utfc_ptr2len((char *)linep + pos.col);
} }
if (!findc) { if (!findc) {
// no brace in the line, maybe use " #if" then // no brace in the line, maybe use " #if" then
@ -2061,7 +2061,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
comment_col = check_linecomment(linep); comment_col = check_linecomment(linep);
} }
} else { } else {
pos.col += utfc_ptr2len(linep + pos.col); pos.col += utfc_ptr2len((char *)linep + pos.col);
} }
} }
@ -2206,7 +2206,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel)
* inquote if the number of quotes in a line is even, unless this * inquote if the number of quotes in a line is even, unless this
* line or the previous one ends in a '\'. Complicated, isn't it? * line or the previous one ends in a '\'. Complicated, isn't it?
*/ */
const int c = utf_ptr2char(linep + pos.col); const int c = utf_ptr2char((char *)linep + pos.col);
switch (c) { switch (c) {
case NUL: case NUL:
// at end of line without trailing backslash, reset inquote // at end of line without trailing backslash, reset inquote
@ -2388,14 +2388,14 @@ void showmatch(int c)
*/ */
// 'matchpairs' is "x:y,x:y" // 'matchpairs' is "x:y,x:y"
for (p = curbuf->b_p_mps; *p != NUL; p++) { for (p = curbuf->b_p_mps; *p != NUL; p++) {
if (utf_ptr2char(p) == c && (curwin->w_p_rl ^ p_ri)) { if (utf_ptr2char((char *)p) == c && (curwin->w_p_rl ^ p_ri)) {
break; break;
} }
p += utfc_ptr2len(p) + 1; p += utfc_ptr2len((char *)p) + 1;
if (utf_ptr2char(p) == c && !(curwin->w_p_rl ^ p_ri)) { if (utf_ptr2char((char *)p) == c && !(curwin->w_p_rl ^ p_ri)) {
break; break;
} }
p += utfc_ptr2len(p); p += utfc_ptr2len((char *)p);
if (*p == NUL) { if (*p == NUL) {
return; return;
} }
@ -3972,7 +3972,7 @@ static int find_next_quote(char_u *line, int col, int quotechar, char_u *escape)
} else if (c == quotechar) { } else if (c == quotechar) {
break; break;
} }
col += utfc_ptr2len(line + col); col += utfc_ptr2len((char *)line + col);
} }
return col; return col;
} }
@ -4883,10 +4883,10 @@ static int fuzzy_match_compute_score(const char_u *const str, const int strSz,
int neighbor; int neighbor;
for (uint32_t sidx = 0; sidx < currIdx; sidx++) { for (uint32_t sidx = 0; sidx < currIdx; sidx++) {
neighbor = utf_ptr2char(p); neighbor = utf_ptr2char((char *)p);
MB_PTR_ADV(p); MB_PTR_ADV(p);
} }
const int curr = utf_ptr2char(p); const int curr = utf_ptr2char((char *)p);
if (mb_islower(neighbor) && mb_isupper(curr)) { if (mb_islower(neighbor) && mb_isupper(curr)) {
score += CAMEL_BONUS; score += CAMEL_BONUS;
@ -4934,8 +4934,8 @@ static int fuzzy_match_recursive(const char_u *fuzpat, const char_u *str, uint32
// Loop through fuzpat and str looking for a match // Loop through fuzpat and str looking for a match
bool first_match = true; bool first_match = true;
while (*fuzpat != NUL && *str != NUL) { while (*fuzpat != NUL && *str != NUL) {
const int c1 = utf_ptr2char(fuzpat); const int c1 = utf_ptr2char((char *)fuzpat);
const int c2 = utf_ptr2char(str); const int c2 = utf_ptr2char((char *)str);
// Found match // Found match
if (mb_tolower(c1) == mb_tolower(c2)) { if (mb_tolower(c1) == mb_tolower(c2)) {
@ -4953,7 +4953,7 @@ static int fuzzy_match_recursive(const char_u *fuzpat, const char_u *str, uint32
// Recursive call that "skips" this match // Recursive call that "skips" this match
uint32_t recursiveMatches[MAX_FUZZY_MATCHES]; uint32_t recursiveMatches[MAX_FUZZY_MATCHES];
int recursiveScore = 0; int recursiveScore = 0;
const char_u *const next_char = str + utfc_ptr2len(str); const char_u *const next_char = str + utfc_ptr2len((char *)str);
if (fuzzy_match_recursive(fuzpat, next_char, strIdx + 1, &recursiveScore, strBegin, strLen, if (fuzzy_match_recursive(fuzpat, next_char, strIdx + 1, &recursiveScore, strBegin, strLen,
matches, recursiveMatches, matches, recursiveMatches,
sizeof(recursiveMatches) / sizeof(recursiveMatches[0]), nextMatch, sizeof(recursiveMatches) / sizeof(recursiveMatches[0]), nextMatch,
@ -5034,7 +5034,7 @@ bool fuzzy_match(char_u *const str, const char_u *const pat_arg, const bool matc
break; break;
} }
pat = p; pat = p;
while (*p != NUL && !ascii_iswhite(utf_ptr2char(p))) { while (*p != NUL && !ascii_iswhite(utf_ptr2char((char *)p))) {
MB_PTR_ADV(p); MB_PTR_ADV(p);
} }
if (*p == NUL) { // processed all the words if (*p == NUL) { // processed all the words
@ -5157,7 +5157,7 @@ static void fuzzy_match_in_list(list_T *const l, char_u *const str, const bool m
int j = 0; int j = 0;
const char_u *p = str; const char_u *p = str;
while (*p != NUL) { while (*p != NUL) {
if (!ascii_iswhite(utf_ptr2char(p))) { if (!ascii_iswhite(utf_ptr2char((char *)p))) {
tv_list_append_number(items[match_count].lmatchpos, matches[j]); tv_list_append_number(items[match_count].lmatchpos, matches[j]);
j++; j++;
} }
@ -5839,7 +5839,7 @@ exit_matched:
&& action == ACTION_EXPAND && action == ACTION_EXPAND
&& !(compl_cont_status & CONT_SOL) && !(compl_cont_status & CONT_SOL)
&& *startp != NUL && *startp != NUL
&& *(p = startp + utfc_ptr2len(startp)) != NUL) { && *(p = startp + utfc_ptr2len((char *)startp)) != NUL) {
goto search_line; goto search_line;
} }
} }

View File

@ -884,11 +884,11 @@ static int sign_define_init_text(sign_T *sp, char_u *text)
} }
// Count cells and check for non-printable chars // Count cells and check for non-printable chars
cells = 0; cells = 0;
for (s = text; s < endp; s += utfc_ptr2len(s)) { for (s = text; s < endp; s += utfc_ptr2len((char *)s)) {
if (!vim_isprintc(utf_ptr2char(s))) { if (!vim_isprintc(utf_ptr2char((char *)s))) {
break; break;
} }
cells += utf_ptr2cells(s); cells += utf_ptr2cells((char *)s);
} }
// Currently must be empty, one or two display cells // Currently must be empty, one or two display cells
if (s != endp || cells > 2) { if (s != endp || cells > 2) {

View File

@ -397,7 +397,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
bool this_upper = false; // init for gcc bool this_upper = false; // init for gcc
if (use_camel_case) { if (use_camel_case) {
c = utf_ptr2char(mi.mi_fend); c = utf_ptr2char((char *)mi.mi_fend);
this_upper = SPELL_ISUPPER(c); this_upper = SPELL_ISUPPER(c);
} }
@ -405,7 +405,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
MB_PTR_ADV(mi.mi_fend); MB_PTR_ADV(mi.mi_fend);
if (use_camel_case) { if (use_camel_case) {
const bool prev_upper = this_upper; const bool prev_upper = this_upper;
c = utf_ptr2char(mi.mi_fend); c = utf_ptr2char((char *)mi.mi_fend);
this_upper = SPELL_ISUPPER(c); this_upper = SPELL_ISUPPER(c);
camel_case = !prev_upper && this_upper; camel_case = !prev_upper && this_upper;
} }
@ -414,7 +414,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) { if (capcol != NULL && *capcol == 0 && wp->w_s->b_cap_prog != NULL) {
// Check word starting with capital letter. // Check word starting with capital letter.
c = utf_ptr2char(ptr); c = utf_ptr2char((char *)ptr);
if (!SPELL_ISUPPER(c)) { if (!SPELL_ISUPPER(c)) {
wrongcaplen = (size_t)(mi.mi_fend - ptr); wrongcaplen = (size_t)(mi.mi_fend - ptr);
} }
@ -512,7 +512,7 @@ size_t spell_check(win_T *wp, char_u *ptr, hlf_T *attrp, int *capcol, bool docou
} }
} }
return (size_t)(utfc_ptr2len(ptr)); return (size_t)(utfc_ptr2len((char *)ptr));
} else if (mi.mi_end == ptr) { } else if (mi.mi_end == ptr) {
// Always include at least one character. Required for when there // Always include at least one character. Required for when there
// is a mixup in "midword". // is a mixup in "midword".
@ -2023,8 +2023,8 @@ static int count_syllables(slang_T *slang, const char_u *word)
skip = false; skip = false;
} else { } else {
// No recognized syllable item, at least a syllable char then? // No recognized syllable item, at least a syllable char then?
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
len = utfc_ptr2len(p); len = utfc_ptr2len((char *)p);
if (vim_strchr(slang->sl_syllable, c) == NULL) { if (vim_strchr(slang->sl_syllable, c) == NULL) {
skip = false; // No, search for next syllable skip = false; // No, search for next syllable
} else if (!skip) { } else if (!skip) {
@ -2355,8 +2355,8 @@ static void use_midword(slang_T *lp, win_T *wp)
} }
for (char_u *p = lp->sl_midword; *p != NUL;) { for (char_u *p = lp->sl_midword; *p != NUL;) {
const int c = utf_ptr2char(p); const int c = utf_ptr2char((char *)p);
const int l = utfc_ptr2len(p); const int l = utfc_ptr2len((char *)p);
if (c < 256 && l <= 2) { if (c < 256 && l <= 2) {
wp->w_s->b_spell_ismw[c] = true; wp->w_s->b_spell_ismw[c] = true;
} else if (wp->w_s->b_spell_ismw_mb == NULL) { } else if (wp->w_s->b_spell_ismw_mb == NULL) {
@ -2423,7 +2423,7 @@ int captype(char_u *word, char_u *end)
// But a word with an upper char only at start is a ONECAP. // But a word with an upper char only at start is a ONECAP.
for (; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) { for (; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) {
if (spell_iswordp_nmw(p, curwin)) { if (spell_iswordp_nmw(p, curwin)) {
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
if (!SPELL_ISUPPER(c)) { if (!SPELL_ISUPPER(c)) {
// UUl -> KEEPCAP // UUl -> KEEPCAP
if (past_second && allcap) { if (past_second && allcap) {
@ -2464,7 +2464,7 @@ static int badword_captype(char_u *word, char_u *end)
l = u = 0; l = u = 0;
first = false; first = false;
for (p = word; p < end; MB_PTR_ADV(p)) { for (p = word; p < end; MB_PTR_ADV(p)) {
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
if (SPELL_ISUPPER(c)) { if (SPELL_ISUPPER(c)) {
++u; ++u;
if (p == word) { if (p == word) {
@ -2674,7 +2674,7 @@ static bool spell_iswordp(const char_u *p, const win_T *wp)
{ {
int c; int c;
const int l = utfc_ptr2len(p); const int l = utfc_ptr2len((char *)p);
const char_u *s = p; const char_u *s = p;
if (l == 1) { if (l == 1) {
// be quick for ASCII // be quick for ASCII
@ -2682,7 +2682,7 @@ static bool spell_iswordp(const char_u *p, const win_T *wp)
s = p + 1; // skip a mid-word character s = p + 1; // skip a mid-word character
} }
} else { } else {
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
if (c < 256 if (c < 256
? wp->w_s->b_spell_ismw[c] ? wp->w_s->b_spell_ismw[c]
: (wp->w_s->b_spell_ismw_mb != NULL : (wp->w_s->b_spell_ismw_mb != NULL
@ -2691,7 +2691,7 @@ static bool spell_iswordp(const char_u *p, const win_T *wp)
} }
} }
c = utf_ptr2char(s); c = utf_ptr2char((char *)s);
if (c > 255) { if (c > 255) {
return spell_mb_isword_class(mb_get_class(s), wp); return spell_mb_isword_class(mb_get_class(s), wp);
} }
@ -2702,7 +2702,7 @@ static bool spell_iswordp(const char_u *p, const win_T *wp)
// Unlike spell_iswordp() this doesn't check for "midword" characters. // Unlike spell_iswordp() this doesn't check for "midword" characters.
bool spell_iswordp_nmw(const char_u *p, win_T *wp) bool spell_iswordp_nmw(const char_u *p, win_T *wp)
{ {
int c = utf_ptr2char(p); int c = utf_ptr2char((char *)p);
if (c > 255) { if (c > 255) {
return spell_mb_isword_class(mb_get_class(p), wp); return spell_mb_isword_class(mb_get_class(p), wp);
} }
@ -3314,7 +3314,7 @@ static void spell_find_suggest(char_u *badptr, int badlen, suginfo_T *su, int ma
// If the word is not capitalised and spell_check() doesn't consider the // If the word is not capitalised and spell_check() doesn't consider the
// word to be bad then it might need to be capitalised. Add a suggestion // word to be bad then it might need to be capitalised. Add a suggestion
// for that. // for that.
c = utf_ptr2char(su->su_badptr); c = utf_ptr2char((char *)su->su_badptr);
if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) {
make_case_word(su->su_badword, buf, WF_ONECAP); make_case_word(su->su_badword, buf, WF_ONECAP);
add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE, add_suggestion(su, &su->su_ga, buf, su->su_badlen, SCORE_ICASE,
@ -4009,7 +4009,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
c = su->su_badflags; c = su->su_badflags;
if ((c & WF_ALLCAP) if ((c & WF_ALLCAP)
&& su->su_badlen == && su->su_badlen ==
utfc_ptr2len(su->su_badptr)) { utfc_ptr2len((char *)su->su_badptr)) {
c = WF_ONECAP; c = WF_ONECAP;
} }
c |= flags; c |= flags;
@ -4258,7 +4258,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
&& goodword_ends) { && goodword_ends) {
int l; int l;
l = utfc_ptr2len(fword + sp->ts_fidx); l = utfc_ptr2len((char *)fword + sp->ts_fidx);
if (fword_ends) { if (fword_ends) {
// Copy the skipped character to preword. // Copy the skipped character to preword.
memmove(preword + sp->ts_prewordlen, memmove(preword + sp->ts_prewordlen,
@ -4405,22 +4405,22 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Correct ts_fidx for the byte length of the // Correct ts_fidx for the byte length of the
// character (we didn't check that before). // character (we didn't check that before).
sp->ts_fidx = sp->ts_fcharstart sp->ts_fidx = sp->ts_fcharstart
+ utfc_ptr2len(fword + sp->ts_fcharstart); + utfc_ptr2len((char *)fword + sp->ts_fcharstart);
// For changing a composing character adjust // For changing a composing character adjust
// the score from SCORE_SUBST to // the score from SCORE_SUBST to
// SCORE_SUBCOMP. // SCORE_SUBCOMP.
if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen if (utf_iscomposing(utf_ptr2char((char *)tword + sp->ts_twordlen
- sp->ts_tcharlen)) - sp->ts_tcharlen))
&& utf_iscomposing(utf_ptr2char(fword && utf_iscomposing(utf_ptr2char((char *)fword
+ sp->ts_fcharstart))) { + sp->ts_fcharstart))) {
sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP;
} else if ( } else if (!soundfold
!soundfold
&& slang->sl_has_map && slang->sl_has_map
&& similar_chars(slang, && similar_chars(slang,
utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), utf_ptr2char((char *)tword + sp->ts_twordlen -
utf_ptr2char(fword + sp->ts_fcharstart))) { sp->ts_tcharlen),
utf_ptr2char((char *)fword + sp->ts_fcharstart))) {
// For a similar character adjust score from // For a similar character adjust score from
// SCORE_SUBST to SCORE_SIMILAR. // SCORE_SUBST to SCORE_SIMILAR.
sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR; sp->ts_score -= SCORE_SUBST - SCORE_SIMILAR;
@ -4428,7 +4428,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
} else if (sp->ts_isdiff == DIFF_INSERT } else if (sp->ts_isdiff == DIFF_INSERT
&& sp->ts_twordlen > sp->ts_tcharlen) { && sp->ts_twordlen > sp->ts_tcharlen) {
p = tword + sp->ts_twordlen - sp->ts_tcharlen; p = tword + sp->ts_twordlen - sp->ts_tcharlen;
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
if (utf_iscomposing(c)) { if (utf_iscomposing(c)) {
// Inserting a composing char doesn't // Inserting a composing char doesn't
// count that much. // count that much.
@ -4440,7 +4440,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// tree (might seem illogical but does // tree (might seem illogical but does
// give better scores). // give better scores).
MB_PTR_BACK(tword, p); MB_PTR_BACK(tword, p);
if (c == utf_ptr2char(p)) { if (c == utf_ptr2char((char *)p)) {
sp->ts_score -= SCORE_INS - SCORE_INSDUP; sp->ts_score -= SCORE_INS - SCORE_INSDUP;
} }
} }
@ -4491,11 +4491,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// score if the same character is following "nn" -> "n". It's // score if the same character is following "nn" -> "n". It's
// a bit illogical for soundfold tree but it does give better // a bit illogical for soundfold tree but it does give better
// results. // results.
c = utf_ptr2char(fword + sp->ts_fidx); c = utf_ptr2char((char *)fword + sp->ts_fidx);
stack[depth].ts_fidx += utfc_ptr2len(fword + sp->ts_fidx); stack[depth].ts_fidx += utfc_ptr2len((char *)fword + sp->ts_fidx);
if (utf_iscomposing(c)) { if (utf_iscomposing(c)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP;
} else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { } else if (c == utf_ptr2char((char *)fword + stack[depth].ts_fidx)) {
stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP;
} }
@ -4610,14 +4610,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
break; break;
} }
n = utf_ptr2len(p); n = utf_ptr2len((char *)p);
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
if (p[n] == NUL) { if (p[n] == NUL) {
c2 = NUL; c2 = NUL;
} else if (!soundfold && !spell_iswordp(p + n, curwin)) { } else if (!soundfold && !spell_iswordp(p + n, curwin)) {
c2 = c; // don't swap non-word char c2 = c; // don't swap non-word char
} else { } else {
c2 = utf_ptr2char(p + n); c2 = utf_ptr2char((char *)p + n);
} }
// When the second character is NUL we can't swap. // When the second character is NUL we can't swap.
@ -4659,9 +4659,9 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNSWAP: case STATE_UNSWAP:
// Undo the STATE_SWAP swap: "21" -> "12". // Undo the STATE_SWAP swap: "21" -> "12".
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utfc_ptr2len(p); n = utfc_ptr2len((char *)p);
c = utf_ptr2char(p + n); c = utf_ptr2char((char *)p + n);
memmove(p + utfc_ptr2len(p + n), p, n); memmove(p + utfc_ptr2len((char *)p + n), p, n);
utf_char2bytes(c, p); utf_char2bytes(c, p);
FALLTHROUGH; FALLTHROUGH;
@ -4670,14 +4670,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
// Swap two bytes, skipping one: "123" -> "321". We change // Swap two bytes, skipping one: "123" -> "321". We change
// "fword" here, it's changed back afterwards at STATE_UNSWAP3. // "fword" here, it's changed back afterwards at STATE_UNSWAP3.
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utf_ptr2len(p); n = utf_ptr2len((char *)p);
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
fl = utf_ptr2len(p + n); fl = utf_ptr2len((char *)p + n);
c2 = utf_ptr2char(p + n); c2 = utf_ptr2char((char *)p + n);
if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { if (!soundfold && !spell_iswordp(p + n + fl, curwin)) {
c3 = c; // don't swap non-word char c3 = c; // don't swap non-word char
} else { } else {
c3 = utf_ptr2char(p + n + fl); c3 = utf_ptr2char((char *)p + n + fl);
} }
// When characters are identical: "121" then SWAP3 result is // When characters are identical: "121" then SWAP3 result is
@ -4715,11 +4715,11 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNSWAP3: case STATE_UNSWAP3:
// Undo STATE_SWAP3: "321" -> "123" // Undo STATE_SWAP3: "321" -> "123"
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utfc_ptr2len(p); n = utfc_ptr2len((char *)p);
c2 = utf_ptr2char(p + n); c2 = utf_ptr2char((char *)p + n);
fl = utfc_ptr2len(p + n); fl = utfc_ptr2len((char *)p + n);
c = utf_ptr2char(p + n + fl); c = utf_ptr2char((char *)p + n + fl);
tl = utfc_ptr2len(p + n + fl); tl = utfc_ptr2len((char *)p + n + fl);
memmove(p + fl + tl, p, n); memmove(p + fl + tl, p, n);
utf_char2bytes(c, p); utf_char2bytes(c, p);
utf_char2bytes(c2, p + tl); utf_char2bytes(c2, p + tl);
@ -4747,10 +4747,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3L; sp->ts_state = STATE_UNROT3L;
++depth; ++depth;
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utf_ptr2len(p); n = utf_ptr2len((char *)p);
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
fl = utf_ptr2len(p + n); fl = utf_ptr2len((char *)p + n);
fl += utf_ptr2len(p + n + fl); fl += utf_ptr2len((char *)p + n + fl);
memmove(p, p + n, fl); memmove(p, p + n, fl);
utf_char2bytes(c, p + fl); utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
@ -4763,10 +4763,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNROT3L: case STATE_UNROT3L:
// Undo ROT3L: "231" -> "123" // Undo ROT3L: "231" -> "123"
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utfc_ptr2len(p); n = utfc_ptr2len((char *)p);
n += utfc_ptr2len(p + n); n += utfc_ptr2len((char *)p + n);
c = utf_ptr2char(p + n); c = utf_ptr2char((char *)p + n);
tl = utfc_ptr2len(p + n); tl = utfc_ptr2len((char *)p + n);
memmove(p + tl, p, n); memmove(p + tl, p, n);
utf_char2bytes(c, p); utf_char2bytes(c, p);
@ -4784,10 +4784,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
sp->ts_state = STATE_UNROT3R; sp->ts_state = STATE_UNROT3R;
++depth; ++depth;
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
n = utf_ptr2len(p); n = utf_ptr2len((char *)p);
n += utf_ptr2len(p + n); n += utf_ptr2len((char *)p + n);
c = utf_ptr2char(p + n); c = utf_ptr2char((char *)p + n);
tl = utf_ptr2len(p + n); tl = utf_ptr2len((char *)p + n);
memmove(p + tl, p, n); memmove(p + tl, p, n);
utf_char2bytes(c, p); utf_char2bytes(c, p);
stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; stack[depth].ts_fidxtry = sp->ts_fidx + n + tl;
@ -4800,10 +4800,10 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
case STATE_UNROT3R: case STATE_UNROT3R:
// Undo ROT3R: "312" -> "123" // Undo ROT3R: "312" -> "123"
p = fword + sp->ts_fidx; p = fword + sp->ts_fidx;
c = utf_ptr2char(p); c = utf_ptr2char((char *)p);
tl = utfc_ptr2len(p); tl = utfc_ptr2len((char *)p);
n = utfc_ptr2len(p + tl); n = utfc_ptr2len((char *)p + tl);
n += utfc_ptr2len(p + tl + n); n += utfc_ptr2len((char *)p + tl + n);
memmove(p, p + tl, n); memmove(p, p + tl, n);
utf_char2bytes(c, p + n); utf_char2bytes(c, p + n);
@ -5025,8 +5025,8 @@ static void find_keepcap_word(slang_T *slang, char_u *fword, char_u *kword)
} else { } else {
// round[depth] == 1: Try using the folded-case character. // round[depth] == 1: Try using the folded-case character.
// round[depth] == 2: Try using the upper-case character. // round[depth] == 2: Try using the upper-case character.
flen = utf_ptr2len(fword + fwordidx[depth]); flen = utf_ptr2len((char *)fword + fwordidx[depth]);
ulen = utf_ptr2len(uword + uwordidx[depth]); ulen = utf_ptr2len((char *)uword + uwordidx[depth]);
if (round[depth] == 1) { if (round[depth] == 1) {
p = fword + fwordidx[depth]; p = fword + fwordidx[depth];
l = flen; l = flen;
@ -5516,9 +5516,9 @@ badword:
// lower to upper case. Helps for "tath" -> "Kath", which is // lower to upper case. Helps for "tath" -> "Kath", which is
// less common than "tath" -> "path". Don't do it when the // less common than "tath" -> "path". Don't do it when the
// letter is the same, that has already been counted. // letter is the same, that has already been counted.
gc = utf_ptr2char(p); gc = utf_ptr2char((char *)p);
if (SPELL_ISUPPER(gc)) { if (SPELL_ISUPPER(gc)) {
bc = utf_ptr2char(su->su_badword); bc = utf_ptr2char((char *)su->su_badword);
if (!SPELL_ISUPPER(bc) if (!SPELL_ISUPPER(bc)
&& SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) { && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) {
goodscore += SCORE_ICASE / 2; goodscore += SCORE_ICASE / 2;
@ -5661,7 +5661,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
if (HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
m1 = 0; m1 = 0;
} else { } else {
m1 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); m1 = utf_ptr2char((char *)hi->hi_key + STRLEN(hi->hi_key) + 1);
} }
} else { } else {
m1 = slang->sl_map_array[c1]; m1 = slang->sl_map_array[c1];
@ -5676,7 +5676,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2)
if (HASHITEM_EMPTY(hi)) { if (HASHITEM_EMPTY(hi)) {
m2 = 0; m2 = 0;
} else { } else {
m2 = utf_ptr2char(hi->hi_key + STRLEN(hi->hi_key) + 1); m2 = utf_ptr2char((char *)hi->hi_key + STRLEN(hi->hi_key) + 1);
} }
} else { } else {
m2 = slang->sl_map_array[c2]; m2 = slang->sl_map_array[c2];
@ -5713,7 +5713,7 @@ static void add_suggestion(suginfo_T *su, garray_T *gap, const char_u *goodword,
} }
MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(goodword, pgood);
MB_PTR_BACK(su->su_badptr, pbad); MB_PTR_BACK(su->su_badptr, pbad);
if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { if (utf_ptr2char((char *)pgood) != utf_ptr2char((char *)pbad)) {
break; break;
} }
} }
@ -6940,7 +6940,7 @@ void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg)
if (n == WF_ONECAP) { if (n == WF_ONECAP) {
dumpflags |= DUMPFLAG_ONECAP; dumpflags |= DUMPFLAG_ONECAP;
} else if (n == WF_ALLCAP } else if (n == WF_ALLCAP
&& (int)STRLEN(pat) > utfc_ptr2len(pat)) { && (int)STRLEN(pat) > utfc_ptr2len((char *)pat)) {
dumpflags |= DUMPFLAG_ALLCAP; dumpflags |= DUMPFLAG_ALLCAP;
} }
} }
@ -7189,7 +7189,7 @@ static linenr_T dump_prefixes(slang_T *slang, char_u *word, char_u *pat, Directi
// If the word starts with a lower-case letter make the word with an // If the word starts with a lower-case letter make the word with an
// upper-case letter in word_up[]. // upper-case letter in word_up[].
c = utf_ptr2char(word); c = utf_ptr2char((char *)word);
if (SPELL_TOUPPER(c) != c) { if (SPELL_TOUPPER(c) != c) {
onecap_copy(word, word_up, true); onecap_copy(word, word_up, true);
has_word_up = true; has_word_up = true;

View File

@ -2504,19 +2504,19 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname)
// be empty or start with the same letter. // be empty or start with the same letter.
if (aff_entry->ae_chop != NULL if (aff_entry->ae_chop != NULL
&& aff_entry->ae_add != NULL && aff_entry->ae_add != NULL
&& aff_entry->ae_chop[utfc_ptr2len(aff_entry->ae_chop)] == && aff_entry->ae_chop[utfc_ptr2len((char *)aff_entry->ae_chop)] ==
NUL) { NUL) {
int c, c_up; int c, c_up;
c = utf_ptr2char(aff_entry->ae_chop); c = utf_ptr2char((char *)aff_entry->ae_chop);
c_up = SPELL_TOUPPER(c); c_up = SPELL_TOUPPER(c);
if (c_up != c if (c_up != c
&& (aff_entry->ae_cond == NULL && (aff_entry->ae_cond == NULL
|| utf_ptr2char(aff_entry->ae_cond) == c)) { || utf_ptr2char((char *)aff_entry->ae_cond) == c)) {
p = aff_entry->ae_add p = aff_entry->ae_add
+ STRLEN(aff_entry->ae_add); + STRLEN(aff_entry->ae_add);
MB_PTR_BACK(aff_entry->ae_add, p); MB_PTR_BACK(aff_entry->ae_add, p);
if (utf_ptr2char(p) == c_up) { if (utf_ptr2char((char *)p) == c_up) {
upper = true; upper = true;
aff_entry->ae_chop = NULL; aff_entry->ae_chop = NULL;
*p = NUL; *p = NUL;

View File

@ -98,7 +98,7 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, c
*/ */
size_t length = 1; // count the trailing NUL size_t length = 1; // count the trailing NUL
for (const char_u *p = string; *p; p++) { for (const char_u *p = string; *p; p++) {
const size_t l = (size_t)(utfc_ptr2len(p)); const size_t l = (size_t)(utfc_ptr2len((char *)p));
if (l > 1) { if (l > 1) {
length += l; // count a multibyte char length += l; // count a multibyte char
p += l - 1; p += l - 1;
@ -113,7 +113,7 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars, c
char_u *escaped_string = xmalloc(length); char_u *escaped_string = xmalloc(length);
char_u *p2 = escaped_string; char_u *p2 = escaped_string;
for (const char_u *p = string; *p; p++) { for (const char_u *p = string; *p; p++) {
const size_t l = (size_t)(utfc_ptr2len(p)); const size_t l = (size_t)(utfc_ptr2len((char *)p));
if (l > 1) { if (l > 1) {
memcpy(p2, p, l); memcpy(p2, p, l);
p2 += l; p2 += l;
@ -357,8 +357,8 @@ char *strcase_save(const char *const orig, bool upper)
char *p = res; char *p = res;
while (*p != NUL) { while (*p != NUL) {
int c = utf_ptr2char((const char_u *)p); int c = utf_ptr2char(p);
int l = utf_ptr2len((const char_u *)p); int l = utf_ptr2len(p);
if (c == 0) { if (c == 0) {
// overlong sequence, use only the first byte // overlong sequence, use only the first byte
c = (char_u)(*p); c = (char_u)(*p);
@ -1011,8 +1011,8 @@ int vim_vsnprintf_typval(char *str, size_t str_m, const char *fmt, va_list ap, t
char_u *p1; char_u *p1;
size_t i; size_t i;
for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len(p1)) { for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len((char *)p1)) {
size_t cell = (size_t)utf_ptr2cells(p1); size_t cell = (size_t)utf_ptr2cells((char *)p1);
if (precision_specified && i + cell > precision) { if (precision_specified && i + cell > precision) {
break; break;
} }

View File

@ -2968,7 +2968,7 @@ static int check_keyword_id(char_u *const line, const int startcol, int *const e
char_u *const kwp = line + startcol; char_u *const kwp = line + startcol;
int kwlen = 0; int kwlen = 0;
do { do {
kwlen += utfc_ptr2len(kwp + kwlen); kwlen += utfc_ptr2len((char *)kwp + kwlen);
} while (vim_iswordp_buf(kwp + kwlen, syn_buf)); } while (vim_iswordp_buf(kwp + kwlen, syn_buf));
if (kwlen > MAXKEYWLEN) { if (kwlen > MAXKEYWLEN) {
@ -4178,8 +4178,8 @@ static char_u *get_syn_options(char_u *arg, syn_opt_arg_T *opt, int *conceal_cha
} }
} else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') {
// cchar=? // cchar=?
*conceal_char = utf_ptr2char(arg + 6); *conceal_char = utf_ptr2char((char *)arg + 6);
arg += utfc_ptr2len(arg + 6) - 1; arg += utfc_ptr2len((char *)arg + 6) - 1;
if (!vim_isprintc_strict(*conceal_char)) { if (!vim_isprintc_strict(*conceal_char)) {
emsg(_("E844: invalid cchar value")); emsg(_("E844: invalid cchar value"));
return NULL; return NULL;
@ -4416,7 +4416,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing)
kw = p + 1; kw = p + 1;
break; // skip over the "]" break; // skip over the "]"
} }
const int l = utfc_ptr2len(p + 1); const int l = utfc_ptr2len((char *)p + 1);
memmove(p, p + 1, l); memmove(p, p + 1, l);
p += l; p += l;

View File

@ -2583,7 +2583,7 @@ static int parse_match(char_u *lbuf, tagptrs_T *tagp)
if (*p++ == TAB) { if (*p++ == TAB) {
// Accept ASCII alphabetic kind characters and any multi-byte // Accept ASCII alphabetic kind characters and any multi-byte
// character. // character.
while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) { while (ASCII_ISALPHA(*p) || utfc_ptr2len((char *)p) > 1) {
if (STRNCMP(p, "kind:", 5) == 0) { if (STRNCMP(p, "kind:", 5) == 0) {
tagp->tagkind = p + 5; tagp->tagkind = p + 5;
} else if (STRNCMP(p, "user_data:", 10) == 0) { } else if (STRNCMP(p, "user_data:", 10) == 0) {

View File

@ -673,8 +673,8 @@ void terminal_paste(long count, char_u **y_array, size_t y_size)
char_u *dst = buff; char_u *dst = buff;
char_u *src = y_array[j]; char_u *src = y_array[j];
while (*src != '\0') { while (*src != '\0') {
len = (size_t)utf_ptr2len(src); len = (size_t)utf_ptr2len((char *)src);
int c = utf_ptr2char(src); int c = utf_ptr2char((char *)src);
if (!is_filter_char(c)) { if (!is_filter_char(c)) {
memcpy(dst, src, len); memcpy(dst, src, len);
dst += len; dst += len;

View File

@ -90,7 +90,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str)
const char_u *s = p; const char_u *s = p;
const int c = mb_ptr2char_adv(&s); const int c = mb_ptr2char_adv(&s);
const int clen = (int)(s - p); const int clen = (int)(s - p);
while (*s != NUL && c == utf_ptr2char(s)) { while (*s != NUL && c == utf_ptr2char((char *)s)) {
same_len++; same_len++;
s += clen; s += clen;
} }

View File

@ -2312,7 +2312,7 @@ static void do_intro_line(long row, char_u *mesg, int attr)
p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>')); p[l] != NUL && (l == 0 || (p[l] != '<' && p[l - 1] != '>'));
l++) { l++) {
clen += ptr2cells(p + l); clen += ptr2cells(p + l);
l += utfc_ptr2len(p + l) - 1; l += utfc_ptr2len((char *)p + l) - 1;
} }
assert(row <= INT_MAX && col <= INT_MAX); assert(row <= INT_MAX && col <= INT_MAX);
grid_puts_len(&default_grid, p, l, (int)row, (int)col, grid_puts_len(&default_grid, p, l, (int)row, (int)col,

View File

@ -6534,7 +6534,7 @@ char_u *file_name_in_line(char_u *line, int col, int options, long count, char_u
// Skip over the "\" in "\ ". // Skip over the "\" in "\ ".
++len; ++len;
} }
len += (size_t)(utfc_ptr2len(ptr + len)); len += (size_t)(utfc_ptr2len((char *)ptr + len));
} }
/* /*