aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/nvim/cursor.c8
-rw-r--r--src/nvim/memline.c4
-rw-r--r--src/nvim/message.c59
-rw-r--r--src/nvim/move.c8
-rw-r--r--src/nvim/option.c56
-rw-r--r--src/nvim/path.c23
-rw-r--r--src/nvim/strings.c10
7 files changed, 72 insertions, 96 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c
index d3ffab1759..74a6f77a6d 100644
--- a/src/nvim/cursor.c
+++ b/src/nvim/cursor.c
@@ -242,9 +242,7 @@ static int coladvance2(
}
// Prevent from moving onto a trail byte.
- if (has_mbyte) {
- mark_mb_adjustpos(curbuf, pos);
- }
+ mark_mb_adjustpos(curbuf, pos);
if (wcol < 0 || col < wcol) {
return FAIL;
@@ -378,9 +376,7 @@ void check_cursor_col_win(win_T *win)
} else {
win->w_cursor.col = len - 1;
// Move the cursor to the head byte.
- if (has_mbyte) {
- mark_mb_adjustpos(win->w_buffer, &win->w_cursor);
- }
+ mark_mb_adjustpos(win->w_buffer, &win->w_cursor);
}
} else if (win->w_cursor.col < 0) {
win->w_cursor.col = 0;
diff --git a/src/nvim/memline.c b/src/nvim/memline.c
index 57ed0d6588..70225484ec 100644
--- a/src/nvim/memline.c
+++ b/src/nvim/memline.c
@@ -4152,9 +4152,7 @@ void goto_byte(long cnt)
check_cursor();
// Make sure the cursor is on the first byte of a multi-byte char.
- if (has_mbyte) {
- mb_adjust_cursor();
- }
+ mb_adjust_cursor();
}
/// Increment the line pointer "lp" crossing line boundaries as necessary.
diff --git a/src/nvim/message.c b/src/nvim/message.c
index 06ba607323..f76a408481 100644
--- a/src/nvim/message.c
+++ b/src/nvim/message.c
@@ -400,12 +400,12 @@ void trunc_string(char_u *s, char_u *buf, int room_in, int buflen)
}
len += n;
buf[e] = s[e];
- if (has_mbyte)
- for (n = (*mb_ptr2len)(s + e); --n > 0; ) {
- if (++e == buflen)
- break;
- buf[e] = s[e];
+ for (n = utfc_ptr2len(s + e); --n > 0; ) {
+ if (++e == buflen) {
+ break;
}
+ buf[e] = s[e];
+ }
}
// Last part: End of the string.
@@ -873,19 +873,17 @@ char_u *msg_may_trunc(int force, char_u *s)
room = (int)(Rows - cmdline_row - 1) * Columns + sc_col - 1;
if ((force || (shortmess(SHM_TRUNC) && !exmode_active))
&& (n = (int)STRLEN(s) - room) > 0) {
- if (has_mbyte) {
- int size = vim_strsize(s);
-
- /* There may be room anyway when there are multibyte chars. */
- if (size <= room)
- return s;
+ int size = vim_strsize(s);
- for (n = 0; size >= room; ) {
- size -= utf_ptr2cells(s + n);
- n += utfc_ptr2len(s + n);
- }
- --n;
+ // There may be room anyway when there are multibyte chars.
+ if (size <= room) {
+ return s;
+ }
+ for (n = 0; size >= room; ) {
+ size -= utf_ptr2cells(s + n);
+ n += utfc_ptr2len(s + n);
}
+ n--;
s += n;
*s = '<';
}
@@ -1430,7 +1428,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 (enc_utf8 && utf_iscomposing(utf_ptr2char(msgstr))) {
+ if (utf_iscomposing(utf_ptr2char(msgstr))) {
msg_puts_attr(" ", attr);
}
@@ -2489,8 +2487,9 @@ 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 (enc_utf8 && utf_iscomposing(utf_ptr2char(t_s)))
- --msg_col;
+ if (utf_iscomposing(utf_ptr2char(t_s))) {
+ msg_col--;
+ }
if (msg_col >= Columns) {
msg_col = 0;
++msg_row;
@@ -3391,12 +3390,12 @@ do_dialog (
* Copy one character from "*from" to "*to", taking care of multi-byte
* characters. Return the length of the character in bytes.
*/
-static int
-copy_char (
- char_u *from,
+static int copy_char(
+ const char_u *from,
char_u *to,
- int lowercase /* make character lower case */
+ bool lowercase // make character lower case
)
+ FUNC_ATTR_NONNULL_ALL
{
if (lowercase) {
int c = mb_tolower(utf_ptr2char(from));
@@ -3408,7 +3407,7 @@ copy_char (
}
#define HAS_HOTKEY_LEN 30
-#define HOTK_LEN (has_mbyte ? MB_MAXBYTES : 1)
+#define HOTK_LEN MB_MAXBYTES
/// Allocates memory for dialog string & for storing hotkeys
///
@@ -3512,7 +3511,7 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
// Define first default hotkey. Keep the hotkey string NUL
// terminated to avoid reading past the end.
- hotkeys_ptr[copy_char(buttons, hotkeys_ptr, TRUE)] = NUL;
+ hotkeys_ptr[copy_char(buttons, hotkeys_ptr, true)] = NUL;
// Remember where the choices start, displaying starts here when
// "hotkeys_ptr" typed at the more prompt.
@@ -3532,8 +3531,8 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
*msgp++ = ' '; // '\n' -> ', '
// Advance to next hotkey and set default hotkey
- hotkeys_ptr += (has_mbyte) ? STRLEN(hotkeys_ptr): 1;
- hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, TRUE)] = NUL;
+ hotkeys_ptr += STRLEN(hotkeys_ptr);
+ hotkeys_ptr[copy_char(r + 1, hotkeys_ptr, true)] = NUL;
if (default_button_idx) {
default_button_idx--;
@@ -3555,15 +3554,15 @@ static void copy_hotkeys_and_msg(const char_u *message, char_u *buttons,
} else {
// '&a' -> '[a]'
*msgp++ = (default_button_idx == 1) ? '[' : '(';
- msgp += copy_char(r, msgp, FALSE);
+ msgp += copy_char(r, msgp, false);
*msgp++ = (default_button_idx == 1) ? ']' : ')';
// redefine hotkey
- hotkeys_ptr[copy_char(r, hotkeys_ptr, TRUE)] = NUL;
+ hotkeys_ptr[copy_char(r, hotkeys_ptr, true)] = NUL;
}
} else {
// everything else copy literally
- msgp += copy_char(r, msgp, FALSE);
+ msgp += copy_char(r, msgp, false);
}
// advance to the next character
diff --git a/src/nvim/move.c b/src/nvim/move.c
index ccd19a81de..fdcf6bb189 100644
--- a/src/nvim/move.c
+++ b/src/nvim/move.c
@@ -717,11 +717,9 @@ int curwin_col_off2(void)
return win_col_off2(curwin);
}
-/*
- * compute curwin->w_wcol and curwin->w_virtcol.
- * Also updates curwin->w_wrow and curwin->w_cline_row.
- * Also updates curwin->w_leftcol.
- */
+// Compute curwin->w_wcol and curwin->w_virtcol.
+// Also updates curwin->w_wrow and curwin->w_cline_row.
+// Also updates curwin->w_leftcol.
void curs_columns(
int may_scroll /* when true, may scroll horizontally */
)
diff --git a/src/nvim/option.c b/src/nvim/option.c
index fcc051ef1a..0a91687352 100644
--- a/src/nvim/option.c
+++ b/src/nvim/option.c
@@ -1725,14 +1725,15 @@ int do_set(
#endif
)
arg++; // remove backslash
- if (has_mbyte
- && (i = (*mb_ptr2len)(arg)) > 1) {
+ i = utfc_ptr2len(arg);
+ if (i > 1) {
// copy multibyte char
memmove(s, arg, (size_t)i);
arg += i;
s += i;
- } else
+ } else {
*s++ = *arg++;
+ }
}
*s = NUL;
@@ -2864,39 +2865,26 @@ ambw_end:
errmsg = e_invarg;
}
} else if (gvarp == &p_mps) { // 'matchpairs'
- if (has_mbyte) {
- for (p = *varp; *p != NUL; p++) {
- int x2 = -1;
- int x3 = -1;
+ for (p = *varp; *p != NUL; p++) {
+ int x2 = -1;
+ int x3 = -1;
- if (*p != NUL) {
- p += mb_ptr2len(p);
- }
- if (*p != NUL) {
- x2 = *p++;
- }
- if (*p != NUL) {
- x3 = utf_ptr2char(p);
- p += mb_ptr2len(p);
- }
- if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
- errmsg = e_invarg;
- break;
- }
- if (*p == NUL) {
- break;
- }
+ if (*p != NUL) {
+ p += utfc_ptr2len(p);
}
- } else {
- // Check for "x:y,x:y"
- for (p = *varp; *p != NUL; p += 4) {
- if (p[1] != ':' || p[2] == NUL || (p[3] != NUL && p[3] != ',')) {
- errmsg = e_invarg;
- break;
- }
- if (p[3] == NUL) {
- break;
- }
+ if (*p != NUL) {
+ x2 = *p++;
+ }
+ if (*p != NUL) {
+ x3 = utf_ptr2char(p);
+ p += utfc_ptr2len(p);
+ }
+ if (x2 != ':' || x3 == -1 || (*p != NUL && *p != ',')) {
+ errmsg = e_invarg;
+ break;
+ }
+ if (*p == NUL) {
+ break;
}
}
} else if (gvarp == &p_com) { // 'comments'
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 31318f6bea..793f917f06 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -260,13 +260,13 @@ char_u *shorten_dir(char_u *str)
*d++ = *s;
skip = false;
} else if (!skip) {
- *d++ = *s; /* copy next char */
- if (*s != '~' && *s != '.') /* and leading "~" and "." */
+ *d++ = *s; // copy next char
+ if (*s != '~' && *s != '.') { // and leading "~" and "."
skip = true;
- if (has_mbyte) {
- int l = mb_ptr2len(s);
- while (--l > 0)
- *d++ = *++s;
+ }
+ int l = utfc_ptr2len(s);
+ while (--l > 0) {
+ *d++ = *++s;
}
}
}
@@ -608,13 +608,10 @@ static size_t do_path_expand(garray_T *gap, const char_u *path,
)) {
e = p;
}
- if (has_mbyte) {
- len = (size_t)(*mb_ptr2len)(path_end);
- memcpy(p, path_end, len);
- p += len;
- path_end += len;
- } else
- *p++ = *path_end++;
+ len = (size_t)(utfc_ptr2len(path_end));
+ memcpy(p, path_end, len);
+ p += len;
+ path_end += len;
}
e = p;
*e = NUL;
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 2f5491fda5..81a1a68a94 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -94,8 +94,8 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
*/
size_t length = 1; // count the trailing NUL
for (const char_u *p = string; *p; p++) {
- size_t l;
- if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
+ const size_t l = (size_t)(utfc_ptr2len(p));
+ if (l > 1) {
length += l; // count a multibyte char
p += l - 1;
continue;
@@ -108,8 +108,8 @@ char_u *vim_strsave_escaped_ext(const char_u *string, const char_u *esc_chars,
char_u *escaped_string = xmalloc(length);
char_u *p2 = escaped_string;
for (const char_u *p = string; *p; p++) {
- size_t l;
- if (has_mbyte && (l = (size_t)(*mb_ptr2len)(p)) > 1) {
+ const size_t l = (size_t)(utfc_ptr2len(p));
+ if (l > 1) {
memcpy(p2, p, l);
p2 += l;
p += l - 1; /* skip multibyte char */
@@ -349,7 +349,7 @@ char *strcase_save(const char *const orig, bool upper)
// thus it's OK to do another malloc()/free().
int newl = utf_char2len(uc);
if (newl != l) {
- // TODO(philix): use xrealloc() in strup_save()
+ // TODO(philix): use xrealloc() in strcase_save()
char *s = xmalloc(STRLEN(res) + (size_t)(1 + newl - l));
memcpy(s, res, (size_t)(p - res));
STRCPY(s + (p - res) + newl, p + l);