refactor(multibyte): eliminate mb_char2len alias for utf_char2len

This commit is contained in:
Björn Linse
2021-11-14 12:48:42 +01:00
parent 0039ba04b0
commit 71a4d275dc
10 changed files with 25 additions and 28 deletions

View File

@@ -3461,7 +3461,7 @@ int build_stl_str_hl(win_T *wp, char_u *out, size_t outlen, char_u *fmt, int use
if (fillchar == 0) { if (fillchar == 0) {
fillchar = ' '; fillchar = ' ';
} else if (mb_char2len(fillchar) > 1) { } else if (utf_char2len(fillchar) > 1) {
// Can't handle a multi-byte fill character yet. // Can't handle a multi-byte fill character yet.
fillchar = '-'; fillchar = '-';
} }

View File

@@ -477,7 +477,7 @@ char_u *get_special_key_name(int c, int modifiers)
* extract modifiers. * extract modifiers.
*/ */
if (c > 0 if (c > 0
&& (*mb_char2len)(c) == 1) { && utf_char2len(c) == 1) {
if (table_idx < 0 if (table_idx < 0
&& (!vim_isprintc(c) || (c & 0x7f) == ' ') && (!vim_isprintc(c) || (c & 0x7f) == ' ')
&& (c & 0x80)) { && (c & 0x80)) {

View File

@@ -114,7 +114,6 @@
#define MB_COPY_CHAR(f, t) mb_copy_char((const char_u **)(&f), &t); #define MB_COPY_CHAR(f, t) mb_copy_char((const char_u **)(&f), &t);
#define MB_CHARLEN(p) mb_charlen(p) #define MB_CHARLEN(p) mb_charlen(p)
#define MB_CHAR2LEN(c) mb_char2len(c)
#define PTR2CHAR(p) utf_ptr2char(p) #define PTR2CHAR(p) utf_ptr2char(p)
#define RESET_BINDING(wp) \ #define RESET_BINDING(wp) \

View File

@@ -38,9 +38,6 @@
#define ENC_LATIN9 0x400 // Latin9 #define ENC_LATIN9 0x400 // Latin9
#define ENC_MACROMAN 0x800 // Mac Roman (not Macro Man! :-) #define ENC_MACROMAN 0x800 // Mac Roman (not Macro Man! :-)
// TODO(bfredl): eventually we should keep only one of the namings
#define mb_char2len utf_char2len
/// Flags for vimconv_T /// Flags for vimconv_T
typedef enum { typedef enum {
CONV_NONE = 0, CONV_NONE = 0,

View File

@@ -1847,7 +1847,7 @@ int op_replace(oparg_T *oap, int c)
// Compute bytes needed, move character count to num_chars. // Compute bytes needed, move character count to num_chars.
num_chars = numc; num_chars = numc;
numc *= (*mb_char2len)(c); numc *= utf_char2len(c);
oldp = get_cursor_line_ptr(); oldp = get_cursor_line_ptr();
oldlen = (int)STRLEN(oldp); oldlen = (int)STRLEN(oldp);
@@ -1926,11 +1926,11 @@ int op_replace(oparg_T *oap, int c)
while (ltoreq(curwin->w_cursor, oap->end)) { while (ltoreq(curwin->w_cursor, oap->end)) {
n = gchar_cursor(); n = gchar_cursor();
if (n != NUL) { if (n != NUL) {
if ((*mb_char2len)(c) > 1 || (*mb_char2len)(n) > 1) { if (utf_char2len(c) > 1 || utf_char2len(n) > 1) {
// This is slow, but it handles replacing a single-byte // This is slow, but it handles replacing a single-byte
// with a multi-byte and the other way around. // with a multi-byte and the other way around.
if (curwin->w_cursor.lnum == oap->end.lnum) { if (curwin->w_cursor.lnum == oap->end.lnum) {
oap->end.col += (*mb_char2len)(c) - (*mb_char2len)(n); oap->end.col += utf_char2len(c) - utf_char2len(n);
} }
replace_character(c); replace_character(c);
} else { } else {

View File

@@ -2255,8 +2255,8 @@ collection:
if (startc > endc) { if (startc > endc) {
EMSG_RET_NULL(_(e_reverse_range)); EMSG_RET_NULL(_(e_reverse_range));
} }
if ((*mb_char2len)(startc) > 1 if (utf_char2len(startc) > 1
|| (*mb_char2len)(endc) > 1) { || utf_char2len(endc) > 1) {
// Limit to a range of 256 chars // Limit to a range of 256 chars
if (endc > startc + 256) { if (endc > startc + 256) {
EMSG_RET_NULL(_(e_large_class)); EMSG_RET_NULL(_(e_large_class));

View File

@@ -543,7 +543,7 @@ static char_u *nfa_get_match_text(nfa_state_T *start)
return NULL; /* just in case */ return NULL; /* just in case */
p = p->out; p = p->out;
while (p->c > 0) { while (p->c > 0) {
len += MB_CHAR2LEN(p->c); len += utf_char2len(p->c);
p = p->out; p = p->out;
} }
if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH) if (p->c != NFA_MCLOSE || p->out->c != NFA_MATCH)
@@ -1746,8 +1746,8 @@ collection:
EMIT(endc); EMIT(endc);
EMIT(NFA_RANGE); EMIT(NFA_RANGE);
EMIT(NFA_CONCAT); EMIT(NFA_CONCAT);
} else if ((*mb_char2len)(startc) > 1 } else if (utf_char2len(startc) > 1
|| (*mb_char2len)(endc) > 1) { || utf_char2len(endc) > 1) {
// Emit the characters in the range. // Emit the characters in the range.
// "startc" was already emitted, so skip it. // "startc" was already emitted, so skip it.
for (c = startc + 1; c <= endc; c++) { for (c = startc + 1; c <= endc; c++) {
@@ -1828,7 +1828,7 @@ collection:
nfa_do_multibyte: nfa_do_multibyte:
// plen is length of current char with composing chars // plen is length of current char with composing chars
if ((*mb_char2len)(c) != (plen = utfc_ptr2len(old_regparse)) if (utf_char2len(c) != (plen = utfc_ptr2len(old_regparse))
|| utf_iscomposing(c)) { || utf_iscomposing(c)) {
int i = 0; int i = 0;
@@ -2972,8 +2972,8 @@ static int nfa_max_width(nfa_state_T *startstate, int depth)
if (state->c < 0) if (state->c < 0)
/* don't know what this is */ /* don't know what this is */
return -1; return -1;
/* normal character */ // normal character
len += MB_CHAR2LEN(state->c); len += utf_char2len(state->c);
break; break;
} }
@@ -5620,7 +5620,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
// Only match composing character(s), ignore base // Only match composing character(s), ignore base
// character. Used for ".{composing}" and "{composing}" // character. Used for ".{composing}" and "{composing}"
// (no preceding character). // (no preceding character).
len += mb_char2len(mc); len += utf_char2len(mc);
} }
if (rex.reg_icombine && len == 0) { if (rex.reg_icombine && len == 0) {
// If \Z was present, then ignore composing characters. // If \Z was present, then ignore composing characters.
@@ -5636,7 +5636,7 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
} else if (len > 0 || mc == sta->c) { } else if (len > 0 || mc == sta->c) {
// Check base character matches first, unless ignored. // Check base character matches first, unless ignored.
if (len == 0) { if (len == 0) {
len += mb_char2len(mc); len += utf_char2len(mc);
sta = sta->out; sta = sta->out;
} }
@@ -5645,10 +5645,11 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start,
while (len < clen) { while (len < clen) {
mc = utf_ptr2char(rex.input + len); mc = utf_ptr2char(rex.input + len);
cchars[ccount++] = mc; cchars[ccount++] = mc;
len += mb_char2len(mc); len += utf_char2len(mc);
if (ccount == MAX_MCO) if (ccount == MAX_MCO) {
break; break;
} }
}
// Check that each composing char in the pattern matches a // Check that each composing char in the pattern matches a
// composing char in the text. We do not check if all // composing char in the text. We do not check if all

View File

@@ -3705,7 +3705,7 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
// if n_extra > 0, it gives the number of chars // if n_extra > 0, it gives the number of chars
// to use for a tab, else we need to calculate the width // to use for a tab, else we need to calculate the width
// for a tab // for a tab
int len = (tab_len * mb_char2len(wp->w_p_lcs_chars.tab2)); int len = (tab_len * utf_char2len(wp->w_p_lcs_chars.tab2));
if (n_extra > 0) { if (n_extra > 0) {
len += n_extra - tab_len; len += n_extra - tab_len;
} }
@@ -3728,8 +3728,8 @@ static int win_line(win_T *wp, linenr_T lnum, int startrow, int endrow, bool noc
lcs = wp->w_p_lcs_chars.tab3; lcs = wp->w_p_lcs_chars.tab3;
} }
utf_char2bytes(lcs, p); utf_char2bytes(lcs, p);
p += mb_char2len(lcs); p += utf_char2len(lcs);
n_extra += mb_char2len(lcs) - (saved_nextra > 0 ? 1 : 0); n_extra += utf_char2len(lcs) - (saved_nextra > 0 ? 1 : 0);
} }
p_extra = p_extra_free; p_extra = p_extra_free;

View File

@@ -4644,7 +4644,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
PROF_STORE(sp->ts_state) PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP; sp->ts_state = STATE_UNSWAP;
depth++; depth++;
fl = mb_char2len(c2); fl = utf_char2len(c2);
memmove(p, p + n, fl); memmove(p, p + n, fl);
utf_char2bytes(c, p + fl); utf_char2bytes(c, p + fl);
stack[depth].ts_fidxtry = sp->ts_fidx + n + fl; stack[depth].ts_fidxtry = sp->ts_fidx + n + fl;
@@ -4700,7 +4700,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so
PROF_STORE(sp->ts_state) PROF_STORE(sp->ts_state)
sp->ts_state = STATE_UNSWAP3; sp->ts_state = STATE_UNSWAP3;
depth++; depth++;
tl = mb_char2len(c3); tl = utf_char2len(c3);
memmove(p, p + n + fl, tl); memmove(p, p + n + fl, tl);
utf_char2bytes(c2, p + tl); utf_char2bytes(c2, p + tl);
utf_char2bytes(c, p + fl + tl); utf_char2bytes(c, p + fl + tl);

View File

@@ -5858,8 +5858,8 @@ static void set_map_str(slang_T *lp, char_u *map)
// the hash table. Each entry is the char, a NUL the headchar and // the hash table. Each entry is the char, a NUL the headchar and
// a NUL. // a NUL.
if (c >= 256) { if (c >= 256) {
int cl = mb_char2len(c); int cl = utf_char2len(c);
int headcl = mb_char2len(headc); int headcl = utf_char2len(headc);
char_u *b; char_u *b;
hash_T hash; hash_T hash;
hashitem_T *hi; hashitem_T *hi;