refactor: replace char_u with char

Work on https://github.com/neovim/neovim/issues/459
This commit is contained in:
dundargoc 2022-11-26 18:57:46 +01:00 committed by zeertzjq
parent 53adccb6e0
commit 08c2c74806
21 changed files with 135 additions and 136 deletions

View File

@ -1721,7 +1721,7 @@ bool rem_backslash(const char *str)
|| (str[1] != NUL
&& str[1] != '*'
&& str[1] != '?'
&& !vim_isfilec(str[1])));
&& !vim_isfilec((uint8_t)str[1])));
#else // ifdef BACKSLASH_IN_FILENAME
return str[0] == '\\' && str[1] != NUL;

View File

@ -370,7 +370,7 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m
char_u *selend = NULL;
static int first_match = 0;
bool add_left = false;
char_u *s;
char *s;
int emenu;
int l;
@ -444,25 +444,25 @@ static void redraw_wildmenu(expand_T *xp, int num_matches, char **matches, int m
selstart_col = clen;
}
s = (char_u *)L_MATCH(i);
s = L_MATCH(i);
// Check for menu separators - replace with '|'
emenu = (xp->xp_context == EXPAND_MENUS
|| xp->xp_context == EXPAND_MENUNAMES);
if (emenu && menu_is_separator((char *)s)) {
if (emenu && menu_is_separator(s)) {
STRCPY(buf + len, transchar('|'));
l = (int)strlen((char *)buf + len);
len += l;
clen += l;
} else {
for (; *s != NUL; s++) {
s += skip_wildmenu_char(xp, s);
clen += ptr2cells((char *)s);
if ((l = utfc_ptr2len((char *)s)) > 1) {
strncpy((char *)buf + len, (char *)s, (size_t)l); // NOLINT(runtime/printf)
s += skip_wildmenu_char(xp, (char_u *)s);
clen += ptr2cells(s);
if ((l = utfc_ptr2len(s)) > 1) {
strncpy((char *)buf + len, s, (size_t)l); // NOLINT(runtime/printf)
s += l - 1;
len += l;
} else {
STRCPY(buf + len, transchar_byte(*s));
STRCPY(buf + len, transchar_byte((uint8_t)(*s)));
len += (int)strlen((char *)buf + len);
}
}

View File

@ -137,39 +137,39 @@ static void margin_columns_win(win_T *wp, int *left_col, int *right_col)
/// Handles composing chars and arabic shaping state.
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((char *)p);
int c_len = utfc_ptr2len((char *)p);
const char *p = s->p;
int cells = utf_ptr2cells(p);
int c_len = utfc_ptr2len(p);
int u8c, u8cc[MAX_MCO];
if (cells > maxcells) {
return -1;
}
u8c = utfc_ptr2char((char *)p, u8cc);
u8c = utfc_ptr2char(p, u8cc);
if (*p == TAB) {
cells = MIN(tabstop_padding(vcol, buf->b_p_ts, buf->b_p_vts_array), maxcells);
for (int c = 0; c < cells; c++) {
schar_from_ascii(dest[c], ' ');
}
goto done;
} else if (*p < 0x80 && u8cc[0] == 0) {
schar_from_ascii(dest[0], (char)(*p));
} else if ((uint8_t)(*p) < 0x80 && u8cc[0] == 0) {
schar_from_ascii(dest[0], *p);
s->prev_c = u8c;
} else {
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) {
// Do Arabic shaping.
int pc, pc1, nc;
int pcc[MAX_MCO];
int firstbyte = *p;
int firstbyte = (uint8_t)(*p);
// The idea of what is the previous and next
// character depends on 'rightleft'.
if (rl) {
pc = s->prev_c;
pc1 = s->prev_c1;
nc = utf_ptr2char((char *)p + c_len);
nc = utf_ptr2char(p + c_len);
s->prev_c1 = u8cc[0];
} else {
pc = utfc_ptr2char((char *)p + c_len, pcc);
pc = utfc_ptr2char(p + c_len, pcc);
nc = s->prev_c;
pc1 = pcc[0];
}

View File

@ -2124,11 +2124,11 @@ void insertchar(int c, int flags, int second_indent)
&& !cindent_on()
&& !p_ri) {
#define INPUT_BUFLEN 100
char_u buf[INPUT_BUFLEN + 1];
char buf[INPUT_BUFLEN + 1];
int i;
colnr_T virtcol = 0;
buf[0] = (char_u)c;
buf[0] = (char)c;
i = 1;
if (textwidth > 0) {
virtcol = get_nolist_virtcol();
@ -2144,27 +2144,27 @@ void insertchar(int c, int flags, int second_indent)
&& MB_BYTE2LEN(c) == 1
&& i < INPUT_BUFLEN
&& (textwidth == 0
|| (virtcol += byte2cells(buf[i - 1])) < (colnr_T)textwidth)
&& !(!no_abbr && !vim_iswordc(c) && vim_iswordc(buf[i - 1]))) {
|| (virtcol += byte2cells((uint8_t)buf[i - 1])) < (colnr_T)textwidth)
&& !(!no_abbr && !vim_iswordc(c) && vim_iswordc((uint8_t)buf[i - 1]))) {
c = vgetc();
if (p_hkmap && KeyTyped) {
c = hkmap(c); // Hebrew mode mapping
}
buf[i++] = (char_u)c;
buf[i++] = (char)c;
}
do_digraph(-1); // clear digraphs
do_digraph(buf[i - 1]); // may be the start of a digraph
do_digraph((uint8_t)buf[i - 1]); // may be the start of a digraph
buf[i] = NUL;
ins_str((char *)buf);
ins_str(buf);
if (flags & INSCHAR_CTRLV) {
redo_literal(*buf);
redo_literal((uint8_t)(*buf));
i = 1;
} else {
i = 0;
}
if (buf[i] != NUL) {
AppendToRedobuffLit((char *)buf + i, -1);
AppendToRedobuffLit(buf + i, -1);
}
} else {
int cc;
@ -2172,7 +2172,7 @@ void insertchar(int c, int flags, int second_indent)
if ((cc = utf_char2len(c)) > 1) {
char buf[MB_MAXBYTES + 1];
utf_char2bytes(c, (char *)buf);
utf_char2bytes(c, buf);
buf[cc] = NUL;
ins_char_bytes(buf, (size_t)cc);
AppendCharToRedobuff(c);

View File

@ -6273,7 +6273,7 @@ int list2fpos(typval_T *arg, pos_T *posp, int *fnump, colnr_T *curswantp, bool c
int get_env_len(const char **arg)
{
const char *p;
for (p = *arg; vim_isIDc(*p); p++) {}
for (p = *arg; vim_isIDc((uint8_t)(*p)); p++) {}
if (p == *arg) { // No name found.
return 0;
}

View File

@ -4692,7 +4692,7 @@ char *skip_vimgrep_pat(char *p, char **s, int *flags)
{
int c;
if (vim_isIDc(*p)) {
if (vim_isIDc((uint8_t)(*p))) {
// ":vimgrep pattern fname"
if (s != NULL) {
*s = p;

View File

@ -324,7 +324,7 @@ static bool do_incsearch_highlighting(int firstc, int *search_delim, incsearch_s
}
p = skipwhite(p);
delim = (delim_optional && vim_isIDc(*p)) ? ' ' : *p++;
delim = (delim_optional && vim_isIDc((uint8_t)(*p))) ? ' ' : *p++;
*search_delim = delim;
end = skip_regexp_ex(p, delim, magic_isset(), NULL, NULL, &magic);
@ -1462,7 +1462,7 @@ static int command_line_erase_chars(CommandLineState *s)
if (s->c == K_DEL) {
ccline.cmdpos += mb_off_next((char_u *)ccline.cmdbuff,
(char_u *)ccline.cmdbuff + ccline.cmdpos);
ccline.cmdbuff + ccline.cmdpos);
}
if (ccline.cmdpos > 0) {
@ -3232,7 +3232,7 @@ static void draw_cmdline(int start, int len)
for (int i = start; i < start + len; i += mb_l) {
char_u *p = (char_u *)ccline.cmdbuff + i;
int u8cc[MAX_MCO];
int u8c = utfc_ptr2char_len(p, u8cc, start + len - i);
int u8c = utfc_ptr2char_len((char *)p, u8cc, start + len - i);
mb_l = utfc_ptr2len_len((char *)p, start + len - i);
if (ARABIC_CHAR(u8c)) {
do_arabicshape = true;
@ -3268,7 +3268,7 @@ static void draw_cmdline(int start, int len)
for (int i = start; i < start + len; i += mb_l) {
char_u *p = (char_u *)ccline.cmdbuff + i;
int u8cc[MAX_MCO];
int u8c = utfc_ptr2char_len(p, u8cc, start + len - i);
int u8c = utfc_ptr2char_len((char *)p, u8cc, start + len - i);
mb_l = utfc_ptr2len_len((char *)p, start + len - i);
if (ARABIC_CHAR(u8c)) {
int pc;
@ -3292,7 +3292,7 @@ static void draw_cmdline(int start, int len)
} else {
int pcc[MAX_MCO];
pc = utfc_ptr2char_len(p + mb_l, pcc, start + len - i - mb_l);
pc = utfc_ptr2char_len((char *)p + mb_l, pcc, start + len - i - mb_l);
pc1 = pcc[0];
}
nc = prev_c;
@ -3956,7 +3956,7 @@ char *vim_strsave_fnameescape(const char *const fname, const int what)
// ":buffer" command.
for (const char *p = what == VSE_BUFFER ? BUFFER_ESC_CHARS : PATH_ESC_CHARS;
*p != NUL; p++) {
if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec(*p)) {
if ((*p != '[' && *p != '{' && *p != '!') || !vim_isfilec((uint8_t)(*p))) {
buf[j++] = *p;
}
}

View File

@ -5635,7 +5635,7 @@ char *file_pat_to_reg_pat(const char *pat, const char *pat_end, char *allow_dirs
// "\*" to "\\.*" e.g., "dir\*.c"
// "\?" to "\\." e.g., "dir\??.c"
// "\+" to "\+" e.g., "fileX\+.c"
if ((vim_isfilec(p[1]) || p[1] == '*' || p[1] == '?')
if ((vim_isfilec((uint8_t)p[1]) || p[1] == '*' || p[1] == '?')
&& p[1] != '+') {
reg_pat[i++] = '[';
reg_pat[i++] = '\\';

View File

@ -253,7 +253,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
? utfc_ptr2len_len(ptr, (int)((text + len) - ptr))
: utfc_ptr2len(ptr);
u8c = len >= 0
? utfc_ptr2char_len((char_u *)ptr, u8cc, (int)((text + len) - ptr))
? utfc_ptr2char_len(ptr, u8cc, (int)((text + len) - ptr))
: utfc_ptr2char(ptr, u8cc);
mbyte_cells = utf_char2cells(u8c);
if (p_arshape && !p_tbidi && ARABIC_CHAR(u8c)) {
@ -264,7 +264,7 @@ void grid_puts_len(ScreenGrid *grid, char *text, int textlen, int row, int col,
nc1 = NUL;
} else {
nc = len >= 0
? utfc_ptr2char_len((char_u *)ptr + mbyte_blen, pcc,
? utfc_ptr2char_len(ptr + mbyte_blen, pcc,
(int)((text + len) - ptr - mbyte_blen))
: utfc_ptr2char(ptr + mbyte_blen, pcc);
nc1 = pcc[0];

View File

@ -219,7 +219,7 @@ bool cin_is_cinword(const char *line)
for (char *cinw = curbuf->b_p_cinw; *cinw;) {
size_t len = copy_option_part(&cinw, cinw_buf, cinw_len, ",");
if (strncmp(line, cinw_buf, len) == 0
&& (!vim_iswordc(line[len]) || !vim_iswordc(line[len - 1]))) {
&& (!vim_iswordc((uint8_t)line[len]) || !vim_iswordc((uint8_t)line[len - 1]))) {
retval = true;
break;
}
@ -298,26 +298,26 @@ static pos_T *find_line_comment(void) // XXX
/// Checks if `text` starts with "key:".
static bool cin_has_js_key(const char_u *text)
{
const char_u *s = (char_u *)skipwhite((char *)text);
const char *s = skipwhite((char *)text);
char_u quote = 0;
char quote = 0;
if (*s == '\'' || *s == '"') {
// can be 'key': or "key":
quote = *s;
s++;
}
if (!vim_isIDc(*s)) { // need at least one ID character
if (!vim_isIDc((uint8_t)(*s))) { // need at least one ID character
return false;
}
while (vim_isIDc(*s)) {
while (vim_isIDc((uint8_t)(*s))) {
s++;
}
if (*s && *s == quote) {
s++;
}
s = cin_skipcomment(s);
s = (char *)cin_skipcomment((char_u *)s);
// "::" is not a label, it's C++
return (*s == ':' && s[1] != ':');
@ -325,18 +325,18 @@ static bool cin_has_js_key(const char_u *text)
/// Checks if string matches "label:"; move to character after ':' if true.
/// "*s" must point to the start of the label, if there is one.
static bool cin_islabel_skip(const char_u **s)
static bool cin_islabel_skip(const char **s)
FUNC_ATTR_NONNULL_ALL
{
if (!vim_isIDc(**s)) { // need at least one ID character
if (!vim_isIDc((uint8_t)(**s))) { // need at least one ID character
return false;
}
while (vim_isIDc(**s)) {
while (vim_isIDc((uint8_t)(**s))) {
(*s)++;
}
*s = cin_skipcomment(*s);
*s = (char *)cin_skipcomment((char_u *)(*s));
// "::" is not a label, it's C++
return **s == ':' && *++*s != ':';
@ -346,14 +346,14 @@ static bool cin_islabel_skip(const char_u **s)
// Note: curwin->w_cursor must be where we are looking for the label.
bool cin_islabel(void) // XXX
{
const char_u *s = cin_skipcomment((char_u *)get_cursor_line_ptr());
const char *s = (char *)cin_skipcomment((char_u *)get_cursor_line_ptr());
// Exclude "default" from labels, since it should be indented
// like a switch label. Same for C++ scope declarations.
if (cin_isdefault((char *)s)) {
return false;
}
if (cin_isscopedecl(s)) {
if (cin_isscopedecl((char_u *)s)) {
return false;
}
if (!cin_islabel_skip(&s)) {
@ -364,7 +364,7 @@ bool cin_islabel(void) // XXX
// label.
pos_T cursor_save;
pos_T *trypos;
const char_u *line;
const char *line;
cursor_save = curwin->w_cursor;
while (curwin->w_cursor.lnum > 1) {
@ -377,19 +377,19 @@ bool cin_islabel(void) // XXX
curwin->w_cursor = *trypos;
}
line = (char_u *)get_cursor_line_ptr();
if (cin_ispreproc(line)) { // ignore #defines, #if, etc.
line = get_cursor_line_ptr();
if (cin_ispreproc((char_u *)line)) { // ignore #defines, #if, etc.
continue;
}
if (*(line = cin_skipcomment(line)) == NUL) {
if (*(line = (char *)cin_skipcomment((char_u *)line)) == NUL) {
continue;
}
curwin->w_cursor = cursor_save;
if (cin_isterminated(line, true, false)
|| cin_isscopedecl(line)
|| cin_iscase(line, true)
|| (cin_islabel_skip(&line) && cin_nocode(line))) {
if (cin_isterminated((char_u *)line, true, false)
|| cin_isscopedecl((char_u *)line)
|| cin_iscase((char_u *)line, true)
|| (cin_islabel_skip(&line) && cin_nocode((char_u *)line))) {
return true;
}
return false;
@ -519,7 +519,7 @@ bool cin_isscopedecl(const char_u *p)
// Recognize a "namespace" scope declaration.
static bool cin_is_cpp_namespace(const char *s)
{
const char_u *p;
const char *p;
bool has_name = false;
bool has_name_start = false;
@ -530,20 +530,20 @@ static bool cin_is_cpp_namespace(const char *s)
}
if (strncmp(s, "namespace", 9) == 0 && (s[9] == NUL || !vim_iswordc((uint8_t)s[9]))) {
p = cin_skipcomment((char_u *)skipwhite((char *)s + 9));
p = (char *)cin_skipcomment((char_u *)skipwhite((char *)s + 9));
while (*p != NUL) {
if (ascii_iswhite(*p)) {
has_name = true; // found end of a name
p = cin_skipcomment((char_u *)skipwhite((char *)p));
p = (char *)cin_skipcomment((char_u *)skipwhite((char *)p));
} else if (*p == '{') {
break;
} else if (vim_iswordc(*p)) {
} else if (vim_iswordc((uint8_t)(*p))) {
has_name_start = true;
if (has_name) {
return false; // word character after skipping past name
}
p++;
} else if (p[0] == ':' && p[1] == ':' && vim_iswordc(p[2])) {
} else if (p[0] == ':' && p[1] == ':' && vim_iswordc((uint8_t)p[2])) {
if (!has_name_start || has_name) {
return false;
}
@ -669,7 +669,7 @@ static int cin_first_id_amount(void)
p = s;
}
}
for (len = 0; vim_isIDc(p[len]); len++) {}
for (len = 0; vim_isIDc((uint8_t)p[len]); len++) {}
if (len == 0 || !ascii_iswhite(p[len]) || cin_nocode((char_u *)p)) {
return 0;
}

View File

@ -1400,15 +1400,15 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir,
int status = OK;
// Add the other matches on the line
char_u *ptr = *buf_arg;
char *ptr = (char *)(*buf_arg);
while (!got_int) {
// Find start of the next word. Skip white
// space and punctuation.
ptr = find_word_start(ptr);
ptr = (char *)find_word_start((char_u *)ptr);
if (*ptr == NUL || *ptr == NL) {
break;
}
char_u *wstart = ptr;
char_u *wstart = (char_u *)ptr;
// Find end of the word.
// Japanese words may have characters in
@ -1417,7 +1417,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir,
while (*ptr != NUL) {
const int l = utfc_ptr2len((const char *)ptr);
if (l < 2 && !vim_iswordc(*ptr)) {
if (l < 2 && !vim_iswordc((uint8_t)(*ptr))) {
break;
}
ptr += l;
@ -1425,7 +1425,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir,
// Add the word. Skip the regexp match.
if (wstart != skip_word) {
status = ins_compl_add_infercase(wstart, (int)(ptr - wstart), p_ic,
status = ins_compl_add_infercase(wstart, (int)(ptr - (char *)wstart), p_ic,
(char_u *)fname, dir, false);
if (status == FAIL) {
break;
@ -1433,7 +1433,7 @@ static int thesaurus_add_words_in_line(char *fname, char_u **buf_arg, int dir,
}
}
*buf_arg = ptr;
*buf_arg = (char_u *)ptr;
return status;
}
@ -3819,7 +3819,7 @@ static int get_normal_compl_info(char *line, int startcol, colnr_T curs_col)
{
if ((compl_cont_status & CONT_SOL) || ctrl_x_mode_path_defines()) {
if (!compl_status_adding()) {
while (--startcol >= 0 && vim_isIDc(line[startcol])) {}
while (--startcol >= 0 && vim_isIDc((uint8_t)line[startcol])) {}
compl_col += ++startcol;
compl_length = curs_col - startcol;
}

View File

@ -55,7 +55,7 @@ static const struct modmasktable {
#define MOD_KEYS_ENTRY_SIZE 5
static char_u modifier_keys_table[] = {
static uint8_t modifier_keys_table[] = {
// mod mask with modifier without modifier
MOD_MASK_SHIFT, '&', '9', '@', '1', // begin
MOD_MASK_SHIFT, '&', '0', '@', '2', // cancel

View File

@ -427,22 +427,22 @@ void remove_bom(char_u *s)
int mb_get_class(const char_u *p)
FUNC_ATTR_PURE
{
return mb_get_class_tab(p, curbuf->b_chartab);
return mb_get_class_tab((char *)p, curbuf->b_chartab);
}
int mb_get_class_tab(const char_u *p, const uint64_t *const chartab)
int mb_get_class_tab(const char *p, const uint64_t *const chartab)
FUNC_ATTR_PURE
{
if (MB_BYTE2LEN(p[0]) == 1) {
if (MB_BYTE2LEN((uint8_t)p[0]) == 1) {
if (p[0] == NUL || ascii_iswhite(p[0])) {
return 0;
}
if (vim_iswordc_tab(p[0], chartab)) {
if (vim_iswordc_tab((uint8_t)p[0], chartab)) {
return 2;
}
return 1;
}
return utf_class_tab(utf_ptr2char((char *)p), chartab);
return utf_class_tab(utf_ptr2char(p), chartab);
}
// Return true if "c" is in "table".
@ -534,13 +534,13 @@ int utf_ptr2cells(const char *p)
/// Like utf_ptr2cells(), but limit string length to "size".
/// For an empty string or truncated character returns 1.
int utf_ptr2cells_len(const char_u *p, int size)
int utf_ptr2cells_len(const char *p, int size)
{
int c;
// Need to convert to a wide character.
if (size > 0 && *p >= 0x80) {
if (utf_ptr2len_len(p, size) < utf8len_tab[*p]) {
if (size > 0 && (uint8_t)(*p) >= 0x80) {
if (utf_ptr2len_len((char_u *)p, size) < utf8len_tab[(uint8_t)(*p)]) {
return 1; // truncated
}
c = utf_ptr2char((char *)p);
@ -599,7 +599,7 @@ size_t mb_string2cells_len(const char *str, size_t size)
/// For an overlong sequence this may return zero.
/// Does not include composing characters for obvious reasons.
///
/// @param[in] p String to convert.
/// @param[in] p_in String to convert.
///
/// @return Unicode codepoint or byte value.
int utf_ptr2char(const char *const p_in)
@ -744,26 +744,25 @@ bool utf_composinglike(const char *p1, const char *p2)
/// space at least for #MAX_MCO + 1 elements.
///
/// @return leading character.
int utfc_ptr2char(const char *p_in, int *pcc)
int utfc_ptr2char(const char *p, int *pcc)
{
uint8_t *p = (uint8_t *)p_in;
int i = 0;
int c = utf_ptr2char((char *)p);
int len = utf_ptr2len((char *)p);
int c = utf_ptr2char(p);
int len = utf_ptr2len(p);
// Only accept a composing char when the first char isn't illegal.
if ((len > 1 || *p < 0x80)
&& p[len] >= 0x80
&& utf_composinglike((char *)p, (char *)p + len)) {
int cc = utf_ptr2char((char *)p + len);
if ((len > 1 || (uint8_t)(*p) < 0x80)
&& (uint8_t)p[len] >= 0x80
&& utf_composinglike(p, p + len)) {
int cc = utf_ptr2char(p + len);
for (;;) {
pcc[i++] = cc;
if (i == MAX_MCO) {
break;
}
len += utf_ptr2len((char *)p + len);
if (p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char((char *)p + len))) {
len += utf_ptr2len(p + len);
if ((uint8_t)p[len] < 0x80 || !utf_iscomposing(cc = utf_ptr2char(p + len))) {
break;
}
}
@ -780,24 +779,24 @@ int utfc_ptr2char(const char *p_in, int *pcc)
// composing characters. Use no more than p[maxlen].
//
// @param [out] pcc: composing chars, last one is 0
int utfc_ptr2char_len(const char_u *p, int *pcc, int maxlen)
int utfc_ptr2char_len(const char *p, int *pcc, int maxlen)
{
assert(maxlen > 0);
int i = 0;
int len = utf_ptr2len_len(p, maxlen);
int len = utf_ptr2len_len((char_u *)p, maxlen);
// Is it safe to use utf_ptr2char()?
bool safe = len > 1 && len <= maxlen;
int c = safe ? utf_ptr2char((char *)p) : *p;
int c = safe ? utf_ptr2char(p) : (uint8_t)(*p);
// Only accept a composing char when the first char isn't illegal.
if ((safe || c < 0x80) && len < maxlen && p[len] >= 0x80) {
if ((safe || c < 0x80) && len < maxlen && (uint8_t)p[len] >= 0x80) {
for (; i < MAX_MCO; i++) {
int len_cc = utf_ptr2len_len(p + len, maxlen - len);
int len_cc = utf_ptr2len_len((char_u *)p + len, maxlen - len);
safe = len_cc > 1 && len_cc <= maxlen - len;
if (!safe || (pcc[i] = utf_ptr2char((char *)p + len)) < 0x80
|| !(i == 0 ? utf_composinglike((char *)p, (char *)p + len) : utf_iscomposing(pcc[i]))) {
if (!safe || (pcc[i] = utf_ptr2char(p + len)) < 0x80
|| !(i == 0 ? utf_composinglike(p, p + len) : utf_iscomposing(pcc[i]))) {
break;
}
len += len_cc;
@ -875,21 +874,20 @@ 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.
/// Returns zero for NUL.
int utfc_ptr2len(const char *const p_in)
int utfc_ptr2len(const char *const p)
FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT FUNC_ATTR_NONNULL_ALL
{
uint8_t *p = (uint8_t *)p_in;
uint8_t b0 = *p;
uint8_t b0 = (uint8_t)(*p);
if (b0 == NUL) {
return 0;
}
if (b0 < 0x80 && p[1] < 0x80) { // be quick for ASCII
if (b0 < 0x80 && (uint8_t)p[1] < 0x80) { // be quick for ASCII
return 1;
}
// Skip over first UTF-8 char, stopping at a NUL byte.
int len = utf_ptr2len((char *)p);
int len = utf_ptr2len(p);
// Check for illegal byte.
if (len == 1 && b0 >= 0x80) {
@ -900,13 +898,13 @@ int utfc_ptr2len(const char *const p_in)
// skip all of them (otherwise the cursor would get stuck).
int prevlen = 0;
for (;;) {
if (p[len] < 0x80 || !utf_composinglike((char *)p + prevlen, (char *)p + len)) {
if ((uint8_t)p[len] < 0x80 || !utf_composinglike(p + prevlen, p + len)) {
return len;
}
// Skip over composing char.
prevlen = len;
len += utf_ptr2len((char *)p + len);
len += utf_ptr2len(p + len);
}
}
@ -1786,11 +1784,12 @@ void mb_copy_char(const char **const fp, char **const tp)
*fp += l;
}
/// Return the offset from "p" to the first byte of a character. When "p" is
/// Return the offset from "p_in" to the first byte of a character. When "p_in" is
/// at the start of a character 0 is returned, otherwise the offset to the next
/// character. Can start anywhere in a stream of bytes.
int mb_off_next(const char_u *base, const char_u *p)
int mb_off_next(const char_u *base, const char *p_in)
{
const uint8_t *p = (uint8_t *)p_in;
int i;
int j;
@ -1882,7 +1881,7 @@ int utf_cp_head_off(const char_u *base, const char_u *p)
void utf_find_illegal(void)
{
pos_T pos = curwin->w_cursor;
char_u *p;
char *p;
int len;
vimconv_T vimconv;
char_u *tofree = NULL;
@ -1897,30 +1896,29 @@ void utf_find_illegal(void)
curwin->w_cursor.coladd = 0;
for (;;) {
p = (char_u *)get_cursor_pos_ptr();
p = get_cursor_pos_ptr();
if (vimconv.vc_type != CONV_NONE) {
xfree(tofree);
tofree = (char_u *)string_convert(&vimconv, (char *)p, NULL);
tofree = (char_u *)string_convert(&vimconv, p, NULL);
if (tofree == NULL) {
break;
}
p = tofree;
p = (char *)tofree;
}
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((char *)p);
if (*p >= 0x80 && (len == 1
|| utf_char2len(utf_ptr2char((char *)p)) != len)) {
len = utf_ptr2len(p);
if ((uint8_t)(*p) >= 0x80 && (len == 1 || utf_char2len(utf_ptr2char(p)) != len)) {
if (vimconv.vc_type == CONV_NONE) {
curwin->w_cursor.col += (colnr_T)(p - (char_u *)get_cursor_pos_ptr());
curwin->w_cursor.col += (colnr_T)(p - get_cursor_pos_ptr());
} else {
int l;
len = (int)(p - tofree);
for (p = (char_u *)get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
l = utf_ptr2len((char *)p);
len = (int)(p - (char *)tofree);
for (p = get_cursor_pos_ptr(); *p != NUL && len-- > 0; p += l) {
l = utf_ptr2len(p);
curwin->w_cursor.col += l;
}
}

View File

@ -1530,7 +1530,7 @@ char *msg_outtrans_one(char *p, int attr)
msg_outtrans_len_attr(p, l, attr);
return p + l;
}
msg_puts_attr((const char *)transchar_byte(*p), attr);
msg_puts_attr((const char *)transchar_byte((uint8_t)(*p)), attr);
return p + 1;
}

View File

@ -889,7 +889,7 @@ static int do_set_string(int opt_idx, int opt_flags, char **argp, int nextchar,
if (*arg == '\\' && arg[1] != NUL
#ifdef BACKSLASH_IN_FILENAME
&& !((flags & P_EXPAND)
&& vim_isfilec(arg[1])
&& vim_isfilec((uint8_t)arg[1])
&& !ascii_iswhite(arg[1])
&& (arg[1] != '\\'
|| (s == newval && arg[2] != '\\')))
@ -4752,7 +4752,7 @@ int ExpandSettings(expand_T *xp, regmatch_T *regmatch, int *num_file, char ***fi
void ExpandOldSetting(int *num_file, char ***file)
{
char_u *var = NULL;
char *var = NULL;
*num_file = 0;
*file = xmalloc(sizeof(char_u *));
@ -4765,14 +4765,14 @@ void ExpandOldSetting(int *num_file, char ***file)
if (expand_option_idx >= 0) {
// Put string of option value in NameBuff.
option_value2string(&options[expand_option_idx], expand_option_flags);
var = (char_u *)NameBuff;
var = NameBuff;
} else {
var = (char_u *)"";
var = "";
}
// A backslash is required before some characters. This is the reverse of
// what happens in do_set().
char_u *buf = vim_strsave_escaped(var, escape_chars);
char_u *buf = vim_strsave_escaped((char_u *)var, escape_chars);
#ifdef BACKSLASH_IN_FILENAME
// For MS-Windows et al. we don't double backslashes at the start and
@ -4781,7 +4781,7 @@ void ExpandOldSetting(int *num_file, char ***file)
if (var[0] == '\\' && var[1] == '\\'
&& expand_option_idx >= 0
&& (options[expand_option_idx].flags & P_EXPAND)
&& vim_isfilec(var[2])
&& vim_isfilec((uint8_t)var[2])
&& (var[2] != '\\' || (var == buf && var[4] != '\\'))) {
STRMOVE(var, var + 1);
}

View File

@ -1034,7 +1034,7 @@ char *did_set_string_option(int opt_idx, char **varp, char *oldval, char *errbuf
if (errbuf != NULL) {
vim_snprintf(errbuf, errbuflen,
_("E526: Missing number after <%s>"),
transchar_byte(*(s - 1)));
transchar_byte((uint8_t)(*(s - 1))));
errmsg = errbuf;
} else {
errmsg = "";

View File

@ -634,7 +634,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
} else // NOLINT
#endif
{
while (c-- > 0 && *tail != NUL && vim_isIDc(*tail)) {
while (c-- > 0 && *tail != NUL && vim_isIDc((uint8_t)(*tail))) {
*var++ = *tail++;
}
}
@ -667,7 +667,7 @@ void expand_env_esc(char *restrict srcp, char *restrict dst, int dstlen, bool es
int c = dstlen - 1;
while (c-- > 0
&& *tail
&& vim_isfilec(*tail)
&& vim_isfilec((uint8_t)(*tail))
&& !vim_ispathsep(*tail)) {
*var++ = *tail++;
}

View File

@ -1077,7 +1077,8 @@ void unref_extmatch(reg_extmatch_T *em)
static int reg_prev_class(void)
{
if (rex.input > rex.line) {
return mb_get_class_tab(rex.input - 1 - utf_head_off((char *)rex.line, (char *)rex.input - 1),
return mb_get_class_tab((char *)rex.input - 1 -
utf_head_off((char *)rex.line, (char *)rex.input - 1),
rex.reg_buf->b_chartab);
}
return -1;

View File

@ -3716,7 +3716,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
} else {
// Get class of current and previous char (if it exists).
const int this_class =
mb_get_class_tab(rex.input, rex.reg_buf->b_chartab);
mb_get_class_tab((char *)rex.input, rex.reg_buf->b_chartab);
if (this_class <= 1) {
status = RA_NOMATCH; // Not on a word at all.
} else if (reg_prev_class() == this_class) {
@ -3732,7 +3732,7 @@ static bool regmatch(char_u *scan, proftime_T *tm, int *timed_out)
int this_class, prev_class;
// Get class of current and previous char (if it exists).
this_class = mb_get_class_tab(rex.input, rex.reg_buf->b_chartab);
this_class = mb_get_class_tab((char *)rex.input, rex.reg_buf->b_chartab);
prev_class = reg_prev_class();
if (this_class == prev_class
|| prev_class == 0 || prev_class == 1) {

View File

@ -6341,7 +6341,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
int this_class;
// Get class of current and previous char (if it exists).
this_class = mb_get_class_tab(rex.input, rex.reg_buf->b_chartab);
this_class = mb_get_class_tab((char *)rex.input, rex.reg_buf->b_chartab);
if (this_class <= 1) {
result = false;
} else if (reg_prev_class() == this_class) {
@ -6362,7 +6362,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, regsubs_T *subm
int this_class, prev_class;
// Get class of current and previous char (if it exists).
this_class = mb_get_class_tab(rex.input, rex.reg_buf->b_chartab);
this_class = mb_get_class_tab((char *)rex.input, rex.reg_buf->b_chartab);
prev_class = reg_prev_class();
if (this_class == prev_class
|| prev_class == 0 || prev_class == 1) {

View File

@ -3604,8 +3604,8 @@ bool valid_spelllang(const char *val)
bool valid_spellfile(const char *val)
FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE FUNC_ATTR_WARN_UNUSED_RESULT
{
for (const char_u *s = (char_u *)val; *s != NUL; s++) {
if (!vim_isfilec(*s) && *s != ',' && *s != ' ') {
for (const char *s = val; *s != NUL; s++) {
if (!vim_isfilec((uint8_t)(*s)) && *s != ',' && *s != ' ') {
return false;
}
}