diff options
author | bfredl <bjorn.linse@gmail.com> | 2022-05-07 16:40:00 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-05-07 16:40:00 +0200 |
commit | 03471e292d48283379a397dadf902572de91b359 (patch) | |
tree | e0736597ec1b49250a128a58ae0f7e7e217c3f2f | |
parent | eccb9896894f0e092b8d3c2519eb81b2a3fb3cca (diff) | |
parent | 2a378e6e82cececb12339f2df51ffe107039d867 (diff) | |
download | rneovim-03471e292d48283379a397dadf902572de91b359.tar.gz rneovim-03471e292d48283379a397dadf902572de91b359.tar.bz2 rneovim-03471e292d48283379a397dadf902572de91b359.zip |
Merge pull request #18425 from dundargoc/refactor/char_u/1
refactor: replace char_u variables and functions with char
51 files changed, 508 insertions, 506 deletions
diff --git a/src/nvim/api/extmark.c b/src/nvim/api/extmark.c index 1f47ac4ebb..e05d80812d 100644 --- a/src/nvim/api/extmark.c +++ b/src/nvim/api/extmark.c @@ -586,7 +586,7 @@ Integer nvim_buf_set_extmark(Buffer buffer, Integer ns_id, Integer line, Integer String c = opts->conceal.data.string; decor.conceal = true; if (c.size) { - decor.conceal_char = utf_ptr2char((const char_u *)c.data); + decor.conceal_char = utf_ptr2char(c.data); } has_decor = true; } else if (HAS_KEY(opts->conceal)) { diff --git a/src/nvim/api/private/helpers.c b/src/nvim/api/private/helpers.c index 9f894d5533..a2ee4f91bc 100644 --- a/src/nvim/api/private/helpers.c +++ b/src/nvim/api/private/helpers.c @@ -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() char *p = (mode.size) ? mode.data : "m"; 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 { - mode_val = get_map_mode((char_u **)&p, false); + mode_val = get_map_mode(&p, false); if ((mode_val == VISUAL + SELECTMODE + NORMAL + OP_PENDING) && mode.size > 0) { // 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 // 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); // 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 int cells = 0; - for (s = text; s < endp; s += utfc_ptr2len((char_u *)s)) { - if (!vim_isprintc(utf_ptr2char((char_u *)s))) { + for (s = text; s < endp; s += utfc_ptr2len(s)) { + if (!vim_isprintc(utf_ptr2char(s))) { break; } - cells += utf_ptr2cells((char_u *)s); + cells += utf_ptr2cells(s); } // Currently must be empty, one or two display cells if (s != endp || cells > 2) { diff --git a/src/nvim/api/ui.c b/src/nvim/api/ui.c index d1b86ed328..b4d20ed975 100644 --- a/src/nvim/api/ui.c +++ b/src/nvim/api/ui.c @@ -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_highlight_set(ui, attrs[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 } } diff --git a/src/nvim/api/vim.c b/src/nvim/api/vim.c index 7f4fafa71b..185c043b06 100644 --- a/src/nvim/api/vim.c +++ b/src/nvim/api/vim.c @@ -2287,12 +2287,12 @@ Dictionary nvim_eval_statusline(String str, Dict(eval_statusline) *opts, Error * if (HAS_KEY(opts->fillchar)) { 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)) { api_set_error(err, kErrorTypeValidation, "fillchar must be a single character"); 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)) { diff --git a/src/nvim/buffer.c b/src/nvim/buffer.c index 9759bdb46e..9839f499eb 100644 --- a/src/nvim/buffer.c +++ b/src/nvim/buffer.c @@ -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; byteval = 0; } else { - byteval = utf_ptr2char(line_ptr + wp->w_cursor.col); + byteval = utf_ptr2char((char *)line_ptr + wp->w_cursor.col); } 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; while (group_len >= stl_items[stl_groupitems[groupdepth]].maxwid) { 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) { while (l >= maxwid) { l -= ptr2cells(t); - t += utfc_ptr2len(t); + t += utfc_ptr2len((char *)t); } // 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 // 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 @@ -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; while (width >= maxwidth) { width -= ptr2cells(trunc_p + trunc_len); - trunc_len += utfc_ptr2len(trunc_p + trunc_len); + trunc_len += utfc_ptr2len((char *)trunc_p + trunc_len); } // } diff --git a/src/nvim/change.c b/src/nvim/change.c index df7a7a00a9..bbb10d3a52 100644 --- a/src/nvim/change.c +++ b/src/nvim/change.c @@ -599,7 +599,7 @@ void ins_char_bytes(char_u *buf, size_t charlen) if (vcol > new_vcol && oldp[col + oldlen] == TAB) { 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. if (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; } else if (oldp[col] != NUL) { // 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) && msg_silent == 0 && !ins_compl_active()) { - showmatch(utf_ptr2char(buf)); + showmatch(utf_ptr2char((char *)buf)); } if (!p_ri || (State & REPLACE_FLAG)) { @@ -715,7 +715,7 @@ int del_chars(long count, int fixpos) int bytes = 0; char_u *p = get_cursor_pos_ptr(); for (long i = 0; i < count && *p != NUL; i++) { - int l = utfc_ptr2len(p); + int l = utfc_ptr2len((char *)p); bytes += 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 // delete the last combining character. if (p_deco && use_delcombine - && utfc_ptr2len(oldp + col) >= count) { + && utfc_ptr2len((char *)oldp + col) >= count) { int cc[MAX_MCO]; (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; do { col = n; - count = utf_ptr2len(oldp + n); + count = utf_ptr2len((char *)oldp + n); n += count; } while (utf_composinglike(oldp + col, oldp + n)); fixpos = false; @@ -1436,7 +1436,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) int 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) { break; } @@ -1459,7 +1459,7 @@ int open_line(int dir, int flags, int second_line_indent, bool *did_do_comment) lead_len--; memmove(p, p + 1, (size_t)(leader + lead_len - p)); } else { - int l = utfc_ptr2len(p); + int l = utfc_ptr2len((char *)p); if (l > 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)) { 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)) { replace_push(*p_extra); } diff --git a/src/nvim/charset.c b/src/nvim/charset.c index 31c61a1398..6012c2ebc6 100644 --- a/src/nvim/charset.c +++ b/src/nvim/charset.c @@ -275,7 +275,7 @@ void trans_characters(char_u *buf, int bufsize) while (*buf != 0) { int trs_len; // length of trs[] // 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; } else { trs = transchar_byte(*buf); @@ -311,7 +311,7 @@ size_t transstr_len(const char *const s, bool untab) size_t len = 0; 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) { int pcc[MAX_MCO + 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; 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 (buf_p + l > buf_e) { 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 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 STR_CHAR(i) (buf == NULL ? GA_CHAR(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. i = 0; while (STR_CHAR(i) != NUL) { - int c = utf_ptr2char(STR_PTR(i)); - int olen = utf_ptr2len(STR_PTR(i)); + int c = utf_ptr2char((char *)STR_PTR(i)); + int olen = utf_ptr2len((char *)STR_PTR(i)); int lc = mb_tolower(c); // 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 - 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. if (*p >= 0x80) { - return utf_ptr2cells(p); + return utf_ptr2cells((char *)p); } // 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); int size = 0; while (*s != NUL && --len >= 0) { - int l = utfc_ptr2len(s); + int l = utfc_ptr2len((char *)s); size += ptr2cells(s); s += l; len -= l - 1; @@ -806,7 +806,7 @@ bool vim_iswordp_buf(const char_u *const p, buf_T *const buf) int c = *p; if (MB_BYTE2LEN(c) > 1) { - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); } 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 // further bytes to find the cell width. if (c >= 0x80) { - incr = utf_ptr2cells(ptr); + incr = utf_ptr2cells((char *)ptr); } else { 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); 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)) { endadd = (colnr_T)(char2cells(c) - 1); if (coladd > endadd) { diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index 87835ec50a..6208efc9c8 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -459,7 +459,7 @@ bool leftcol_changed(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. diff --git a/src/nvim/diff.c b/src/nvim/diff.c index 6b606f50a1..7e296ebf52 100644 --- a/src/nvim/diff.c +++ b/src/nvim/diff.c @@ -750,10 +750,10 @@ static int diff_write_buffer(buf_T *buf, diffin_T *din) c = NUL; } else { // xdiff doesn't support ignoring case, fold-case the text. - c = utf_ptr2char(s); + c = utf_ptr2char((char *)s); 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) { // TODO(Bram): handle byte length difference 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. 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; } if (l > 1) { if (STRNCMP(p1, p2, l) != 0 && (!(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; } *len = l; diff --git a/src/nvim/edit.c b/src/nvim/edit.c index a608612af5..3821cd3f41 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -440,7 +440,7 @@ static void insert_enter(InsertState *s) if (s->ptr[1] == NUL) { curwin->w_cursor.col++; } else { - s->i = utfc_ptr2len(s->ptr); + s->i = utfc_ptr2len((char *)s->ptr); if (s->ptr[s->i] == NUL) { curwin->w_cursor.col += s->i; } @@ -727,7 +727,7 @@ static int insert_execute(VimState *state, int key) if (str != NULL) { for (p = str; *p != NUL; MB_PTR_ADV(p)) { - ins_compl_addleader(utf_ptr2char(p)); + ins_compl_addleader(utf_ptr2char((char *)p)); } xfree(str); } else { @@ -1332,7 +1332,7 @@ normalchar: if (*str != NUL && stop_arrow() != FAIL) { // Insert the new value of v:char literally. 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) { ins_eol(s->c); } 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) { last_vcol = vcol; 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 { new_cursor_col++; } @@ -2061,7 +2061,7 @@ static bool del_char_after_col(int limit_col) // composing character. mb_adjust_cursor(); 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 break; @@ -2566,8 +2566,8 @@ static void ins_compl_longest_match(compl_T *match) p = compl_leader; s = match->cp_str; while (*p != NUL) { - c1 = utf_ptr2char(p); - c2 = utf_ptr2char(s); + c1 = utf_ptr2char((char *)p); + c2 = utf_ptr2char((char *)s); if ((match->cp_flags & CP_ICASE) ? (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 // with single-byte non-word characters. while (*ptr != NUL) { - const int l = utfc_ptr2len(ptr); + const int l = utfc_ptr2len((char *)ptr); if (l < 2 && !vim_iswordc(*ptr)) { break; @@ -3150,7 +3150,7 @@ char_u *find_word_start(char_u *ptr) FUNC_ATTR_PURE { while (*ptr != NUL && *ptr != '\n' && mb_get_class(ptr) <= 1) { - ptr += utfc_ptr2len(ptr); + ptr += utfc_ptr2len((char *)ptr); } return ptr; } @@ -3165,7 +3165,7 @@ char_u *find_word_end(char_u *ptr) const int start_class = mb_get_class(ptr); if (start_class > 1) { while (*ptr != NUL) { - ptr += utfc_ptr2len(ptr); + ptr += utfc_ptr2len((char *)ptr); if (mb_get_class(ptr) != start_class) { break; } @@ -3602,7 +3602,7 @@ static void ins_compl_addfrommatch(void) } } p += len; - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); ins_compl_addleader(c); } @@ -5251,10 +5251,10 @@ static int ins_complete(int c, bool enable_pum) char_u *p = line + startcol; 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); } - if (p == line && vim_isfilec(utf_ptr2char(p))) { + if (p == line && vim_isfilec(utf_ptr2char((char *)p))) { startcol = 0; } else { startcol = (int)(p - line) + 1; @@ -5590,7 +5590,7 @@ static unsigned quote_meta(char_u *dest, char_u *src, int len) *dest++ = *src; } // 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) { for (int i = 0; i < mb_len; i++) { 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 WHITECHAR(cc) ( \ - ascii_iswhite(cc) \ - && !utf_iscomposing(utf_ptr2char(get_cursor_pos_ptr() + 1))) +#define WHITECHAR(cc) (ascii_iswhite(cc) \ + && !utf_iscomposing(utf_ptr2char((char *)get_cursor_pos_ptr() + 1))) /// /// "flags": INSCHAR_FORMAT - force formatting @@ -6903,7 +6902,7 @@ int oneright(void) // Adjust for multi-wide char (excluding TAB) 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)); curwin->w_set_curswant = true; // 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 } - l = utfc_ptr2len(ptr); + l = utfc_ptr2len((char *)ptr); // move "l" bytes right, but don't end up on the NUL, unless 'virtualedit' // contains "onemore". @@ -6957,7 +6956,7 @@ int oneleft(void) // Adjust for multi-wide char (not a TAB) 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) { curwin->w_cursor.coladd = 0; } @@ -7249,7 +7248,7 @@ void replace_push(int c) */ int replace_push_mb(char_u *p) { - int l = utfc_ptr2len(p); + int l = utfc_ptr2len((char *)p); int 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++) { 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); } else { // Not a composing char, put it back. @@ -7403,7 +7402,7 @@ static void replace_do_bs(int limit_col) vcol = start_vcol; for (i = 0; i < ins_len; i++) { vcol += win_chartabsize(curwin, p + i, vcol); - i += utfc_ptr2len(p) - 1; + i += utfc_ptr2len((char *)p) - 1; } vcol -= start_vcol; @@ -8796,7 +8795,7 @@ static void ins_right(void) if (virtual_active()) { oneright(); } else { - curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr()); } revins_legal++; @@ -9305,7 +9304,7 @@ int ins_copychar(linenr_T lnum) ptr = prev_ptr; } - c = utf_ptr2char(ptr); + c = utf_ptr2char((char *)ptr); if (c == NUL) { vim_beep(BO_COPY); } diff --git a/src/nvim/eval.c b/src/nvim/eval.c index 548dd96444..901976bb16 100644 --- a/src/nvim/eval.c +++ b/src/nvim/eval.c @@ -2656,7 +2656,7 @@ bool next_for_item(void *fi_void, char *arg) } 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) { return false; } @@ -7681,7 +7681,7 @@ int buf_byteidx_to_charidx(buf_T *buf, int lnum, int byteidx) char *t = str; int 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, @@ -7714,7 +7714,7 @@ int buf_charidx_to_byteidx(buf_T *buf, int lnum, int charidx) // Convert the character offset to a byte offset char *t = str; while (*t != NUL && --charidx > 0) { - t += utfc_ptr2len((char_u *)t); + t += utfc_ptr2len(t); } 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 ((char_u *)zero_width == regmatch.startp[0]) { // 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); ga.ga_len += i; tail += i; diff --git a/src/nvim/eval/decode.c b/src/nvim/eval/decode.c index ec9a30ad65..93e0a6cfb7 100644 --- a/src/nvim/eval/decode.c +++ b/src/nvim/eval/decode.c @@ -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)); 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 // and thus cannot possibly be equal to *p. But utf_ptr2char({0xFF, // 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; } 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; p += ch_len; } diff --git a/src/nvim/eval/encode.c b/src/nvim/eval/encode.c index 963837fefc..de93ddc70d 100644 --- a/src/nvim/eval/encode.c +++ b/src/nvim/eval/encode.c @@ -611,8 +611,8 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const #define ENCODE_RAW(ch) \ (ch >= 0x20 && utf_printable(ch)) for (size_t i = 0; i < utf_len;) { - const int ch = utf_ptr2char((char_u *)utf_buf + i); - const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len((char_u *)utf_buf + i))); + const int ch = utf_ptr2char(utf_buf + i); + const size_t shift = (ch == 0 ? 1 : ((size_t)utf_ptr2len(utf_buf + i))); assert(shift > 0); i += shift; switch (ch) { @@ -651,11 +651,11 @@ static inline int convert_to_json_string(garray_T *const gap, const char *const ga_append(gap, '"'); ga_grow(gap, (int)str_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))); assert(shift > 0); // 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) { case BS: case TAB: diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c index 92c60e394a..be43c3010a 100644 --- a/src/nvim/eval/funcs.c +++ b/src/nvim/eval/funcs.c @@ -733,9 +733,9 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp) return; } if (comp) { - t += utf_ptr2len((const char_u *)t); + t += utf_ptr2len(t); } else { - t += utfc_ptr2len((const char_u *)t); + t += utfc_ptr2len(t); } } 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'. @@ -925,7 +925,7 @@ static void get_col(typval_T *argvars, typval_T *rettv, bool charcol) if (curwin->w_cursor.coladd >= (colnr_T)win_chartabsize(curwin, p, curwin->w_virtcol - curwin->w_cursor.coladd)) { int l; - if (*p != NUL && p[(l = utfc_ptr2len(p))] == NUL) { + if (*p != NUL && p[(l = utfc_ptr2len((char *)p))] == NUL) { col += l; } } @@ -968,7 +968,7 @@ static void f_charidx(typval_T *argvars, typval_T *rettv, FunPtr fptr) return; } - int (*ptr2len)(const char_u *); + int (*ptr2len)(const char *); if (countcc) { ptr2len = utf_ptr2len; } else { @@ -981,7 +981,7 @@ static void f_charidx(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (*p == NUL) { return; } - p += ptr2len((const char_u *)p); + p += ptr2len(p); } 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; } - mode = get_map_mode((char_u **)&which, 0); + mode = get_map_mode((char **)&which, 0); char_u *keys_simplified = 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++; } else { 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]) { match = false; break; @@ -8062,7 +8062,7 @@ static void f_screenchar(typval_T *argvars, typval_T *rettv, FunPtr fptr) } else { ScreenGrid *grid = &default_grid; 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; } @@ -8660,7 +8660,7 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (csearch != NULL) { int pcc[MAX_MCO]; 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")); @@ -9796,7 +9796,7 @@ static void f_split(typval_T *argvars, typval_T *rettv, FunPtr fptr) col = 0; } else { // 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]; } @@ -9856,8 +9856,8 @@ static void f_str2list(typval_T *argvars, typval_T *rettv, FunPtr fptr) tv_list_alloc_ret(rettv, kListLenUnknown); const char_u *p = (const char_u *)tv_get_string(&argvars[0]); - for (; *p != NUL; p += utf_ptr2len(p)) { - tv_list_append_number(rettv->vval.v_list, utf_ptr2char(p)); + for (; *p != NUL; p += utf_ptr2len((char *)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) { if (charidx == 0) { - rettv->vval.v_number = utf_ptr2char((const char_u *)str + byteidx); + rettv->vval.v_number = utf_ptr2char(str + byteidx); break; } 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 (nchar > 0) { while (nchar > 0 && (size_t)nbyte < slen) { - nbyte += utf_ptr2len((const char_u *)p + nbyte); + nbyte += utf_ptr2len(p + nbyte); nchar--; } } else { @@ -10101,7 +10101,7 @@ static void f_strcharpart(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (off < 0) { len += 1; } else { - len += utf_ptr2len((const char_u *)p + off); + len += utf_ptr2len(p + off); } charlen--; } @@ -10164,7 +10164,7 @@ static void f_strpart(typval_T *argvars, typval_T *rettv, FunPtr fptr) // length in characters for (off = n; off < (int)slen && len > 0; len--) { - off += utfc_ptr2len((char_u *)p + off); + off += utfc_ptr2len(p + off); } len = off - n; } @@ -10935,16 +10935,16 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr) bool first = true; while (*in_str != NUL) { 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 idx = 0; int 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) { int tolen; for (p = tostr; *p != NUL; p += tolen) { - tolen = utfc_ptr2len((const char_u *)p); + tolen = utfc_ptr2len(p); if (idx-- == 0) { cplen = tolen; cpstr = (char *)p; @@ -10966,7 +10966,7 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr) first = false; int tolen; for (const char *p = tostr; *p != NUL; p += tolen) { - tolen = utfc_ptr2len((const char_u *)p); + tolen = utfc_ptr2len(p); idx--; } if (idx != 0) { @@ -11029,14 +11029,14 @@ static void f_trim(typval_T *argvars, typval_T *rettv, FunPtr fptr) if (dir == 0 || dir == 1) { // Trim leading characters while (*head != NUL) { - c1 = utf_ptr2char(head); + c1 = utf_ptr2char((char *)head); if (mask == NULL) { if (c1 > ' ' && c1 != 0xa0) { break; } } else { for (p = mask; *p != NUL; MB_PTR_ADV(p)) { - if (c1 == utf_ptr2char(p)) { + if (c1 == utf_ptr2char((char *)p)) { break; } } @@ -11054,14 +11054,14 @@ static void f_trim(typval_T *argvars, typval_T *rettv, FunPtr fptr) for (; tail > head; tail = prev) { prev = tail; MB_PTR_BACK(head, prev); - c1 = utf_ptr2char(prev); + c1 = utf_ptr2char((char *)prev); if (mask == NULL) { if (c1 > ' ' && c1 != 0xa0) { break; } } else { for (p = mask; *p != NUL; MB_PTR_ADV(p)) { - if (c1 == utf_ptr2char(p)) { + if (c1 == utf_ptr2char((char *)p)) { break; } } diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c index 5b831a21c0..7aab27577a 100644 --- a/src/nvim/ex_cmds.c +++ b/src/nvim/ex_cmds.c @@ -850,7 +850,7 @@ void ex_retab(exarg_T *eap) emsg(_(e_resulting_text_too_long)); break; } - col += utfc_ptr2len((char_u *)ptr + col); + col += utfc_ptr2len(ptr + col); } if (new_line == NULL) { // out of memory break; @@ -3785,7 +3785,7 @@ static buf_T *do_sub(exarg_T *eap, proftime_T timeout, bool do_buf_event, handle skip_match = true; } else { // 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 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; } } else { - p1 += utfc_ptr2len((char_u *)p1) - 1; + p1 += utfc_ptr2len(p1) - 1; } } size_t new_endcol = STRLEN(new_start); @@ -5464,7 +5464,7 @@ void fix_help_buffer(void) // illegal byte sequence is found. if ((char_u)(*s) >= 0x80 && this_utf != kFalse) { this_utf = kTrue; - const int l = utf_ptr2len((char_u *)s); + const int l = utf_ptr2len(s); if (l == 1) { 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++) { if ((char_u)(*s) >= 0x80) { this_utf8 = kTrue; - const int l = utf_ptr2len((char_u *)s); + const int l = utf_ptr2len(s); if (l == 1) { // Illegal UTF-8 byte sequence. this_utf8 = kFalse; diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index a54d1a14ce..eed2a38a4f 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -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); p = (const char *)xp->xp_pattern; while (*p != NUL) { - c = utf_ptr2char((const char_u *)p); + c = utf_ptr2char(p); if (c == '\\' && p[1] != NUL) { p++; } else if (c == '`') { @@ -3399,11 +3399,11 @@ const char *set_one_cmd_context(expand_T *xp, const char *buff) || ascii_iswhite(c)) { len = 0; // avoid getting stuck when space is in 'isfname' while (*p != NUL) { - c = utf_ptr2char((const char_u *)p); + c = utf_ptr2char(p); if (c == '`' || vim_isfilec_or_wc(c)) { break; } - len = (size_t)utfc_ptr2len((const char_u *)p); + len = (size_t)utfc_ptr2len(p); MB_PTR_ADV(p); } if (in_quote) { @@ -6030,7 +6030,7 @@ static char *uc_split_args(char *arg, size_t *lenp) } len += 3; // "," } else { - const int charlen = utfc_ptr2len((char_u *)p); + const int charlen = utfc_ptr2len(p); len += charlen; p += charlen; @@ -8167,7 +8167,7 @@ static void do_exmap(exarg_T *eap, int isabbrev) { int mode; 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'), (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. 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 len += 2; } @@ -8839,7 +8839,7 @@ static void ex_normal(exarg_T *eap) len = 0; for (p = eap->arg; *p != NUL; 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; if (*p == (char)K_SPECIAL) { arg[len++] = (char)KS_SPECIAL; diff --git a/src/nvim/ex_getln.c b/src/nvim/ex_getln.c index faedba5e5a..1932c02cf2 100644 --- a/src/nvim/ex_getln.c +++ b/src/nvim/ex_getln.c @@ -1780,7 +1780,7 @@ static int command_line_handle_key(CommandLineState *s) } 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.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 || (mod_mask & (MOD_MASK_SHIFT|MOD_MASK_CTRL))) && 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. 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; } 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; - i += utfc_ptr2len(ccline.cmdbuff + i)) { + i += utfc_ptr2len((char *)ccline.cmdbuff + i)) { int c = cmdline_charsize(i); // Count ">" for double-wide multi-byte char that doesn't fit. 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. static void correct_screencol(int idx, int cells, int *col) { - if (utfc_ptr2len(ccline.cmdbuff + idx) > 1 - && utf_ptr2cells(ccline.cmdbuff + idx) > 1 + if (utfc_ptr2len((char *)ccline.cmdbuff + idx) > 1 + && utf_ptr2cells((char *)ccline.cmdbuff + idx) > 1 && (*col) % Columns + cells > Columns) { (*col)++; } @@ -2996,7 +2996,7 @@ static void draw_cmdline(int start, int len) if (cmdline_star > 0) { for (int i = 0; i < len; i++) { 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) { bool do_arabicshape = false; @@ -3029,7 +3029,7 @@ static void draw_cmdline(int start, int len) } 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. arshape_buf[0] = ' '; newlen = 1; @@ -3055,7 +3055,7 @@ static void draw_cmdline(int start, int len) if (i + mb_l >= start + len) { nc = NUL; } else { - nc = utf_ptr2char(p + mb_l); + nc = utf_ptr2char((char *)p + mb_l); } } else { // Displaying from left to right. @@ -3261,7 +3261,7 @@ void unputcmdline(void) if (ccline.cmdlen == ccline.cmdpos && !ui_has(kUICmdline)) { msg_putchar(' '); } 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; cursorcmd(); @@ -3297,13 +3297,13 @@ void put_on_cmdline(char_u *str, int len, int redraw) } else { // Count nr of characters in the new string. m = 0; - for (i = 0; i < len; i += utfc_ptr2len(str + i)) { + for (i = 0; i < len; i += utfc_ptr2len((char *)str + i)) { m++; } // Count nr of bytes in cmdline that are overwritten by these // characters. for (i = ccline.cmdpos; i < ccline.cmdlen && m > 0; - i += utfc_ptr2len(ccline.cmdbuff + i)) { + i += utfc_ptr2len((char *)ccline.cmdbuff + i)) { m--; } 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, // backup to the character before it. There could be two of them. i = 0; - c = utf_ptr2char(ccline.cmdbuff + ccline.cmdpos); + c = utf_ptr2char((char *)ccline.cmdbuff + ccline.cmdpos); while (ccline.cmdpos > 0 && utf_iscomposing(c)) { i = utf_head_off(ccline.cmdbuff, ccline.cmdbuff + ccline.cmdpos - 1) + 1; ccline.cmdpos -= 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)) { // Check the previous character for Arabic combining pair. 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; len += i; } else { @@ -3379,7 +3379,7 @@ void put_on_cmdline(char_u *str, int len, int redraw) if (ccline.cmdspos + c < m) { 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) { 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. for (w = ccline.cmdbuff + ccline.cmdpos; w > ccline.cmdbuff;) { 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; } 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; 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]); - int c0 = utf_ptr2char((char_u *)&xp->xp_files[0][len]); + mb_len = (size_t)utfc_ptr2len(&xp->xp_files[0][len]); + int c0 = utf_ptr2char(&xp->xp_files[0][len]); 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 || xp->xp_context == EXPAND_FILES diff --git a/src/nvim/file_search.c b/src/nvim/file_search.c index 1113459feb..6a3acef91d 100644 --- a/src/nvim/file_search.c +++ b/src/nvim/file_search.c @@ -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;) { - c1 = utf_ptr2char(s1 + i); - c2 = utf_ptr2char(s2 + j); + c1 = utf_ptr2char((char *)s1 + i); + c2 = utf_ptr2char((char *)s2 + j); if ((p_fic ? mb_tolower(c1) != mb_tolower(c2) : c1 != c2) && (prev1 != '*' || prev2 != '*')) { @@ -1121,8 +1121,8 @@ static bool ff_wc_equal(char_u *s1, char_u *s2) prev2 = prev1; prev1 = c1; - i += utfc_ptr2len(s1 + i); - j += utfc_ptr2len(s2 + j); + i += utfc_ptr2len((char *)s1 + i); + j += utfc_ptr2len((char *)s2 + j); } return s1[i] == s2[j]; } diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index 24052d4951..ad0440e0b3 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -1377,7 +1377,7 @@ retry: } else { len = utf_head_off(ptr, p); p -= len; - u8c = utf_ptr2char(p); + u8c = utf_ptr2char((char *)p); if (len == 0) { // Not a valid UTF-8 character, retry with // another fenc when possible, otherwise just @@ -3982,7 +3982,7 @@ static int buf_write_bytes(struct bw_info *ip) break; } if (n > 1) { - c = utf_ptr2char(ip->bw_rest); + c = utf_ptr2char((char *)ip->bw_rest); } else { c = ip->bw_rest[0]; } @@ -4010,7 +4010,7 @@ static int buf_write_bytes(struct bw_info *ip) break; } if (n > 1) { - c = utf_ptr2char(buf + wlen); + c = utf_ptr2char((char *)buf + wlen); } else { c = buf[wlen]; } diff --git a/src/nvim/fold.c b/src/nvim/fold.c index af7288e103..56f3f4893d 100644 --- a/src/nvim/fold.c +++ b/src/nvim/fold.c @@ -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 a TAB with a space. for (p = text; *p != NUL; p++) { - int len = utfc_ptr2len(p); + int len = utfc_ptr2len((char *)p); if (len > 1) { - if (!vim_isprintc(utf_ptr2char(p))) { + if (!vim_isprintc(utf_ptr2char((char *)p))) { break; } p += len - 1; diff --git a/src/nvim/getchar.c b/src/nvim/getchar.c index 4bf7543f5f..5f2a4a281b 100644 --- a/src/nvim/getchar.c +++ b/src/nvim/getchar.c @@ -700,7 +700,7 @@ static int read_redo(bool init, bool old_redo) buf[i] = (char_u)c; if (i == n - 1) { // last byte of a character if (n != 1) { - c = utf_ptr2char(buf); + c = utf_ptr2char((char *)buf); } break; } @@ -1624,7 +1624,7 @@ int vgetc(void) } } no_mapping--; - c = utf_ptr2char(buf); + c = utf_ptr2char((char *)buf); } 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 *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; } @@ -2450,7 +2450,7 @@ static int vgetorpeek(bool advance) curwin->w_wcol = 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_wcol / curwin->w_width_inner; @@ -2471,7 +2471,7 @@ static int vgetorpeek(bool advance) // of a double-wide character. ptr = get_cursor_line_ptr(); col -= utf_head_off(ptr, ptr + col); - if (utf_ptr2cells(ptr + col) > 1) { + if (utf_ptr2cells((char *)ptr + col) > 1) { 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); int last = first; - p = lhs + utfc_ptr2len(lhs); + p = lhs + utfc_ptr2len((char *)lhs); n = 1; while (p < lhs + len) { 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) { 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) { retval = 1; @@ -3543,14 +3543,14 @@ static void validate_maphash(void) /* * 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 mode; p = *cmdp; - modec = *p++; + modec = (uint8_t)(*p++); if (modec == 'i') { mode = INSERT; // :imap } else if (modec == 'l') { @@ -3597,7 +3597,7 @@ void map_clear_mode(char_u *cmdp, char_u *arg, int forceit, int abbr) return; } - mode = get_map_mode(&cmdp, forceit); + mode = get_map_mode((char **)&cmdp, forceit); map_clear_int(curbuf, mode, local, 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; } else { if (isunmap) { - expand_mapmodes = get_map_mode(&cmd, forceit || isabbrev); + expand_mapmodes = get_map_mode((char **)&cmd, forceit || isabbrev); } else { expand_mapmodes = INSERT + CMDLINE; if (!isabbrev) { @@ -4117,7 +4117,7 @@ bool check_abbr(int c, char_u *ptr, int col, int mincol) while (p > ptr + mincol) { p = mb_prevptr(ptr, p); if (ascii_isspace(*p) || (!vim_abbr && is_id != vim_iswordp(p))) { - p += utfc_ptr2len(p); + p += utfc_ptr2len((char *)p); break; } ++clen; @@ -4310,8 +4310,8 @@ char_u *vim_strsave_escape_ks(char_u *p) } else { // Add character, possibly multi-byte to destination, escaping // K_SPECIAL. Be careful, it can be an illegal byte! - d = add_char2buf(utf_ptr2char(s), d); - s += utf_ptr2len(s); + d = add_char2buf(utf_ptr2char((char *)s), d); + s += utf_ptr2len((char *)s); } } *d = NUL; diff --git a/src/nvim/hardcopy.c b/src/nvim/hardcopy.c index b2974854c1..1e9c69c390 100644 --- a/src/nvim/hardcopy.c +++ b/src/nvim/hardcopy.c @@ -589,7 +589,7 @@ static void prt_header(prt_settings_T *const psettings, const int pagenum, const int page_line = 0 - prt_header_height(); mch_print_start_line(true, page_line); for (char_u *p = tbuf; *p != NUL;) { - const int l = utfc_ptr2len(p); + const int l = utfc_ptr2len((char *)p); assert(l >= 0); if (mch_print_text_out(p, (size_t)l)) { 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. */ 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; } // 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; } else { 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) { - const bool half_width = (utf_ptr2cells(p) == 1); + const bool half_width = (utf_ptr2cells((char *)p) == 1); if (half_width) { char_width /= 2; } diff --git a/src/nvim/input.c b/src/nvim/input.c index 6827dcae87..0dfd564e1f 100644 --- a/src/nvim/input.c +++ b/src/nvim/input.c @@ -144,7 +144,7 @@ int get_keystroke(MultiQueue *events) continue; } buf[len >= buflen ? buflen - 1 : len] = NUL; - n = utf_ptr2char(buf); + n = utf_ptr2char((char *)buf); break; } xfree(buf); diff --git a/src/nvim/keymap.c b/src/nvim/keymap.c index 7541837782..3c30389e0b 100644 --- a/src/nvim/keymap.c +++ b/src/nvim/keymap.c @@ -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 off = l = 2; } else { - l = utfc_ptr2len(last_dash + 1); + l = utfc_ptr2len((char *)last_dash + 1); } if (modifiers != 0 && last_dash[l + 1] == '>') { - key = utf_ptr2char(last_dash + off); + key = utf_ptr2char((char *)last_dash + off); } else { key = get_special_key_code(last_dash + off); if (!(flags & FSK_KEEP_X_KEY)) { diff --git a/src/nvim/macros.h b/src/nvim/macros.h index 0af7483154..69ff8c18e4 100644 --- a/src/nvim/macros.h +++ b/src/nvim/macros.h @@ -95,10 +95,10 @@ // MB_PTR_ADV(): advance a pointer to the next character, taking care of // 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. -#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 // multi-byte characters if needed. Only use with "p" > "s" ! diff --git a/src/nvim/mark.c b/src/nvim/mark.c index 0a9b1b26ef..02ae148396 100644 --- a/src/nvim/mark.c +++ b/src/nvim/mark.c @@ -1579,7 +1579,7 @@ void mark_mb_adjustpos(buf_T *buf, pos_T *lp) // double-wide character. if (lp->coladd == 1 && p[lp->col] != TAB - && vim_isprintc(utf_ptr2char(p + lp->col)) + && vim_isprintc(utf_ptr2char((char *)p + lp->col)) && ptr2cells(p + lp->col) > 1) { lp->coladd = 0; } diff --git a/src/nvim/match.c b/src/nvim/match.c index e6f34c5876..808b761df0 100644 --- a/src/nvim/match.c +++ b/src/nvim/match.c @@ -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->conceal_char = 0; 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 @@ -447,7 +447,7 @@ static void next_search_hl(win_T *win, match_T *search_hl, match_T *shl, linenr_ shl->lnum = 0; break; } - matchcol += utfc_ptr2len(ml); + matchcol += utfc_ptr2len((char *)ml); } else { 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. if (shl->startcol == shl->endcol) { if ((*line)[shl->endcol] != NUL) { - shl->endcol += utfc_ptr2len(*line + shl->endcol); + shl->endcol += utfc_ptr2len((char *)(*line) + shl->endcol); } else { 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 && col >= shl->startcol && 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) { 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) { // 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 diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 6dbbb17da9..5f1114fa42 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -430,7 +430,7 @@ int mb_get_class_tab(const char_u *p, const uint64_t *const chartab) } 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. /// 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; // Need to convert to a character number. - if (*p >= 0x80) { + if ((uint8_t)(*p) >= 0x80) { c = utf_ptr2char(p); // An illegal byte is displayed as <xx>. 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]) { return 1; // truncated } - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); // An illegal byte is displayed as <xx>. - if (utf_ptr2len(p) == 1 || c == NUL) { + if (utf_ptr2len((char *)p) == 1 || c == NUL) { return 4; } // 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; - for (const char_u *p = (char_u *)str; *p != NUL; p += utfc_ptr2len(p)) { - clen += utf_ptr2cells(p); + for (const char_u *p = (char_u *)str; *p != NUL; p += utfc_ptr2len((char *)p)) { + clen += utf_ptr2cells((char *)p); } 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; p += utfc_ptr2len_len(p, size + (p - str))) { - clen += utf_ptr2cells(p); + clen += utf_ptr2cells((char *)p); } return clen; @@ -602,9 +602,10 @@ size_t mb_string2cells_len(const char_u *str, size_t size) /// @param[in] p String to convert. /// /// @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 { + uint8_t *p = (uint8_t *)p_in; if (p[0] < 0x80) { // Be quick for ASCII. 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 // 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(). - c = utf_ptr2char(*s); + c = utf_ptr2char((char *)(*s)); // On failure, utf_ptr2char() returns the first byte, so here we // 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; - c = utf_ptr2char(*pp); - *pp += utfc_ptr2len(*pp); + c = utf_ptr2char((char *)(*pp)); + *pp += utfc_ptr2len((char *)(*pp)); return c; } @@ -719,8 +720,8 @@ int mb_cptr2char_adv(const char_u **pp) { int c; - c = utf_ptr2char(*pp); - *pp += utf_ptr2len(*pp); + c = utf_ptr2char((char *)(*pp)); + *pp += utf_ptr2len((char *)(*pp)); return c; } @@ -733,14 +734,14 @@ bool utf_composinglike(const char_u *p1, const char_u *p2) { int c2; - c2 = utf_ptr2char(p2); + c2 = utf_ptr2char((char *)p2); if (utf_iscomposing(c2)) { return true; } if (!arabic_maycombine(c2)) { 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 @@ -758,21 +759,21 @@ int utfc_ptr2char(const char_u *p, int *pcc) int cc; int i = 0; - c = utf_ptr2char(p); - len = utf_ptr2len(p); + c = utf_ptr2char((char *)p); + len = utf_ptr2len((char *)p); // Only accept a composing char when the first char isn't illegal. if ((len > 1 || *p < 0x80) && p[len] >= 0x80 && utf_composinglike(p, p + len)) { - cc = utf_ptr2char(p + len); + cc = utf_ptr2char((char *)p + len); for (;;) { pcc[i++] = cc; if (i == MAX_MCO) { break; } - len += utf_ptr2len(p + len); - if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) { + len += utf_ptr2len((char *)p + len); + if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char((char *)p + len))) { break; } } @@ -800,14 +801,14 @@ int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen) int len = utf_ptr2len_len(p, maxlen); // Is it safe to use utf_ptr2char()? 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. if ((safe || c < 0x80) && len < maxlen && p[len] >= 0x80) { for (; i < MAX_MCO; i++) { int len_cc = utf_ptr2len_len(p + len, 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]))) { 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 /// 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 { + uint8_t *p = (uint8_t *)p_in; if (*p == NUL) { 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 /// /// 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 { - uint8_t b0 = (uint8_t)(*p); + uint8_t *p = (uint8_t *)p_in; + uint8_t b0 = *p; if (b0 == NUL) { 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. - int len = utf_ptr2len(p); + int len = utf_ptr2len((char *)p); // Check for illegal byte. if (len == 1 && b0 >= 0x80) { @@ -919,7 +922,7 @@ int utfc_ptr2len(const char_u *const p) // Skip over composing char. 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); // NB: gets the byte value of invalid sequence bytes. // 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++; if (c > 0xFFFF) { 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); // NB: gets the byte value of invalid sequence bytes. // 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++; if (use_utf16_units && c > 0xFFFF) { count++; @@ -1590,7 +1593,7 @@ void show_utf8(void) // Get the byte length of the char under the cursor, including composing // characters. line = get_cursor_pos_ptr(); - len = utfc_ptr2len(line); + len = utfc_ptr2len((char *)line); if (len == 0) { msg("NUL"); return; @@ -1604,7 +1607,7 @@ void show_utf8(void) STRCPY(IObuff + rlen, "+ "); rlen += 2; } - clen = utf_ptr2len(line + i); + clen = utf_ptr2len((char *)line + i); } sprintf((char *)IObuff + rlen, "%02x ", (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; } - c = utf_ptr2char(q); + c = utf_ptr2char((char *)q); if (utf_iscomposing(c)) { continue; } @@ -1667,7 +1670,7 @@ int utf_head_off(const char_u *base, const char_u *p) while (j > base && (*j & 0xc0) == 0x80) { --j; } - if (arabic_combine(utf_ptr2char(j), c)) { + if (arabic_combine(utf_ptr2char((char *)j), c)) { continue; } } @@ -1823,7 +1826,7 @@ bool utf_allow_break(int cc, int ncc) /// @param[in,out] tp Destination to copy to. 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); *tp += l; @@ -1955,9 +1958,9 @@ void utf_find_illegal(void) while (*p != NUL) { // Illegal means that there are not enough trail bytes (checked by // utf_ptr2len()) or too many of them (overlong sequence). - len = utf_ptr2len(p); + len = utf_ptr2len((char *)p); if (*p >= 0x80 && (len == 1 - || utf_char2len(utf_ptr2char(p)) != len)) { + || utf_char2len(utf_ptr2char((char *)p)) != len)) { if (vimconv.vc_type == CONV_NONE) { curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr()); } else { @@ -1965,7 +1968,7 @@ void utf_find_illegal(void) len = (int)(p - tofree); 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; } } @@ -2027,7 +2030,7 @@ void mb_check_adjust_col(void *win_) // Reset `coladd` when the cursor would be on the right half of a // double-wide character. 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) { win->w_cursor.coladd = 0; } @@ -2057,7 +2060,7 @@ int mb_charlen(const char_u *str) } for (count = 0; *p != NUL; count++) { - p += utfc_ptr2len(p); + p += utfc_ptr2len((char *)p); } return count; @@ -2070,7 +2073,7 @@ int mb_charlen_len(const char_u *str, int len) int count; for (count = 0; *p != NUL && p < str + len; count++) { - p += utfc_ptr2len(p); + p += utfc_ptr2len((char *)p); } 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 // 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; 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 // situations we don't know what to skip anyway. *to++ = '?'; - if (utf_ptr2cells((char_u *)from) > 1) { + if (utf_ptr2cells(from) > 1) { *to++ = '?'; } 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]; } else { - c = utf_ptr2char(ptr + i); + c = utf_ptr2char((char *)ptr + i); if (vcp->vc_type == CONV_TO_LATIN9) { switch (c) { case 0x20ac: diff --git a/src/nvim/memline.c b/src/nvim/memline.c index eec0b2fafc..081045ab18 100644 --- a/src/nvim/memline.c +++ b/src/nvim/memline.c @@ -1823,7 +1823,7 @@ int gchar_pos(pos_T *pos) if (pos->col == MAXCOL) { 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) @@ -4206,7 +4206,7 @@ int inc(pos_T *lp) if (lp->col != MAXCOL) { const char_u *const p = ml_get_pos(lp); 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; return ((p[l] != NUL) ? 0 : 2); diff --git a/src/nvim/message.c b/src/nvim/message.c index 57433ac988..2cd3f8b63d 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -408,7 +408,7 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen) } len += n; buf[e] = s[e]; - for (n = utfc_ptr2len(s + e); --n > 0;) { + for (n = utfc_ptr2len((char *)s + e); --n > 0;) { if (++e == buflen) { break; } @@ -421,7 +421,7 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen) for (;;) { do { 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); if (len + n > room || half == 0) { break; @@ -882,8 +882,8 @@ char_u *msg_may_trunc(bool force, char_u *s) } int n; for (n = 0; size >= room;) { - size -= utf_ptr2cells(s + n); - n += utfc_ptr2len(s + n); + size -= utf_ptr2cells((char *)s + n); + n += utfc_ptr2len((char *)s + n); } n--; s += n; @@ -1480,7 +1480,7 @@ char_u *msg_outtrans_one(char_u *p, int attr) { int l; - if ((l = utfc_ptr2len(p)) > 1) { + if ((l = utfc_ptr2len((char *)p)) > 1) { msg_outtrans_len_attr(p, l, attr); 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 // which the composing char can be drawn. - if (utf_iscomposing(utf_ptr2char(msgstr))) { + if (utf_iscomposing(utf_ptr2char((char *)msgstr))) { 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. mb_l = utfc_ptr2len_len((char_u *)str, len + 1); if (mb_l > 1) { - c = utf_ptr2char((char_u *)str); + c = utf_ptr2char(str); if (vim_isprintc(c)) { // Printable multi-byte char: count the cells. - retval += utf_ptr2cells((char_u *)str); + retval += utf_ptr2cells(str); } else { // Unprintable multi-byte char: print the printable chars so // 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 msg_puts_attr(text, (len > 1 - && utfc_ptr2len((char_u *)text) <= 1 + && utfc_ptr2len(text) <= 1 ? attr : 0)); retval += len; } @@ -1705,7 +1705,7 @@ const char *str2special(const char **const sp, const bool replace_spaces, const const char *p = mb_unescape(sp); if (p == NULL) { - const int len = utf_ptr2len((const char_u *)str); + const int len = utf_ptr2len(str); // Check for an illegal byte. if (MB_BYTE2LEN((uint8_t)(*str)) > len) { 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 // processed by get_special_key_name(). - c = utf_ptr2char((const char_u *)p); + c = utf_ptr2char(p); } else { *sp = str + 1; } @@ -1813,16 +1813,16 @@ void msg_prt_line(char_u *s, int list) assert(p_extra != NULL); c = *p_extra++; } - } else if ((l = utfc_ptr2len(s)) > 1) { - col += utf_ptr2cells(s); + } else if ((l = utfc_ptr2len((char *)s)) > 1) { + col += utf_ptr2cells((char *)s); char buf[MB_MAXBYTES + 1]; if (l >= MB_MAXBYTES) { xstrlcpy(buf, "?", sizeof(buf)); } else if (curwin->w_p_lcs_chars.nbsp != NUL && list - && (utf_ptr2char(s) == 160 - || utf_ptr2char(s) == 0x202f)) { + && (utf_ptr2char((char *)s) == 160 + || utf_ptr2char((char *)s) == 0x202f)) { utf_char2bytes(curwin->w_p_lcs_chars.nbsp, (char_u *)buf); - buf[utfc_ptr2len((char_u *)buf)] = NUL; + buf[utfc_ptr2len(buf)] = NUL; } else { memmove(buf, s, (size_t)l); 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); msg_didout = true; // remember that line is not empty - cw = utf_ptr2cells(s); + cw = utf_ptr2cells((char *)s); if (cw > 1 && (cmdmsg_rl ? msg_col <= 1 : msg_col == Columns - 1)) { // 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 ? (msg_col <= 1 || (*s == TAB && msg_col <= 7) - || (utf_ptr2cells(s) > 1 + || (utf_ptr2cells((char *)s) > 1 && msg_col <= 2)) : ((*s != '\r' && msg_col + t_col >= Columns - 1) || (*s == TAB && msg_col + t_col >= ((Columns - 1) & ~7)) - || (utf_ptr2cells(s) > 1 + || (utf_ptr2cells((char *)s) > 1 && msg_col + t_col >= Columns - 2))))) { // The screen is scrolled up when at the last row (some terminals // 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. l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); } else { - l = utfc_ptr2len(s); + l = utfc_ptr2len((char *)s); } s = screen_puts_mbyte((char_u *)s, l, attr); 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' || msg_col + t_col >= Columns - || (utf_ptr2cells(s) > 1 + || (utf_ptr2cells((char *)s) > 1 && msg_col + t_col >= Columns - 1) ; 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") vim_beep(BO_SH); } else if (*s >= 0x20) { // printable char - cw = utf_ptr2cells(s); + cw = utf_ptr2cells((char *)s); if (maxlen >= 0) { // avoid including composing chars after the end l = utfc_ptr2len_len(s, (int)((str + maxlen) - s)); } else { - l = utfc_ptr2len(s); + l = utfc_ptr2len((char *)s); } // When drawing from right to left or when a double-wide character // 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; // If the string starts with a composing character don't increment the // column position for it. - if (utf_iscomposing(utf_ptr2char(t_s))) { + if (utf_iscomposing(utf_ptr2char((char *)t_s))) { msg_col--; } 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) { - int len = utf_ptr2len((const char_u *)s); + int len = utf_ptr2len(s); if (!(silent_mode && p_verbose == 0)) { // NL --> CR NL translation (for Unix, not for "--version") 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 if (cmdmsg_rl) { 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); retval = 1; for (i = 0; hotkeys[i]; i++) { - if (utf_ptr2char(hotkeys + i) == c) { + if (utf_ptr2char((char *)hotkeys + i) == c) { break; } - i += utfc_ptr2len(hotkeys + i) - 1; + i += utfc_ptr2len((char *)hotkeys + i) - 1; retval++; } if (hotkeys[i]) { @@ -3508,10 +3508,10 @@ static int copy_char(const char_u *from, char_u *to, bool lowercase) FUNC_ATTR_NONNULL_ALL { if (lowercase) { - int c = mb_tolower(utf_ptr2char(from)); + int c = mb_tolower(utf_ptr2char((char *)from)); return utf_char2bytes(c, to); } - int len = utfc_ptr2len(from); + int len = utfc_ptr2len((char *)from); memmove(to, from, (size_t)len); return len; } diff --git a/src/nvim/mouse.c b/src/nvim/mouse.c index 4495473074..8038ba2cad 100644 --- a/src/nvim/mouse.c +++ b/src/nvim/mouse.c @@ -702,7 +702,7 @@ static int mouse_adjust_click(win_T *wp, int row, int col) vcol = 0; while (vcol < offset && *ptr != NUL) { vcol += win_chartabsize(curwin, ptr, vcol); - ptr += utfc_ptr2len(ptr); + ptr += utfc_ptr2len((char *)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; while (vcol < col && *ptr_end != NUL) { vcol += win_chartabsize(curwin, ptr_end, vcol); - ptr_end += utfc_ptr2len(ptr_end); + ptr_end += utfc_ptr2len((char *)ptr_end); } int matchid; @@ -723,8 +723,8 @@ static int mouse_adjust_click(win_T *wp, int row, int col) vcol = offset; -#define INCR() nudge++; ptr_end += utfc_ptr2len(ptr_end) -#define DECR() nudge--; ptr_end -= utfc_ptr2len(ptr_end) +#define INCR() nudge++; ptr_end += utfc_ptr2len((char *)ptr_end) +#define DECR() nudge--; ptr_end -= utfc_ptr2len((char *)ptr_end) while (ptr < ptr_end && *ptr != NUL) { 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) { INCR(); - ptr += utfc_ptr2len(ptr); + ptr += utfc_ptr2len((char *)ptr); 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; @@ -798,8 +798,8 @@ int mouse_check_fold(void) // Remember the character under the mouse, might be one of foldclose or // foldopen fillchars in the fold column. if (gp->chars != NULL) { - mouse_char = utf_ptr2char(gp->chars[gp->line_offset[row] - + (unsigned)col]); + mouse_char = utf_ptr2char((char *)gp->chars[gp->line_offset[row] + + (unsigned)col]); } // Check for position outside of the fold column. diff --git a/src/nvim/normal.c b/src/nvim/normal.c index 81c95ec77f..9c8c27c9bb 100644 --- a/src/nvim/normal.c +++ b/src/nvim/normal.c @@ -2094,7 +2094,7 @@ bool do_mouse(oparg_T *oap, int c, int dir, long count, bool fixindent) find_start_of_word(&VIsual); if (*p_sel == 'e' && *get_cursor_pos_ptr() != NUL) { curwin->w_cursor.col += - utfc_ptr2len(get_cursor_pos_ptr()); + utfc_ptr2len((char *)get_cursor_pos_ptr()); } 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); 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 (*p_sel == 'e') { 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)) { break; } - col += utfc_ptr2len(ptr + col); + col += utfc_ptr2len((char *)ptr + col); } // 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) && col <= (int)startcol && find_is_eval_item(ptr + col, &col, &bn, FORWARD)))) { - col += utfc_ptr2len(ptr + col); + col += utfc_ptr2len((char *)ptr + col); } assert(col >= 0); @@ -2585,7 +2585,7 @@ void clear_showcmd(void) e = ml_get_pos(&VIsual); } while ((*p_sel != 'e') ? s <= e : s < e) { - l = utfc_ptr2len(s); + l = utfc_ptr2len((char *)s); if (l == 0) { bytes++; chars++; @@ -3262,7 +3262,7 @@ static bool nv_screengo(oparg_T *oap, int dir, long dist) 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 && (curwin->w_curswant <= (colnr_T)width1) && !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 // 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--) { *p++ = *ptr++; } @@ -4308,7 +4308,7 @@ bool get_visual_text(cmdarg_T *cap, char_u **pp, size_t *lenp) } if (*lenp > 0) { // 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(); @@ -4470,7 +4470,7 @@ static void nv_right(cmdarg_T *cap) if (virtual_active()) { oneright(); } 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(); 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; } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index f7a3201568..d9844b4e99 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -381,7 +381,7 @@ static void shift_block(oparg_T *oap, int amount) colnr_T ws_vcol = bd.start_vcol - bd.pre_whitesp; char_u *old_textstart = bd.textstart; if (bd.startspaces) { - if (utfc_ptr2len(bd.textstart) == 1) { + if (utfc_ptr2len((char *)bd.textstart) == 1) { bd.textstart++; } else { ws_vcol = 0; @@ -2034,7 +2034,7 @@ static int op_replace(oparg_T *oap, int c) n = gchar_cursor(); if (n != NUL) { 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) { // 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; 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 if (len > 0) { @@ -2256,7 +2256,7 @@ bool swapchar(int op_type, pos_T *pos) curwin->w_cursor = *pos; // 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); curwin->w_cursor = sp; } 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 eol = false; 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); @@ -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 - curwin->w_cursor.col += utfc_ptr2len(get_cursor_pos_ptr()); + curwin->w_cursor.col += utfc_ptr2len((char *)get_cursor_pos_ptr()); col++; } else { 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 // char 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. col += bytelen; @@ -3898,7 +3898,7 @@ void ex_display(exarg_T *eap) n -= 2; } 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); p += clen - 1; } @@ -3976,7 +3976,7 @@ static void dis_msg(const char_u *p, bool skip_esc) while (*p != NUL && !(*p == ESC && skip_esc && *(p + 1) == NUL) && (n -= ptr2cells(p)) >= 0) { - if ((l = utfc_ptr2len(p)) > 1) { + if ((l = utfc_ptr2len((char *)p)) > 1) { msg_outtrans_len(p, l); p += l; } else { @@ -4120,11 +4120,11 @@ int do_join(size_t count, int insert_space, int save_undo, int use_formatoptions && sumsize != 0 && endcurr1 != TAB && (!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) - || (utf_ptr2char(curr) < 0x100 && !utf_eat_space(endcurr1)) + || (utf_ptr2char((char *)curr) < 0x100 && !utf_eat_space(endcurr1)) || (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 if (endcurr1 == ' ') { 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) { cend = curr + currsize; MB_PTR_BACK(curr, cend); - endcurr1 = utf_ptr2char(cend); + endcurr1 = utf_ptr2char((char *)cend); if (cend > curr) { MB_PTR_BACK(curr, cend); - endcurr2 = utf_ptr2char(cend); + endcurr2 = utf_ptr2char((char *)cend); } } line_breakcheck(); @@ -5117,7 +5117,7 @@ int do_addsub(int op_type, pos_T *pos, int length, linenr_T Prenum1) if (visual) { while (ptr[col] != NUL && length > 0 && !ascii_isdigit(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; 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; } chars++; - i += utfc_ptr2len(line + i); + i += utfc_ptr2len((char *)line + i); } 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. 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) { oap->end.col += l - 1; } diff --git a/src/nvim/option.c b/src/nvim/option.c index 9be55b91b4..aac05eba0b 100644 --- a/src/nvim/option.c +++ b/src/nvim/option.c @@ -1502,7 +1502,7 @@ int do_set(char_u *arg, int opt_flags) ) { arg++; // remove backslash } - i = utfc_ptr2len(arg); + i = utfc_ptr2len((char *)arg); if (i > 1) { // copy multibyte char memmove(s, arg, (size_t)i); @@ -2664,13 +2664,13 @@ ambw_end: int x2 = -1; int x3 = -1; - p += utfc_ptr2len(p); + p += utfc_ptr2len((char *)p); if (*p != NUL) { x2 = *p++; } if (*p != NUL) { - x3 = utf_ptr2char(p); - p += utfc_ptr2len(p); + x3 = utf_ptr2char((char *)p); + p += utfc_ptr2len((char *)p); } if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) { 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 - int clen = utf_ptr2len(s); + int clen = utf_ptr2len((char *)s); int c = mb_cptr2char_adv((const char_u **)p); if (clen == 1 && c > 127) { // Invalid UTF-8 byte return 0; @@ -7140,7 +7140,7 @@ static void langmap_set(void) if (p[0] == '\\' && p[1] != NUL) { p++; } - from = utf_ptr2char(p); + from = utf_ptr2char((char *)p); to = NUL; if (p2 == NULL) { MB_PTR_ADV(p); @@ -7148,14 +7148,14 @@ static void langmap_set(void) if (p[0] == '\\') { p++; } - to = utf_ptr2char(p); + to = utf_ptr2char((char *)p); } } else { if (p2[0] != ',') { if (p2[0] == '\\') { p2++; } - to = utf_ptr2char(p2); + to = utf_ptr2char((char *)p2); } } if (to == NUL) { diff --git a/src/nvim/path.c b/src/nvim/path.c index 4cbe6ebcf5..9e3aad5aae 100644 --- a/src/nvim/path.c +++ b/src/nvim/path.c @@ -299,7 +299,7 @@ void shorten_dir_len(char_u *str, int trim_len) skip = true; } } - int l = utfc_ptr2len(s); + int l = utfc_ptr2len((char *)s); while (--l > 0) { *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 && (vim_strchr((char_u *)"*?[{~$", *path_end) != NULL #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 )) { e = p; } - len = (size_t)(utfc_ptr2len(path_end)); + len = (size_t)(utfc_ptr2len((char *)path_end)); memcpy(p, path_end, len); p += len; path_end += len; @@ -1980,8 +1980,8 @@ int pathcmp(const char *p, const char *q, int maxlen) const char *s = NULL; for (i = 0, j = 0; maxlen < 0 || (i < maxlen && j < maxlen);) { - c1 = utf_ptr2char((char_u *)p + i); - c2 = utf_ptr2char((char_u *)q + j); + c1 = utf_ptr2char(p + i); + c2 = utf_ptr2char(q + j); // End of "p": check if "q" also ends or just has a slash. if (c1 == NUL) { @@ -2016,15 +2016,15 @@ int pathcmp(const char *p, const char *q, int maxlen) : c1 - c2; // no match } - i += utfc_ptr2len((char_u *)p + i); - j += utfc_ptr2len((char_u *)q + j); + i += utfc_ptr2len(p + i); + j += utfc_ptr2len(q + j); } if (s == NULL) { // "i" or "j" ran into "maxlen" return 0; } - c1 = utf_ptr2char((char_u *)s + i); - c2 = utf_ptr2char((char_u *)s + i + utfc_ptr2len((char_u *)s + i)); + c1 = utf_ptr2char(s + i); + c2 = utf_ptr2char(s + i + utfc_ptr2len(s + i)); // ignore a trailing slash, but not "//" or ":/" if (c2 == NUL && i > 0 diff --git a/src/nvim/popupmnu.c b/src/nvim/popupmnu.c index aff0ea94f7..78b3ceaacf 100644 --- a/src/nvim/popupmnu.c +++ b/src/nvim/popupmnu.c @@ -521,7 +521,7 @@ void pum_redraw(void) if (size > pum_width) { do { - size -= utf_ptr2cells(rt); + size -= utf_ptr2cells((char *)rt); MB_PTR_ADV(rt); } while (size > pum_width); diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index cc960b0dc7..6a4a15d7f8 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -392,9 +392,9 @@ static int get_equi_class(char_u **pp) char_u *p = *pp; if (p[1] == '=' && p[2] != NUL) { - l = utfc_ptr2len(p + 2); + l = utfc_ptr2len((char *)p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - c = utf_ptr2char(p + 2); + c = utf_ptr2char((char *)p + 2); *pp += l + 4; return c; } @@ -416,9 +416,9 @@ static int get_coll_element(char_u **pp) char_u *p = *pp; 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] == ']') { - c = utf_ptr2char(p + 2); + c = utf_ptr2char((char *)p + 2); *pp += l + 4; return c; } @@ -449,7 +449,7 @@ static char_u *skip_anyof(char_u *p) p++; } while (*p != NUL && *p != ']') { - if ((l = utfc_ptr2len(p)) > 1) { + if ((l = utfc_ptr2len((char *)p)) > 1) { p += l; } else if (*p == '-') { p++; @@ -719,13 +719,13 @@ static int peekchr(void) * Next character can never be (made) magic? * Then backslashing it won't do anything. */ - curchr = utf_ptr2char(regparse + 1); + curchr = utf_ptr2char((char *)regparse + 1); } break; } default: - curchr = utf_ptr2char(regparse); + curchr = utf_ptr2char((char *)regparse); } return curchr; @@ -744,7 +744,7 @@ static void skipchr(void) } if (regparse[prevchr_len] != NUL) { // 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; 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. if (c > 0x80) { const int folded_c = utf_fold(c); - for (const char_u *p = s; *p != NUL; p += utfc_ptr2len(p)) { - if (utf_fold(utf_ptr2char(p)) == folded_c) { + for (const char_u *p = s; *p != NUL; p += utfc_ptr2len((char *)p)) { + if (utf_fold(utf_ptr2char((char *)p)) == folded_c) { 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 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++; } } else { - c = utf_ptr2char(src - 1); + c = utf_ptr2char((char *)src - 1); } // Write to buffer, if copy is set. if (func_one != NULL) { @@ -1926,13 +1926,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, cc = c; } - int totlen = utfc_ptr2len(src - 1); + int totlen = utfc_ptr2len((char *)src - 1); if (copy) { utf_char2bytes(cc, dst); } 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 // 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; } else { - c = utf_ptr2char(s); + c = utf_ptr2char((char *)s); if (func_one != (fptr_T)NULL) { // 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 // at a time. - l = utf_ptr2len(s) - 1; + l = utf_ptr2len((char *)s) - 1; s += l; len -= l; diff --git a/src/nvim/regexp_bt.c b/src/nvim/regexp_bt.c index 7d0b9a7a77..e8878d61d5 100644 --- a/src/nvim/regexp_bt.c +++ b/src/nvim/regexp_bt.c @@ -1895,8 +1895,8 @@ collection: } else { // produce a multibyte character, including any // following composing characters. - startc = utf_ptr2char(regparse); - int len = utfc_ptr2len(regparse); + startc = utf_ptr2char((char *)regparse); + int len = utfc_ptr2len((char *)regparse); if (utf_char2len(startc) != len) { // composing chars startc = -1; @@ -1953,11 +1953,11 @@ do_multibyte: // Need to get composing character too. for (;; ) { - l = utf_ptr2len(regparse); + l = utf_ptr2len((char *)regparse); if (!utf_composinglike(regparse, regparse + l)) { break; } - regmbc(utf_ptr2char(regparse)); + regmbc(utf_ptr2char((char *)regparse)); skipchr(); } } @@ -2403,7 +2403,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) } if (OP(scan) == EXACTLY) { - r->regstart = utf_ptr2char(OPERAND(scan)); + r->regstart = utf_ptr2char((char *)OPERAND(scan)); } else if (OP(scan) == BOW || OP(scan) == EOW || 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) { char_u *regnext_scan = regnext(scan); 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 + ADD_NL: 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); } else if (*scan == NUL) { if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline @@ -2671,7 +2671,7 @@ regrepeat( case SFNAME: case SFNAME + ADD_NL: 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); } else if (*scan == NUL) { if (!REG_MULTI || !WITH_NL(OP(p)) || rex.lnum > rex.reg_maxline @@ -2709,7 +2709,7 @@ regrepeat( if (got_int) { break; } - } else if (vim_isprintc(utf_ptr2char(scan)) == 1 + } else if (vim_isprintc(utf_ptr2char((char *)scan)) == 1 && (testval || !ascii_isdigit(*scan))) { MB_PTR_ADV(scan); } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { @@ -2737,7 +2737,7 @@ do_class: if (got_int) { break; } - } else if ((l = utfc_ptr2len(scan)) > 1) { + } else if ((l = utfc_ptr2len((char *)scan)) > 1) { if (testval != 0) { break; } @@ -2852,18 +2852,18 @@ do_class: // Safety check (just in case 'encoding' was changed since // compiling the program). - if ((len = utfc_ptr2len(opnd)) > 1) { + if ((len = utfc_ptr2len((char *)opnd)) > 1) { 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++) { if (opnd[i] != scan[i]) { break; } } if (i < len && (!rex.reg_ic - || utf_fold(utf_ptr2char(scan)) != cf)) { + || utf_fold(utf_ptr2char((char *)scan)) != cf)) { break; } scan += len; @@ -2894,8 +2894,8 @@ do_class: } } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; - } else if ((len = utfc_ptr2len(scan)) > 1) { - if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { + } else if ((len = utfc_ptr2len((char *)scan)) > 1) { + if ((cstrchr(opnd, utf_ptr2char((char *)scan)) == NULL) == testval) { break; } scan += len; @@ -3106,7 +3106,7 @@ static bool regmatch( if (WITH_NL(op)) { op -= ADD_NL; } - c = utf_ptr2char(rex.input); + c = utf_ptr2char((char *)rex.input); switch (op) { case BOL: if (rex.input != rex.line) { @@ -3308,7 +3308,7 @@ static bool regmatch( break; case PRINT: - if (!vim_isprintc(utf_ptr2char(rex.input))) { + if (!vim_isprintc(utf_ptr2char((char *)rex.input))) { status = RA_NOMATCH; } else { ADVANCE_REGINPUT(); @@ -3316,7 +3316,7 @@ static bool regmatch( break; 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; } else { ADVANCE_REGINPUT(); @@ -3507,25 +3507,25 @@ static bool regmatch( const char_u *opnd = OPERAND(scan); // Safety check (just in case 'encoding' was changed since // compiling the program). - if ((len = utfc_ptr2len(opnd)) < 2) { + if ((len = utfc_ptr2len((char *)opnd)) < 2) { status = RA_NOMATCH; break; } - const int opndc = utf_ptr2char(opnd); + const int opndc = utf_ptr2char((char *)opnd); if (utf_iscomposing(opndc)) { // When only a composing char is given match at any // position where that composing char appears. status = RA_NOMATCH; for (i = 0; rex.input[i] != NUL; - i += utf_ptr2len(rex.input + i)) { - const int inpc = utf_ptr2char(rex.input + i); + i += utf_ptr2len((char *)rex.input + i)) { + const int inpc = utf_ptr2char((char *)rex.input + i); if (!utf_iscomposing(inpc)) { if (i > 0) { break; } } else if (opndc == inpc) { // Include all following composing chars. - len = i + utfc_ptr2len(rex.input + i); + len = i + utfc_ptr2len((char *)rex.input + i); status = RA_MATCH; break; } @@ -3545,7 +3545,7 @@ static bool regmatch( case RE_COMPOSING: { // Skip composing characters. - while (utf_iscomposing(utf_ptr2char(rex.input))) { + while (utf_iscomposing(utf_ptr2char((char *)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 (prog->regmust != NULL) { - int c = utf_ptr2char(prog->regmust); + int c = utf_ptr2char((char *)prog->regmust); s = line + col; // 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. if (prog->reganch) { - int c = utf_ptr2char(rex.line + col); + int c = utf_ptr2char((char *)rex.line + col); if (prog->regstart == NUL || prog->regstart == c || (rex.reg_ic @@ -4570,7 +4570,7 @@ static long bt_regexec_both(char_u *line, if (rex.line[col] == NUL) { 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. if (tm != NULL && ++tm_count == 20) { tm_count = 0; diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index a8d6e9c40b..0a6d513a35 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -1465,7 +1465,7 @@ static int nfa_regatom(void) return FAIL; } 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) { EMIT(NFA_CONCAT); } @@ -1902,7 +1902,7 @@ collection: // Normal printable char if (startc == -1) { - startc = utf_ptr2char(regparse); + startc = utf_ptr2char((char *)regparse); } /* Previous char was '-', so this char is end of range. */ @@ -2007,7 +2007,7 @@ collection: nfa_do_multibyte: // 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)) { int i = 0; @@ -2025,7 +2025,7 @@ nfa_do_multibyte: EMIT(NFA_CONCAT); if ((i += utf_char2len(c)) >= plen) break; - c = utf_ptr2char(old_regparse + i); + c = utf_ptr2char((char *)old_regparse + i); } EMIT(NFA_COMPOSING); 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) colnr_T col = startcol; - int regstart_len = PTR2LEN(rex.line + startcol); + int regstart_len = PTR2LEN((char *)rex.line + startcol); for (;;) { bool match = true; char_u *s1 = match_text; char_u *s2 = rex.line + col + regstart_len; // skip regstart while (*s1) { - int c1_len = PTR2LEN(s1); - int c1 = utf_ptr2char(s1); - int c2_len = PTR2LEN(s2); - int c2 = utf_ptr2char(s2); + int c1_len = PTR2LEN((char *)s1); + int c1 = utf_ptr2char((char *)s1); + int c2_len = PTR2LEN((char *)s2); + int c2 = utf_ptr2char((char *)s2); if ((c1 != c2 && (!rex.reg_ic || utf_fold(c1) != utf_fold(c2))) || c1_len != c2_len) { @@ -5189,7 +5189,7 @@ static long find_match_text(colnr_T startcol, int regstart, char_u *match_text) } if (match // check that no composing char follows - && !utf_iscomposing(utf_ptr2char(s2))) { + && !utf_iscomposing(utf_ptr2char((char *)s2))) { cleanup_subexpr(); if (REG_MULTI) { 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. */ for (;; ) { - int curc = utf_ptr2char(rex.input); - int clen = utfc_ptr2len(rex.input); + int curc = utf_ptr2char((char *)rex.input); + int clen = utfc_ptr2len((char *)rex.input); if (curc == NUL) { clen = 0; 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. // Get them into cchars[] first. while (len < clen) { - mc = utf_ptr2char(rex.input + len); + mc = utf_ptr2char((char *)rex.input + len); cchars[ccount++] = mc; len += utf_char2len(mc); if (ccount == MAX_MCO) { @@ -5987,12 +5987,12 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, break; 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); break; 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); 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 // itself. When it is set skip over composing characters. if (result && !rex.reg_icombine) { - clen = utf_ptr2len(rex.input); + clen = utf_ptr2len((char *)rex.input); } ADD_STATE_IF_MATCH(t->state); @@ -6494,7 +6494,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, } else { // Checking if the required start character matches is // 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 && (!rex.reg_ic || utf_fold(c) != utf_fold(prog->regstart))) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index 07207b70d1..f3e627cc65 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -1858,8 +1858,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) { const char_u *p = (char_u *)s->p; - int cells = utf_ptr2cells(p); - int c_len = utfc_ptr2len(p); + int cells = utf_ptr2cells((char *)p); + int c_len = utfc_ptr2len((char *)p); int u8c, u8cc[MAX_MCO]; if (cells > maxcells) { return -1; @@ -1886,7 +1886,7 @@ static int line_putchar(buf_T *buf, LineState *s, schar_T *dest, int maxcells, b if (rl) { pc = s->prev_c; pc1 = s->prev_c1; - nc = utf_ptr2char(p + c_len); + nc = utf_ptr2char((char *)p + c_len); s->prev_c1 = u8cc[0]; } else { pc = utfc_ptr2char(p + c_len, pcc); @@ -2534,7 +2534,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc ptr = prev_ptr; // If the character fits on the screen, don't need to skip it. // Except for a TAB. - if (utf_ptr2cells(ptr) >= c || *ptr == TAB) { + if (utf_ptr2cells((char *)ptr) >= c || *ptr == TAB) { n_skip = v - vcol; } } @@ -2958,7 +2958,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 if (vcol == fromcol || (vcol + 1 == fromcol && n_extra == 0 - && utf_ptr2cells(ptr) > 1) + && utf_ptr2cells((char *)ptr) > 1) || ((int)vcol_prev == fromcol_prev && vcol_prev < vcol // not at margin && vcol < tocol)) { @@ -3058,7 +3058,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc mb_c = c; // If the UTF-8 character is more than one byte: // Decode it into "mb_c". - mb_l = utfc_ptr2len(p_extra); + mb_l = utfc_ptr2len((char *)p_extra); mb_utf8 = false; if (mb_l > n_extra) { mb_l = 1; @@ -3111,7 +3111,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc mb_c = c; // If the UTF-8 character is more than one byte: Decode it // into "mb_c". - mb_l = utfc_ptr2len(ptr); + mb_l = utfc_ptr2len((char *)ptr); mb_utf8 = false; if (mb_l > 1) { mb_c = utfc_ptr2char(ptr, u8cc); @@ -3169,7 +3169,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc if (wp->w_p_rl) { pc = prev_c; pc1 = prev_c1; - nc = utf_ptr2char(ptr + mb_l); + nc = utf_ptr2char((char *)ptr + mb_l); prev_c1 = u8cc[0]; } else { pc = utfc_ptr2char(ptr + mb_l, pcc); @@ -5072,7 +5072,7 @@ void win_redr_status_matches(expand_T *xp, int num_matches, char_u **matches, in for (; *s != NUL; ++s) { s += skip_status_match_char(xp, 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) s += l - 1; len += l; @@ -5232,8 +5232,8 @@ static void win_redr_status(win_T *wp) // Find first character that will fit. // Going from start to end is much faster for DBCS. for (i = 0; p[i] != NUL && clen >= this_ru_col - 1; - i += utfc_ptr2len(p + i)) { - clen -= utf_ptr2cells(p + i); + i += utfc_ptr2len((char *)p + i)) { + clen -= utf_ptr2cells((char *)p + i); } len = clen; if (i > 0) { @@ -5883,7 +5883,7 @@ void grid_puts_len(ScreenGrid *grid, char_u *text, int textlen, int row, int col if (len > 0) { mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); } else { - mbyte_blen = utfc_ptr2len(ptr); + mbyte_blen = utfc_ptr2len((char *)ptr); } if (len >= 0) { u8c = utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr)); @@ -6506,7 +6506,7 @@ void setcursor(void) // With 'rightleft' set and the cursor on a double-wide character, // position it on the leftmost column. 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); } @@ -7371,8 +7371,8 @@ static void win_redr_ruler(win_T *wp, bool always) } // Truncate at window boundary. o = 0; - for (i = 0; buffer[i] != NUL; i += utfc_ptr2len(buffer + i)) { - o += utf_ptr2cells(buffer + i); + for (i = 0; buffer[i] != NUL; i += utfc_ptr2len((char *)buffer + i)) { + o += utf_ptr2cells((char *)buffer + i); if (this_ru_col + o > width) { buffer[i] = NUL; break; diff --git a/src/nvim/search.c b/src/nvim/search.c index 0749e53e68..a7a8d2762c 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -219,7 +219,7 @@ char_u *reverse_text(char_u *s) FUNC_ATTR_NONNULL_RET char_u *rev = xmalloc(len + 1); size_t rev_i = len; 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; memmove(rev + rev_i, s + s_i, mb_len); s_i += mb_len - 1; @@ -388,10 +388,10 @@ bool pat_has_uppercase(char_u *pat) char_u *p = pat; while (*p != NUL) { - const int l = utfc_ptr2len(p); + const int l = utfc_ptr2len((char *)p); if (l > 1) { - if (mb_isupper(utf_ptr2char(p))) { + if (mb_isupper(utf_ptr2char((char *)p))) { return true; } 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) { start_char_len = 1; } else { - start_char_len = utfc_ptr2len(ptr + pos->col); + start_char_len = utfc_ptr2len((char *)ptr + pos->col); } } else { 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) { - matchcol += utfc_ptr2len(ptr + matchcol); + matchcol += utfc_ptr2len((char *)ptr + matchcol); } 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 if (matchcol == matchpos.col && ptr[matchcol] != NUL) { - matchcol += utfc_ptr2len(ptr + matchcol); + matchcol += utfc_ptr2len((char *)ptr + matchcol); } } else { // 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; if (ptr[matchcol] != NUL) { - matchcol += utfc_ptr2len(ptr + matchcol); + matchcol += utfc_ptr2len((char *)ptr + matchcol); } } 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. if (!cmd_silent) { 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. msgbuf[1] = ' '; memmove(msgbuf + 2, p, STRLEN(p)); @@ -1593,7 +1593,7 @@ int searchc(cmdarg_T *cap, int t_cmd) while (count--) { for (;;) { if (dir > 0) { - col += utfc_ptr2len(p + col); + col += utfc_ptr2len((char *)p + col); if (col >= len) { 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; while (*ptr != NUL) { - if (utf_ptr2char(ptr) == *initc) { + if (utf_ptr2char((char *)ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); + *initc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1); *backwards = true; } else { - *findc = utf_ptr2char(ptr + utfc_ptr2len(ptr) + 1); + *findc = utf_ptr2char((char *)ptr + utfc_ptr2len((char *)ptr) + 1); *backwards = false; } return; } char_u *prev = ptr; - ptr += utfc_ptr2len(ptr) + 1; - if (utf_ptr2char(ptr) == *initc) { + ptr += utfc_ptr2len((char *)ptr) + 1; + if (utf_ptr2char((char *)ptr) == *initc) { if (switchit) { *findc = *initc; - *initc = utf_ptr2char(prev); + *initc = utf_ptr2char((char *)prev); *backwards = false; } else { - *findc = utf_ptr2char(prev); + *findc = utf_ptr2char((char *)prev); *backwards = true; } return; } - ptr += utfc_ptr2len(ptr); + ptr += utfc_ptr2len((char *)ptr); if (*ptr == ',') { ptr++; } @@ -1880,7 +1880,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) --pos.col; } for (;;) { - initc = utf_ptr2char(linep + pos.col); + initc = utf_ptr2char((char *)linep + pos.col); if (initc == NUL) { break; } @@ -1889,7 +1889,7 @@ pos_T *findmatchlimit(oparg_T *oap, int initc, int flags, int64_t maxtravel) if (findc) { break; } - pos.col += utfc_ptr2len(linep + pos.col); + pos.col += utfc_ptr2len((char *)linep + pos.col); } if (!findc) { // 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); } } 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 * 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) { case NUL: // at end of line without trailing backslash, reset inquote @@ -2388,14 +2388,14 @@ void showmatch(int c) */ // 'matchpairs' is "x:y,x:y" 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; } - p += utfc_ptr2len(p) + 1; - if (utf_ptr2char(p) == c && !(curwin->w_p_rl ^ p_ri)) { + p += utfc_ptr2len((char *)p) + 1; + if (utf_ptr2char((char *)p) == c && !(curwin->w_p_rl ^ p_ri)) { break; } - p += utfc_ptr2len(p); + p += utfc_ptr2len((char *)p); if (*p == NUL) { return; } @@ -3972,7 +3972,7 @@ static int find_next_quote(char_u *line, int col, int quotechar, char_u *escape) } else if (c == quotechar) { break; } - col += utfc_ptr2len(line + col); + col += utfc_ptr2len((char *)line + col); } return col; } @@ -4883,10 +4883,10 @@ static int fuzzy_match_compute_score(const char_u *const str, const int strSz, int neighbor; for (uint32_t sidx = 0; sidx < currIdx; sidx++) { - neighbor = utf_ptr2char(p); + neighbor = utf_ptr2char((char *)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)) { 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 bool first_match = true; while (*fuzpat != NUL && *str != NUL) { - const int c1 = utf_ptr2char(fuzpat); - const int c2 = utf_ptr2char(str); + const int c1 = utf_ptr2char((char *)fuzpat); + const int c2 = utf_ptr2char((char *)str); // Found match 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 uint32_t recursiveMatches[MAX_FUZZY_MATCHES]; 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, matches, recursiveMatches, 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; } pat = p; - while (*p != NUL && !ascii_iswhite(utf_ptr2char(p))) { + while (*p != NUL && !ascii_iswhite(utf_ptr2char((char *)p))) { MB_PTR_ADV(p); } 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; const char_u *p = str; 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]); j++; } @@ -5839,7 +5839,7 @@ exit_matched: && action == ACTION_EXPAND && !(compl_cont_status & CONT_SOL) && *startp != NUL - && *(p = startp + utfc_ptr2len(startp)) != NUL) { + && *(p = startp + utfc_ptr2len((char *)startp)) != NUL) { goto search_line; } } diff --git a/src/nvim/sign.c b/src/nvim/sign.c index e2d40b4a21..6e1ae1fdec 100644 --- a/src/nvim/sign.c +++ b/src/nvim/sign.c @@ -884,11 +884,11 @@ static int sign_define_init_text(sign_T *sp, char_u *text) } // Count cells and check for non-printable chars cells = 0; - for (s = text; s < endp; s += utfc_ptr2len(s)) { - if (!vim_isprintc(utf_ptr2char(s))) { + for (s = text; s < endp; s += utfc_ptr2len((char *)s)) { + if (!vim_isprintc(utf_ptr2char((char *)s))) { break; } - cells += utf_ptr2cells(s); + cells += utf_ptr2cells((char *)s); } // Currently must be empty, one or two display cells if (s != endp || cells > 2) { diff --git a/src/nvim/spell.c b/src/nvim/spell.c index ae3d475f36..047558b0cf 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -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 if (use_camel_case) { - c = utf_ptr2char(mi.mi_fend); + c = utf_ptr2char((char *)mi.mi_fend); 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); if (use_camel_case) { const bool prev_upper = this_upper; - c = utf_ptr2char(mi.mi_fend); + c = utf_ptr2char((char *)mi.mi_fend); this_upper = SPELL_ISUPPER(c); 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) { // Check word starting with capital letter. - c = utf_ptr2char(ptr); + c = utf_ptr2char((char *)ptr); if (!SPELL_ISUPPER(c)) { 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) { // Always include at least one character. Required for when there // is a mixup in "midword". @@ -2023,8 +2023,8 @@ static int count_syllables(slang_T *slang, const char_u *word) skip = false; } else { // No recognized syllable item, at least a syllable char then? - c = utf_ptr2char(p); - len = utfc_ptr2len(p); + c = utf_ptr2char((char *)p); + len = utfc_ptr2len((char *)p); if (vim_strchr(slang->sl_syllable, c) == NULL) { skip = false; // No, search for next syllable } 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;) { - const int c = utf_ptr2char(p); - const int l = utfc_ptr2len(p); + const int c = utf_ptr2char((char *)p); + const int l = utfc_ptr2len((char *)p); if (c < 256 && l <= 2) { wp->w_s->b_spell_ismw[c] = true; } 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. for (; end == NULL ? *p != NUL : p < end; MB_PTR_ADV(p)) { if (spell_iswordp_nmw(p, curwin)) { - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); if (!SPELL_ISUPPER(c)) { // UUl -> KEEPCAP if (past_second && allcap) { @@ -2464,7 +2464,7 @@ static int badword_captype(char_u *word, char_u *end) l = u = 0; first = false; for (p = word; p < end; MB_PTR_ADV(p)) { - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); if (SPELL_ISUPPER(c)) { ++u; if (p == word) { @@ -2674,7 +2674,7 @@ static bool spell_iswordp(const char_u *p, const win_T *wp) { int c; - const int l = utfc_ptr2len(p); + const int l = utfc_ptr2len((char *)p); const char_u *s = p; if (l == 1) { // 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 } } else { - c = utf_ptr2char(p); + c = utf_ptr2char((char *)p); if (c < 256 ? wp->w_s->b_spell_ismw[c] : (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) { 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. 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) { 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 // word to be bad then it might need to be capitalised. Add a suggestion // for that. - c = utf_ptr2char(su->su_badptr); + c = utf_ptr2char((char *)su->su_badptr); if (!SPELL_ISUPPER(c) && attr == HLF_COUNT) { make_case_word(su->su_badword, buf, WF_ONECAP); 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; if ((c & WF_ALLCAP) && su->su_badlen == - utfc_ptr2len(su->su_badptr)) { + utfc_ptr2len((char *)su->su_badptr)) { c = WF_ONECAP; } c |= flags; @@ -4258,7 +4258,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && goodword_ends) { int l; - l = utfc_ptr2len(fword + sp->ts_fidx); + l = utfc_ptr2len((char *)fword + sp->ts_fidx); if (fword_ends) { // Copy the skipped character to preword. 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 // character (we didn't check that before). 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 // the score from SCORE_SUBST to // SCORE_SUBCOMP. - if (utf_iscomposing(utf_ptr2char(tword + sp->ts_twordlen + if (utf_iscomposing(utf_ptr2char((char *)tword + sp->ts_twordlen - sp->ts_tcharlen)) - && utf_iscomposing(utf_ptr2char(fword + && utf_iscomposing(utf_ptr2char((char *)fword + sp->ts_fcharstart))) { sp->ts_score -= SCORE_SUBST - SCORE_SUBCOMP; - } else if ( - !soundfold + } else if (!soundfold && slang->sl_has_map && similar_chars(slang, - utf_ptr2char(tword + sp->ts_twordlen - sp->ts_tcharlen), - utf_ptr2char(fword + sp->ts_fcharstart))) { + utf_ptr2char((char *)tword + sp->ts_twordlen - + sp->ts_tcharlen), + utf_ptr2char((char *)fword + sp->ts_fcharstart))) { // For a similar character adjust score from // SCORE_SUBST to 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 && 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)) { // Inserting a composing char doesn't // 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 // give better scores). MB_PTR_BACK(tword, p); - if (c == utf_ptr2char(p)) { + if (c == utf_ptr2char((char *)p)) { 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 // a bit illogical for soundfold tree but it does give better // results. - c = utf_ptr2char(fword + sp->ts_fidx); - stack[depth].ts_fidx += utfc_ptr2len(fword + sp->ts_fidx); + c = utf_ptr2char((char *)fword + sp->ts_fidx); + stack[depth].ts_fidx += utfc_ptr2len((char *)fword + sp->ts_fidx); if (utf_iscomposing(c)) { 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; } @@ -4610,14 +4610,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so break; } - n = utf_ptr2len(p); - c = utf_ptr2char(p); + n = utf_ptr2len((char *)p); + c = utf_ptr2char((char *)p); if (p[n] == NUL) { c2 = NUL; } else if (!soundfold && !spell_iswordp(p + n, curwin)) { c2 = c; // don't swap non-word char } else { - c2 = utf_ptr2char(p + n); + c2 = utf_ptr2char((char *)p + n); } // 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: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; - n = utfc_ptr2len(p); - c = utf_ptr2char(p + n); - memmove(p + utfc_ptr2len(p + n), p, n); + n = utfc_ptr2len((char *)p); + c = utf_ptr2char((char *)p + n); + memmove(p + utfc_ptr2len((char *)p + n), p, n); utf_char2bytes(c, p); 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 // "fword" here, it's changed back afterwards at STATE_UNSWAP3. p = fword + sp->ts_fidx; - n = utf_ptr2len(p); - c = utf_ptr2char(p); - fl = utf_ptr2len(p + n); - c2 = utf_ptr2char(p + n); + n = utf_ptr2len((char *)p); + c = utf_ptr2char((char *)p); + fl = utf_ptr2len((char *)p + n); + c2 = utf_ptr2char((char *)p + n); if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { c3 = c; // don't swap non-word char } else { - c3 = utf_ptr2char(p + n + fl); + c3 = utf_ptr2char((char *)p + n + fl); } // 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: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; - n = utfc_ptr2len(p); - c2 = utf_ptr2char(p + n); - fl = utfc_ptr2len(p + n); - c = utf_ptr2char(p + n + fl); - tl = utfc_ptr2len(p + n + fl); + n = utfc_ptr2len((char *)p); + c2 = utf_ptr2char((char *)p + n); + fl = utfc_ptr2len((char *)p + n); + c = utf_ptr2char((char *)p + n + fl); + tl = utfc_ptr2len((char *)p + n + fl); memmove(p + fl + tl, p, n); utf_char2bytes(c, p); 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; ++depth; p = fword + sp->ts_fidx; - n = utf_ptr2len(p); - c = utf_ptr2char(p); - fl = utf_ptr2len(p + n); - fl += utf_ptr2len(p + n + fl); + n = utf_ptr2len((char *)p); + c = utf_ptr2char((char *)p); + fl = utf_ptr2len((char *)p + n); + fl += utf_ptr2len((char *)p + n + fl); memmove(p, p + n, fl); utf_char2bytes(c, p + 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: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; - n = utfc_ptr2len(p); - n += utfc_ptr2len(p + n); - c = utf_ptr2char(p + n); - tl = utfc_ptr2len(p + n); + n = utfc_ptr2len((char *)p); + n += utfc_ptr2len((char *)p + n); + c = utf_ptr2char((char *)p + n); + tl = utfc_ptr2len((char *)p + n); memmove(p + tl, p, n); 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; ++depth; p = fword + sp->ts_fidx; - n = utf_ptr2len(p); - n += utf_ptr2len(p + n); - c = utf_ptr2char(p + n); - tl = utf_ptr2len(p + n); + n = utf_ptr2len((char *)p); + n += utf_ptr2len((char *)p + n); + c = utf_ptr2char((char *)p + n); + tl = utf_ptr2len((char *)p + n); memmove(p + tl, p, n); utf_char2bytes(c, p); 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: // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; - c = utf_ptr2char(p); - tl = utfc_ptr2len(p); - n = utfc_ptr2len(p + tl); - n += utfc_ptr2len(p + tl + n); + c = utf_ptr2char((char *)p); + tl = utfc_ptr2len((char *)p); + n = utfc_ptr2len((char *)p + tl); + n += utfc_ptr2len((char *)p + tl + n); memmove(p, p + tl, 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 { // round[depth] == 1: Try using the folded-case character. // round[depth] == 2: Try using the upper-case character. - flen = utf_ptr2len(fword + fwordidx[depth]); - ulen = utf_ptr2len(uword + uwordidx[depth]); + flen = utf_ptr2len((char *)fword + fwordidx[depth]); + ulen = utf_ptr2len((char *)uword + uwordidx[depth]); if (round[depth] == 1) { p = fword + fwordidx[depth]; l = flen; @@ -5516,9 +5516,9 @@ badword: // lower to upper case. Helps for "tath" -> "Kath", which is // less common than "tath" -> "path". Don't do it when the // letter is the same, that has already been counted. - gc = utf_ptr2char(p); + gc = utf_ptr2char((char *)p); if (SPELL_ISUPPER(gc)) { - bc = utf_ptr2char(su->su_badword); + bc = utf_ptr2char((char *)su->su_badword); if (!SPELL_ISUPPER(bc) && SPELL_TOFOLD(bc) != SPELL_TOFOLD(gc)) { goodscore += SCORE_ICASE / 2; @@ -5661,7 +5661,7 @@ static bool similar_chars(slang_T *slang, int c1, int c2) if (HASHITEM_EMPTY(hi)) { m1 = 0; } 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 { 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)) { m2 = 0; } 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 { 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(su->su_badptr, pbad); - if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { + if (utf_ptr2char((char *)pgood) != utf_ptr2char((char *)pbad)) { break; } } @@ -6940,7 +6940,7 @@ void spell_dump_compl(char_u *pat, int ic, Direction *dir, int dumpflags_arg) if (n == WF_ONECAP) { dumpflags |= DUMPFLAG_ONECAP; } else if (n == WF_ALLCAP - && (int)STRLEN(pat) > utfc_ptr2len(pat)) { + && (int)STRLEN(pat) > utfc_ptr2len((char *)pat)) { 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 // upper-case letter in word_up[]. - c = utf_ptr2char(word); + c = utf_ptr2char((char *)word); if (SPELL_TOUPPER(c) != c) { onecap_copy(word, word_up, true); has_word_up = true; diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c index c1b116e498..d4c0f389fb 100644 --- a/src/nvim/spellfile.c +++ b/src/nvim/spellfile.c @@ -2504,19 +2504,19 @@ static afffile_T *spell_read_aff(spellinfo_T *spin, char_u *fname) // be empty or start with the same letter. if (aff_entry->ae_chop != 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) { int c, c_up; - c = utf_ptr2char(aff_entry->ae_chop); + c = utf_ptr2char((char *)aff_entry->ae_chop); c_up = SPELL_TOUPPER(c); if (c_up != c && (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 + STRLEN(aff_entry->ae_add); MB_PTR_BACK(aff_entry->ae_add, p); - if (utf_ptr2char(p) == c_up) { + if (utf_ptr2char((char *)p) == c_up) { upper = true; aff_entry->ae_chop = NULL; *p = NUL; diff --git a/src/nvim/strings.c b/src/nvim/strings.c index a897228d6b..6582e6075a 100644 --- a/src/nvim/strings.c +++ b/src/nvim/strings.c @@ -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 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) { length += l; // count a multibyte char 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 *p2 = escaped_string; 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) { memcpy(p2, p, l); p2 += l; @@ -357,8 +357,8 @@ char *strcase_save(const char *const orig, bool upper) char *p = res; while (*p != NUL) { - int c = utf_ptr2char((const char_u *)p); - int l = utf_ptr2len((const char_u *)p); + int c = utf_ptr2char(p); + int l = utf_ptr2len(p); if (c == 0) { // overlong sequence, use only the first byte 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; size_t i; - for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len(p1)) { - size_t cell = (size_t)utf_ptr2cells(p1); + for (i = 0, p1 = (char_u *)str_arg; *p1; p1 += utfc_ptr2len((char *)p1)) { + size_t cell = (size_t)utf_ptr2cells((char *)p1); if (precision_specified && i + cell > precision) { break; } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 7afabdeb96..422e7150ab 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -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; int kwlen = 0; do { - kwlen += utfc_ptr2len(kwp + kwlen); + kwlen += utfc_ptr2len((char *)kwp + kwlen); } while (vim_iswordp_buf(kwp + kwlen, syn_buf)); 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] == '=') { // cchar=? - *conceal_char = utf_ptr2char(arg + 6); - arg += utfc_ptr2len(arg + 6) - 1; + *conceal_char = utf_ptr2char((char *)arg + 6); + arg += utfc_ptr2len((char *)arg + 6) - 1; if (!vim_isprintc_strict(*conceal_char)) { emsg(_("E844: invalid cchar value")); return NULL; @@ -4416,7 +4416,7 @@ static void syn_cmd_keyword(exarg_T *eap, int syncing) kw = p + 1; break; // skip over the "]" } - const int l = utfc_ptr2len(p + 1); + const int l = utfc_ptr2len((char *)p + 1); memmove(p, p + 1, l); p += l; diff --git a/src/nvim/tag.c b/src/nvim/tag.c index f2ba5d501c..b9203b4941 100644 --- a/src/nvim/tag.c +++ b/src/nvim/tag.c @@ -2583,7 +2583,7 @@ static int parse_match(char_u *lbuf, tagptrs_T *tagp) if (*p++ == TAB) { // Accept ASCII alphabetic kind characters and any multi-byte // character. - while (ASCII_ISALPHA(*p) || utfc_ptr2len(p) > 1) { + while (ASCII_ISALPHA(*p) || utfc_ptr2len((char *)p) > 1) { if (STRNCMP(p, "kind:", 5) == 0) { tagp->tagkind = p + 5; } else if (STRNCMP(p, "user_data:", 10) == 0) { diff --git a/src/nvim/terminal.c b/src/nvim/terminal.c index 385b55e545..1f763c3e1e 100644 --- a/src/nvim/terminal.c +++ b/src/nvim/terminal.c @@ -673,8 +673,8 @@ void terminal_paste(long count, char_u **y_array, size_t y_size) char_u *dst = buff; char_u *src = y_array[j]; while (*src != '\0') { - len = (size_t)utf_ptr2len(src); - int c = utf_ptr2char(src); + len = (size_t)utf_ptr2len((char *)src); + int c = utf_ptr2char((char *)src); if (!is_filter_char(c)) { memcpy(dst, src, len); dst += len; diff --git a/src/nvim/testing.c b/src/nvim/testing.c index 07e1fe424b..9207ebe73b 100644 --- a/src/nvim/testing.c +++ b/src/nvim/testing.c @@ -90,7 +90,7 @@ static void ga_concat_shorten_esc(garray_T *gap, const char_u *str) const char_u *s = p; const int c = mb_ptr2char_adv(&s); const int clen = (int)(s - p); - while (*s != NUL && c == utf_ptr2char(s)) { + while (*s != NUL && c == utf_ptr2char((char *)s)) { same_len++; s += clen; } diff --git a/src/nvim/version.c b/src/nvim/version.c index fb718d3882..2369681dca 100644 --- a/src/nvim/version.c +++ b/src/nvim/version.c @@ -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] != '>')); 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); grid_puts_len(&default_grid, p, l, (int)row, (int)col, diff --git a/src/nvim/window.c b/src/nvim/window.c index 887df31650..9cf1e3eca1 100644 --- a/src/nvim/window.c +++ b/src/nvim/window.c @@ -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 "\ ". ++len; } - len += (size_t)(utfc_ptr2len(ptr + len)); + len += (size_t)(utfc_ptr2len((char *)ptr + len)); } /* |