diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/nvim/edit.c | 6 | ||||
-rw-r--r-- | src/nvim/ex_docmd.c | 20 | ||||
-rw-r--r-- | src/nvim/fileio.c | 15 | ||||
-rw-r--r-- | src/nvim/globals.h | 1 | ||||
-rw-r--r-- | src/nvim/mbyte.c | 5 | ||||
-rw-r--r-- | src/nvim/message.c | 12 | ||||
-rw-r--r-- | src/nvim/ops.c | 3 | ||||
-rw-r--r-- | src/nvim/screen.c | 409 | ||||
-rw-r--r-- | src/nvim/search.c | 98 |
9 files changed, 228 insertions, 341 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 5a21c50fa6..67ac675a14 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -5110,11 +5110,9 @@ int get_literal(void) } } - if (cc == 0) /* NUL is stored as NL */ + if (cc == 0) { // NUL is stored as NL cc = '\n'; - if (enc_dbcs && (cc & 0xff) == 0) - cc = '?'; /* don't accept an illegal DBCS char, the NUL in the - second byte will cause trouble! */ + } --no_mapping; if (nc) diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c index c60ccabf4c..8f9af1c2ec 100644 --- a/src/nvim/ex_docmd.c +++ b/src/nvim/ex_docmd.c @@ -5489,24 +5489,18 @@ uc_check_code( break; case 1: /* Quote, but don't split */ result = STRLEN(eap->arg) + 2; - for (p = eap->arg; *p; ++p) { - if (enc_dbcs != 0 && (*mb_ptr2len)(p) == 2) - /* DBCS can contain \ in a trail byte, skip the - * double-byte character. */ - ++p; - else if (*p == '\\' || *p == '"') - ++result; + for (p = eap->arg; *p; p++) { + if (*p == '\\' || *p == '"') { + result++; + } } if (buf != NULL) { *buf++ = '"'; - for (p = eap->arg; *p; ++p) { - if (enc_dbcs != 0 && (*mb_ptr2len)(p) == 2) - /* DBCS can contain \ in a trail byte, copy the - * double-byte character to avoid escaping. */ - *buf++ = *p++; - else if (*p == '\\' || *p == '"') + for (p = eap->arg; *p; p++) { + if (*p == '\\' || *p == '"') { *buf++ = '\\'; + } *buf++ = *p; } *buf = '"'; diff --git a/src/nvim/fileio.c b/src/nvim/fileio.c index ba3625bf95..b9de46efc8 100644 --- a/src/nvim/fileio.c +++ b/src/nvim/fileio.c @@ -5313,9 +5313,7 @@ void forward_slash(char_u *fname) } for (p = fname; *p != NUL; p++) { // The Big5 encoding can have '\' in the trail byte. - if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) { - p++; - } else if (*p == '\\') { + if (*p == '\\') { *p = '/'; } } @@ -7615,10 +7613,6 @@ char_u * file_pat_to_reg_pat( #endif default: size++; - if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) { - ++p; - ++size; - } break; } } @@ -7739,10 +7733,9 @@ char_u * file_pat_to_reg_pat( reg_pat[i++] = ','; break; default: - if (enc_dbcs != 0 && (*mb_ptr2len)(p) > 1) - reg_pat[i++] = *p++; - else if (allow_dirs != NULL && vim_ispathsep(*p)) - *allow_dirs = TRUE; + if (allow_dirs != NULL && vim_ispathsep(*p)) { + *allow_dirs = true; + } reg_pat[i++] = *p; break; } diff --git a/src/nvim/globals.h b/src/nvim/globals.h index 1cc3d05cd3..52c5d65512 100644 --- a/src/nvim/globals.h +++ b/src/nvim/globals.h @@ -641,7 +641,6 @@ EXTERN int vr_lines_changed INIT(= 0); /* #Lines changed by "gR" so far */ // mbyte flags that used to depend on 'encoding'. These are now deprecated, as // 'encoding' is always "utf-8". Code that use them can be refactored to // remove dead code. -#define enc_dbcs 0 #define enc_utf8 true #define has_mbyte true diff --git a/src/nvim/mbyte.c b/src/nvim/mbyte.c index 1cf045d7e0..5ed2b4c564 100644 --- a/src/nvim/mbyte.c +++ b/src/nvim/mbyte.c @@ -4,9 +4,8 @@ /// mbyte.c: Code specifically for handling multi-byte characters. /// Multibyte extensions partly by Sung-Hoon Baek /// -/// The encoding used in nvim is always UTF-8. "enc_utf8" and "has_mbyte" is -/// thus always true. "enc_dbcs" is always zero. The 'encoding' option is -/// read-only and always reads "utf-8". +/// Strings internal to Nvim are always encoded as UTF-8 (thus the legacy +/// 'encoding' option is always "utf-8"). /// /// The cell width on the display needs to be determined from the character /// value. Recognizing UTF-8 bytes is easy: 0xxx.xxxx is a single-byte char, diff --git a/src/nvim/message.c b/src/nvim/message.c index abe9c25bb8..b4aa333a48 100644 --- a/src/nvim/message.c +++ b/src/nvim/message.c @@ -281,15 +281,9 @@ msg_strtrunc ( /* Use up to 'showcmd' column. */ room = (int)(Rows - msg_row - 1) * Columns + sc_col - 1; if (len > room && room > 0) { - if (enc_utf8) - /* may have up to 18 bytes per cell (6 per char, up to two - * composing chars) */ - len = (room + 2) * 18; - else if (enc_dbcs == DBCS_JPNU) - /* may have up to 2 bytes per cell for euc-jp */ - len = (room + 2) * 2; - else - len = room + 2; + // may have up to 18 bytes per cell (6 per char, up to two + // composing chars) + len = (room + 2) * 18; buf = xmalloc(len); trunc_string(s, buf, room, len); } diff --git a/src/nvim/ops.c b/src/nvim/ops.c index 674a9244f0..99dee939fc 100644 --- a/src/nvim/ops.c +++ b/src/nvim/ops.c @@ -1974,8 +1974,6 @@ int swapchar(int op_type, pos_T *pos) inc(pos); } - if (enc_dbcs != 0 && c >= 0x100) /* No lower/uppercase letter */ - return FALSE; nc = c; if (mb_islower(c)) { if (op_type == OP_ROT13) { @@ -3610,6 +3608,7 @@ int do_join(size_t count, int remove_comments = (use_formatoptions == TRUE) && has_format_option(FO_REMOVE_COMS); bool prev_was_comment = false; + assert(count >= 1); if (save_undo && u_save(curwin->w_cursor.lnum - 1, curwin->w_cursor.lnum + (linenr_T)count) == FAIL) { diff --git a/src/nvim/screen.c b/src/nvim/screen.c index de353fa3f6..08bb4e4a52 100644 --- a/src/nvim/screen.c +++ b/src/nvim/screen.c @@ -2617,7 +2617,7 @@ win_line ( } // Highlight one character for an empty match. if (shl->startcol == shl->endcol) { - if (has_mbyte && line[shl->endcol] != NUL) { + if (line[shl->endcol] != NUL) { shl->endcol += (*mb_ptr2len)(line + shl->endcol); } else { ++shl->endcol; @@ -2963,13 +2963,8 @@ win_line ( shl->endcol = MAXCOL; if (shl->startcol == shl->endcol) { - /* highlight empty match, try again after - * it */ - if (has_mbyte) - shl->endcol += (*mb_ptr2len)(line - + shl->endcol); - else - ++shl->endcol; + // highlight empty match, try again after it + shl->endcol += (*mb_ptr2len)(line + shl->endcol); } /* Loop to check if the match starts at the @@ -3069,7 +3064,7 @@ win_line ( if (c_extra != NUL || (n_extra == 1 && c_final != NUL)) { c = (n_extra == 1 && c_final != NUL) ? c_final : c_extra; mb_c = c; // doesn't handle non-utf-8 multi-byte! - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3078,43 +3073,38 @@ win_line ( } } else { c = *p_extra; - if (has_mbyte) { + 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_utf8 = false; + if (mb_l > n_extra) { + mb_l = 1; + } else if (mb_l > 1) { + mb_c = utfc_ptr2char(p_extra, u8cc); + mb_utf8 = true; + c = 0xc0; + } + if (mb_l == 0) { // at the NUL at end-of-line + mb_l = 1; + } + + // If a double-width char doesn't fit display a '>' in the last column. + if ((wp->w_p_rl ? (col <= 0) : (col >= grid->Columns - 1)) + && (*mb_char2cells)(mb_c) == 2) { + c = '>'; mb_c = c; - if (enc_utf8) { - // If the UTF-8 character is more than one byte: - // Decode it into "mb_c". - mb_l = utfc_ptr2len(p_extra); - mb_utf8 = false; - if (mb_l > n_extra) { - mb_l = 1; - } else if (mb_l > 1) { - mb_c = utfc_ptr2char(p_extra, u8cc); - mb_utf8 = true; - c = 0xc0; - } - } - if (mb_l == 0) /* at the NUL at end-of-line */ - mb_l = 1; - - /* If a double-width char doesn't fit display a '>' in the - * last column. */ - if ((wp->w_p_rl ? (col <= 0) : - (col >= grid->Columns - 1)) - && (*mb_char2cells)(mb_c) == 2) { - c = '>'; - mb_c = c; - mb_l = 1; - mb_utf8 = false; - multi_attr = win_hl_attr(wp, HLF_AT); + mb_l = 1; + mb_utf8 = false; + multi_attr = win_hl_attr(wp, HLF_AT); - // put the pointer back to output the double-width - // character at the start of the next line. - n_extra++; - p_extra--; - } else { - n_extra -= mb_l - 1; - p_extra += mb_l - 1; - } + // put the pointer back to output the double-width + // character at the start of the next line. + n_extra++; + p_extra--; + } else { + n_extra -= mb_l - 1; + p_extra += mb_l - 1; } ++p_extra; } @@ -3129,151 +3119,113 @@ win_line ( // Get a character from the line itself. c0 = c = *ptr; - if (has_mbyte) { - mb_c = c; - if (enc_utf8) { - // If the UTF-8 character is more than one byte: Decode it - // into "mb_c". - mb_l = utfc_ptr2len(ptr); - mb_utf8 = false; - if (mb_l > 1) { - mb_c = utfc_ptr2char(ptr, u8cc); - // Overlong encoded ASCII or ASCII with composing char - // is displayed normally, except a NUL. - if (mb_c < 0x80) { - c0 = c = mb_c; - } - mb_utf8 = true; + mb_c = c; + // If the UTF-8 character is more than one byte: Decode it + // into "mb_c". + mb_l = utfc_ptr2len(ptr); + mb_utf8 = false; + if (mb_l > 1) { + mb_c = utfc_ptr2char(ptr, u8cc); + // Overlong encoded ASCII or ASCII with composing char + // is displayed normally, except a NUL. + if (mb_c < 0x80) { + c0 = c = mb_c; + } + mb_utf8 = true; - /* At start of the line we can have a composing char. - * Draw it as a space with a composing char. */ - if (utf_iscomposing(mb_c)) { - int i; + // At start of the line we can have a composing char. + // Draw it as a space with a composing char. + if (utf_iscomposing(mb_c)) { + int i; - for (i = MAX_MCO - 1; i > 0; i--) { - u8cc[i] = u8cc[i - 1]; - } - u8cc[0] = mb_c; - mb_c = ' '; - } + for (i = MAX_MCO - 1; i > 0; i--) { + u8cc[i] = u8cc[i - 1]; } + u8cc[0] = mb_c; + mb_c = ' '; + } + } - if ((mb_l == 1 && c >= 0x80) - || (mb_l >= 1 && mb_c == 0) - || (mb_l > 1 && (!vim_isprintc(mb_c)))) { - // Illegal UTF-8 byte: display as <xx>. - // Non-BMP character : display as ? or fullwidth ?. - transchar_hex((char *)extra, mb_c); - if (wp->w_p_rl) { // reverse - rl_mirror(extra); - } - - p_extra = extra; - c = *p_extra; - mb_c = mb_ptr2char_adv((const char_u **)&p_extra); - mb_utf8 = (c >= 0x80); - n_extra = (int)STRLEN(p_extra); - c_extra = NUL; - c_final = NUL; - if (area_attr == 0 && search_attr == 0) { - n_attr = n_extra + 1; - extra_attr = win_hl_attr(wp, HLF_8); - saved_attr2 = char_attr; // save current attr - } - } else if (mb_l == 0) /* at the NUL at end-of-line */ - mb_l = 1; - else if (p_arshape && !p_tbidi && arabic_char(mb_c)) { - /* Do Arabic shaping. */ - int pc, pc1, nc; - int pcc[MAX_MCO]; - - /* The idea of what is the previous and next - * character depends on 'rightleft'. */ - if (wp->w_p_rl) { - pc = prev_c; - pc1 = prev_c1; - nc = utf_ptr2char(ptr + mb_l); - prev_c1 = u8cc[0]; - } else { - pc = utfc_ptr2char(ptr + mb_l, pcc); - nc = prev_c; - pc1 = pcc[0]; - } - prev_c = mb_c; + if ((mb_l == 1 && c >= 0x80) + || (mb_l >= 1 && mb_c == 0) + || (mb_l > 1 && (!vim_isprintc(mb_c)))) { + // Illegal UTF-8 byte: display as <xx>. + // Non-BMP character : display as ? or fullwidth ?. + transchar_hex((char *)extra, mb_c); + if (wp->w_p_rl) { // reverse + rl_mirror(extra); + } - mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); - } else - prev_c = mb_c; - } else { /* enc_dbcs */ - mb_l = MB_BYTE2LEN(c); - if (mb_l == 0) /* at the NUL at end-of-line */ - mb_l = 1; - else if (mb_l > 1) { - /* We assume a second byte below 32 is illegal. - * Hopefully this is OK for all double-byte encodings! - */ - if (ptr[1] >= 32) - mb_c = (c << 8) + ptr[1]; - else { - if (ptr[1] == NUL) { - /* head byte at end of line */ - mb_l = 1; - transchar_nonprint(extra, c); - } else { - /* illegal tail byte */ - mb_l = 2; - STRCPY(extra, "XX"); - } - p_extra = extra; - n_extra = (int)STRLEN(extra) - 1; - c_extra = NUL; - c_final = NUL; - c = *p_extra++; - if (area_attr == 0 && search_attr == 0) { - n_attr = n_extra + 1; - extra_attr = win_hl_attr(wp, HLF_8); - saved_attr2 = char_attr; // save current attr - } - mb_c = c; - } - } + p_extra = extra; + c = *p_extra; + mb_c = mb_ptr2char_adv((const char_u **)&p_extra); + mb_utf8 = (c >= 0x80); + n_extra = (int)STRLEN(p_extra); + c_extra = NUL; + c_final = NUL; + if (area_attr == 0 && search_attr == 0) { + n_attr = n_extra + 1; + extra_attr = win_hl_attr(wp, HLF_8); + saved_attr2 = char_attr; // save current attr } - /* If a double-width char doesn't fit display a '>' in the - * last column; the character is displayed at the start of the - * next line. */ - if ((wp->w_p_rl ? (col <= 0) : - (col >= grid->Columns - 1)) - && (*mb_char2cells)(mb_c) == 2) { - c = '>'; - mb_c = c; - mb_utf8 = false; - mb_l = 1; - multi_attr = win_hl_attr(wp, HLF_AT); - // Put pointer back so that the character will be - // displayed at the start of the next line. - ptr--; - } else if (*ptr != NUL) { - ptr += mb_l - 1; + } else if (mb_l == 0) { // at the NUL at end-of-line + mb_l = 1; + } else if (p_arshape && !p_tbidi && arabic_char(mb_c)) { + // Do Arabic shaping. + int pc, pc1, nc; + int pcc[MAX_MCO]; + + // The idea of what is the previous and next + // character depends on 'rightleft'. + if (wp->w_p_rl) { + pc = prev_c; + pc1 = prev_c1; + nc = utf_ptr2char(ptr + mb_l); + prev_c1 = u8cc[0]; + } else { + pc = utfc_ptr2char(ptr + mb_l, pcc); + nc = prev_c; + pc1 = pcc[0]; } + prev_c = mb_c; - /* If a double-width char doesn't fit at the left side display - * a '<' in the first column. Don't do this for unprintable - * characters. */ - if (n_skip > 0 && mb_l > 1 && n_extra == 0) { - n_extra = 1; - c_extra = MB_FILLER_CHAR; - c_final = NUL; - c = ' '; - if (area_attr == 0 && search_attr == 0) { - n_attr = n_extra + 1; - extra_attr = win_hl_attr(wp, HLF_AT); - saved_attr2 = char_attr; // save current attr - } - mb_c = c; - mb_utf8 = false; - mb_l = 1; + mb_c = arabic_shape(mb_c, &c, &u8cc[0], pc, pc1, nc); + } else { + prev_c = mb_c; + } + // If a double-width char doesn't fit display a '>' in the + // last column; the character is displayed at the start of the + // next line. + if ((wp->w_p_rl ? (col <= 0) : + (col >= grid->Columns - 1)) + && (*mb_char2cells)(mb_c) == 2) { + c = '>'; + mb_c = c; + mb_utf8 = false; + mb_l = 1; + multi_attr = win_hl_attr(wp, HLF_AT); + // Put pointer back so that the character will be + // displayed at the start of the next line. + ptr--; + } else if (*ptr != NUL) { + ptr += mb_l - 1; + } + + // If a double-width char doesn't fit at the left side display a '<' in + // the first column. Don't do this for unprintable characters. + if (n_skip > 0 && mb_l > 1 && n_extra == 0) { + n_extra = 1; + c_extra = MB_FILLER_CHAR; + c_final = NUL; + c = ' '; + if (area_attr == 0 && search_attr == 0) { + n_attr = n_extra + 1; + extra_attr = win_hl_attr(wp, HLF_AT); + saved_attr2 = char_attr; // save current attr } - + mb_c = c; + mb_utf8 = false; + mb_l = 1; } ptr++; @@ -3331,11 +3283,8 @@ win_line ( char_u *p; int len; hlf_T spell_hlf = HLF_COUNT; - if (has_mbyte) { - prev_ptr = ptr - mb_l; - v -= mb_l - 1; - } else - prev_ptr = ptr - 1; + prev_ptr = ptr - mb_l; + v -= mb_l - 1; /* Use nextline[] if possible, it has the start of the * next line concatenated. */ @@ -3445,7 +3394,7 @@ win_line ( extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = char_attr; // save current attr mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3460,7 +3409,7 @@ win_line ( extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = char_attr; // save current attr mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3567,7 +3516,7 @@ win_line ( extra_attr = win_hl_attr(wp, HLF_0); saved_attr2 = char_attr; // save current attr mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3614,7 +3563,7 @@ win_line ( extra_attr = win_hl_attr(wp, HLF_AT); n_attr = 1; mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3703,7 +3652,7 @@ win_line ( n_skip = 1; } mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -3749,9 +3698,9 @@ win_line ( && c != NUL) { c = wp->w_p_lcs_chars.prec; lcs_prec_todo = NUL; - if (has_mbyte && (*mb_char2cells)(mb_c) > 1) { - /* Double-width character being overwritten by the "precedes" - * character, need to fill up half the character. */ + if ((*mb_char2cells)(mb_c) > 1) { + // Double-width character being overwritten by the "precedes" + // character, need to fill up half the character. c_extra = MB_FILLER_CHAR; c_final = NUL; n_extra = 1; @@ -3759,7 +3708,7 @@ win_line ( extra_attr = win_hl_attr(wp, HLF_AT); } mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -4033,7 +3982,7 @@ win_line ( c = wp->w_p_lcs_chars.ext; char_attr = win_hl_attr(wp, HLF_AT); mb_c = c; - if (enc_utf8 && utf_char2len(c) > 1) { + if (utf_char2len(c) > 1) { mb_utf8 = true; u8cc[0] = 0; c = 0xc0; @@ -4074,13 +4023,13 @@ win_line ( */ vcol_prev = vcol; if (draw_state < WL_LINE || n_skip <= 0) { - /* - * Store the character. - */ - if (has_mbyte && wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) { - /* A double-wide character is: put first halve in left cell. */ - --off; - --col; + // + // Store the character. + // + if (wp->w_p_rl && (*mb_char2cells)(mb_c) > 1) { + // A double-wide character is: put first halve in left cell. + off--; + col--; } if (mb_utf8) { schar_from_cc(linebuf_char[off], mb_c, u8cc); @@ -4094,7 +4043,7 @@ win_line ( linebuf_attr[off] = char_attr; } - if (has_mbyte && (*mb_char2cells)(mb_c) > 1) { + if ((*mb_char2cells)(mb_c) > 1) { // Need to fill two screen columns. off++; col++; @@ -4154,8 +4103,8 @@ win_line ( } - if (has_mbyte && (*mb_char2cells)(mb_c) > 1) { - /* Need to fill two screen columns. */ + if ((*mb_char2cells)(mb_c) > 1) { + // Need to fill two screen columns. if (wp->w_p_rl) { --boguscols; --col; @@ -4755,8 +4704,8 @@ win_redr_status_matches ( for (; *s != NUL; ++s) { s += skip_status_match_char(xp, s); clen += ptr2cells(s); - if (has_mbyte && (l = (*mb_ptr2len)(s)) > 1) { - STRNCPY(buf + len, s, l); + if ((l = (*mb_ptr2len)(s)) > 1) { + STRNCPY(buf + len, s, l); // NOLINT(runtime/printf) s += l - 1; len += l; } else { @@ -5024,10 +4973,11 @@ get_keymap_str ( curbuf = old_curbuf; curwin = old_curwin; if (p == NULL || *p == NUL) { - if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) + if (wp->w_buffer->b_kmap_state & KEYMAP_LOADED) { p = wp->w_buffer->b_p_keymap; - else + } else { p = (char_u *)"lang"; + } } if (vim_snprintf((char *)buf, len, (char *)fmt, p) > len - 1) { buf[0] = NUL; @@ -5688,12 +5638,10 @@ next_search_hl ( shl->lnum = 0; break; } - if (has_mbyte) - matchcol += mb_ptr2len(ml); - else - ++matchcol; - } else + matchcol += mb_ptr2len(ml); + } else { matchcol = shl->rm.endpos[0].col; + } shl->lnum = lnum; if (shl->rm.regprog != NULL) { @@ -5828,18 +5776,16 @@ void grid_fill(ScreenGrid *grid, int start_row, int end_row, int start_col, } for (int row = start_row; row < end_row; row++) { - if (has_mbyte) { - // When drawing over the right halve of a double-wide char clear - // out the left halve. When drawing over the left halve of a - // double wide-char clear out the right halve. Only needed in a - // terminal. - if (start_col > 0 && grid_fix_col(grid, start_col, row) != start_col) { - grid_puts_len(grid, (char_u *)" ", 1, row, start_col - 1, 0); - } - if (end_col < grid->Columns - && grid_fix_col(grid, end_col, row) != end_col) { - grid_puts_len(grid, (char_u *)" ", 1, row, end_col, 0); - } + // When drawing over the right halve of a double-wide char clear + // out the left halve. When drawing over the left halve of a + // double wide-char clear out the right halve. Only needed in a + // terminal. + if (start_col > 0 && grid_fix_col(grid, start_col, row) != start_col) { + grid_puts_len(grid, (char_u *)" ", 1, row, start_col - 1, 0); + } + if (end_col < grid->Columns + && grid_fix_col(grid, end_col, row) != end_col) { + grid_puts_len(grid, (char_u *)" ", 1, row, end_col, 0); } // if grid was resized (in ext_multigrid mode), the UI has no redraw updates @@ -6770,14 +6716,9 @@ static void draw_tabline(void) (void)shorten_dir(NameBuff); len = vim_strsize(NameBuff); p = NameBuff; - if (has_mbyte) - while (len > room) { - len -= ptr2cells(p); - MB_PTR_ADV(p); - } - else if (len > room) { - p += len - room; - len = room; + while (len > room) { + len -= ptr2cells(p); + MB_PTR_ADV(p); } if (len > Columns - col - 1) { len = Columns - col - 1; diff --git a/src/nvim/search.c b/src/nvim/search.c index d635763acc..b09931b337 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -360,17 +360,16 @@ int ignorecase_opt(char_u *pat, int ic_in, int scs) return ic; } -/* - * Return TRUE if pattern "pat" has an uppercase character. - */ -int pat_has_uppercase(char_u *pat) +/// Returns true if pattern `pat` has an uppercase character. +bool pat_has_uppercase(char_u *pat) + FUNC_ATTR_NONNULL_ALL { char_u *p = pat; while (*p != NUL) { - int l; + const int l = mb_ptr2len(p); - if ((l = mb_ptr2len(p)) > 1) { + if (l > 1) { if (mb_isupper(utf_ptr2char(p))) { return true; } @@ -391,7 +390,7 @@ int pat_has_uppercase(char_u *pat) p++; } } - return FALSE; + return false; } const char *last_csearch(void) @@ -744,37 +743,29 @@ int searchit( } else break; - /* - * We found a valid match, now check if there is - * another one after it. - * If vi-compatible searching, continue at the end - * of the match, otherwise continue one position - * forward. - */ + // We found a valid match, now check if there is + // another one after it. + // If vi-compatible searching, continue at the end + // of the match, otherwise continue one position + // forward. if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) { - if (nmatched > 1) + if (nmatched > 1) { break; + } matchcol = endpos.col; - /* for empty match: advance one char */ + // for empty match: advance one char if (matchcol == matchpos.col && ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += - (*mb_ptr2len)(ptr + matchcol); - else - ++matchcol; + matchcol += mb_ptr2len(ptr + matchcol); } } else { - /* Stop when the match is in a next line. */ - if (matchpos.lnum > 0) + // Stop when the match is in a next line. + if (matchpos.lnum > 0) { break; + } matchcol = matchpos.col; if (ptr[matchcol] != NUL) { - if (has_mbyte) - matchcol += - (*mb_ptr2len)(ptr + matchcol); - else - ++matchcol; + matchcol += mb_ptr2len(ptr + matchcol); } } if (ptr[matchcol] == NUL @@ -3229,37 +3220,18 @@ static int in_html_tag(int end_tag) int lc = NUL; pos_T pos; - if (enc_dbcs) { - char_u *lp = NULL; - - /* We search forward until the cursor, because searching backwards is - * very slow for DBCS encodings. */ - for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p)) { - if (*p == '>' || *p == '<') { - lc = *p; - lp = p; - } - } - if (*p != '<') { // check for '<' under cursor - if (lc != '<') { - return false; - } - p = lp; - } - } else { - for (p = line + curwin->w_cursor.col; p > line; ) { - if (*p == '<') { // find '<' under/before cursor - break; - } - MB_PTR_BACK(line, p); - if (*p == '>') { // find '>' before cursor - break; - } + for (p = line + curwin->w_cursor.col; p > line; ) { + if (*p == '<') { // find '<' under/before cursor + break; } - if (*p != '<') { - return false; + MB_PTR_BACK(line, p); + if (*p == '>') { // find '>' before cursor + break; } } + if (*p != '<') { + return false; + } pos.lnum = curwin->w_cursor.lnum; pos.col = (colnr_T)(p - line); @@ -3655,16 +3627,14 @@ find_next_quote( for (;; ) { c = line[col]; - if (c == NUL) + if (c == NUL) { return -1; - else if (escape != NULL && vim_strchr(escape, c)) - ++col; - else if (c == quotechar) + } else if (escape != NULL && vim_strchr(escape, c)) { + col++; + } else if (c == quotechar) { break; - if (has_mbyte) - col += (*mb_ptr2len)(line + col); - else - ++col; + } + col += mb_ptr2len(line + col); } return col; } |