aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/eval/funcs.c
diff options
context:
space:
mode:
authorMatthieu Coudron <mattator@gmail.com>2020-11-14 19:35:26 +0100
committerGitHub <noreply@github.com>2020-11-14 19:35:26 +0100
commit27d630926cab78511075159012ce6ac920d8747e (patch)
treedb9afbe90762056b2f2c538744ce04d571108b89 /src/nvim/eval/funcs.c
parentd8c69adbabe963142f433a2ddad172ff46413f15 (diff)
parent5d6ecfa3c7447009da75842c611ea1b9f1db83e7 (diff)
downloadrneovim-27d630926cab78511075159012ce6ac920d8747e.tar.gz
rneovim-27d630926cab78511075159012ce6ac920d8747e.tar.bz2
rneovim-27d630926cab78511075159012ce6ac920d8747e.zip
Merge pull request #13275 from janlazo/vim-8.1.0805
vim-patch:8.1.{805,806,809,810,811}
Diffstat (limited to 'src/nvim/eval/funcs.c')
-rw-r--r--src/nvim/eval/funcs.c113
1 files changed, 44 insertions, 69 deletions
diff --git a/src/nvim/eval/funcs.c b/src/nvim/eval/funcs.c
index 679548ab91..eee40965e0 100644
--- a/src/nvim/eval/funcs.c
+++ b/src/nvim/eval/funcs.c
@@ -783,10 +783,10 @@ static void byteidx(typval_T *argvars, typval_T *rettv, int comp)
if (*t == NUL) { // EOL reached.
return;
}
- if (enc_utf8 && comp) {
+ if (comp) {
t += utf_ptr2len((const char_u *)t);
} else {
- t += (*mb_ptr2len)((const char_u *)t);
+ t += utfc_ptr2len((const char_u *)t);
}
}
rettv->vval.v_number = (varnumber_T)(t - str);
@@ -1427,9 +1427,7 @@ static void f_cursor(typval_T *argvars, typval_T *rettv, FunPtr fptr)
// Make sure the cursor is in a valid position.
check_cursor();
// Correct cursor for multi-byte character.
- if (has_mbyte) {
- mb_adjust_cursor();
- }
+ mb_adjust_cursor();
curwin->w_set_curswant = set_curswant;
rettv->vval.v_number = 0;
@@ -4198,7 +4196,7 @@ static void f_has(typval_T *argvars, typval_T *rettv, FunPtr fptr)
} else if (STRICMP(name, "ttyout") == 0) {
n = stdout_isatty;
} else if (STRICMP(name, "multi_byte_encoding") == 0) {
- n = has_mbyte != 0;
+ n = true;
} else if (STRICMP(name, "syntax_items") == 0) {
n = syntax_present(curwin);
#ifdef UNIX
@@ -8025,14 +8023,9 @@ static void f_setcharsearch(typval_T *argvars, typval_T *rettv, FunPtr fptr)
if ((d = argvars[0].vval.v_dict) != NULL) {
char_u *const csearch = (char_u *)tv_dict_get_string(d, "char", false);
if (csearch != NULL) {
- if (enc_utf8) {
- int pcc[MAX_MCO];
- int c = utfc_ptr2char(csearch, pcc);
- set_last_csearch(c, csearch, utfc_ptr2len(csearch));
- }
- else
- set_last_csearch(PTR2CHAR(csearch),
- csearch, utfc_ptr2len(csearch));
+ int pcc[MAX_MCO];
+ const int c = utfc_ptr2char(csearch, pcc);
+ set_last_csearch(c, csearch, utfc_ptr2len(csearch));
}
di = tv_dict_find(d, S_LEN("forward"));
@@ -10711,72 +10704,54 @@ static void f_tr(typval_T *argvars, typval_T *rettv, FunPtr fptr)
garray_T ga;
ga_init(&ga, (int)sizeof(char), 80);
- if (!has_mbyte) {
- // Not multi-byte: fromstr and tostr must be the same length.
- if (strlen(fromstr) != strlen(tostr)) {
- goto error;
- }
- }
-
// fromstr and tostr have to contain the same number of chars.
bool first = true;
while (*in_str != NUL) {
- if (has_mbyte) {
- const char *cpstr = in_str;
- const int inlen = (*mb_ptr2len)((const char_u *)in_str);
- int cplen = inlen;
- int idx = 0;
- int fromlen;
- for (const char *p = fromstr; *p != NUL; p += fromlen) {
- fromlen = (*mb_ptr2len)((const char_u *)p);
- if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) {
- int tolen;
- for (p = tostr; *p != NUL; p += tolen) {
- tolen = (*mb_ptr2len)((const char_u *)p);
- if (idx-- == 0) {
- cplen = tolen;
- cpstr = (char *)p;
- break;
- }
- }
- if (*p == NUL) { // tostr is shorter than fromstr.
- goto error;
- }
- break;
- }
- idx++;
- }
-
- if (first && cpstr == in_str) {
- // Check that fromstr and tostr have the same number of
- // (multi-byte) characters. Done only once when a character
- // of in_str doesn't appear in fromstr.
- first = false;
+ const char *cpstr = in_str;
+ const int inlen = utfc_ptr2len((const char_u *)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);
+ if (fromlen == inlen && STRNCMP(in_str, p, inlen) == 0) {
int tolen;
- for (const char *p = tostr; *p != NUL; p += tolen) {
- tolen = (*mb_ptr2len)((const char_u *)p);
- idx--;
+ for (p = tostr; *p != NUL; p += tolen) {
+ tolen = utfc_ptr2len((const char_u *)p);
+ if (idx-- == 0) {
+ cplen = tolen;
+ cpstr = (char *)p;
+ break;
+ }
}
- if (idx != 0) {
+ if (*p == NUL) { // tostr is shorter than fromstr.
goto error;
}
+ break;
}
+ idx++;
+ }
- ga_grow(&ga, cplen);
- memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
- ga.ga_len += cplen;
-
- in_str += inlen;
- } else {
- // When not using multi-byte chars we can do it faster.
- const char *const p = strchr(fromstr, *in_str);
- if (p != NULL) {
- ga_append(&ga, tostr[p - fromstr]);
- } else {
- ga_append(&ga, *in_str);
+ if (first && cpstr == in_str) {
+ // Check that fromstr and tostr have the same number of
+ // (multi-byte) characters. Done only once when a character
+ // of in_str doesn't appear in fromstr.
+ first = false;
+ int tolen;
+ for (const char *p = tostr; *p != NUL; p += tolen) {
+ tolen = utfc_ptr2len((const char_u *)p);
+ idx--;
+ }
+ if (idx != 0) {
+ goto error;
}
- in_str++;
}
+
+ ga_grow(&ga, cplen);
+ memmove((char *)ga.ga_data + ga.ga_len, cpstr, (size_t)cplen);
+ ga.ga_len += cplen;
+
+ in_str += inlen;
}
// add a terminating NUL