From 10b6afd652a896144d87fb0db4389001293e7973 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Fri, 29 Jun 2018 22:31:20 +0300 Subject: Remove all occurences of the mb_ptr2char macro First step towards implemening issue #7401. The same can be done for all deprecated mb_ functions in follow-up patches. --- src/nvim/regexp.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index d76da62c6d..ca4db722ad 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -776,7 +776,7 @@ static int get_equi_class(char_u **pp) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { if (has_mbyte) - c = mb_ptr2char(p + 2); + c = utf_ptr2char(p + 2); else c = p[2]; *pp += l + 4; @@ -1111,7 +1111,7 @@ static int get_coll_element(char_u **pp) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { if (has_mbyte) - c = mb_ptr2char(p + 2); + c = utf_ptr2char(p + 2); else c = p[2]; *pp += l + 4; @@ -1300,7 +1300,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) if (OP(scan) == EXACTLY) { if (has_mbyte) - r->regstart = (*mb_ptr2char)(OPERAND(scan)); + r->regstart = utf_ptr2char(OPERAND(scan)); else r->regstart = *OPERAND(scan); } else if (OP(scan) == BOW @@ -1311,7 +1311,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { if (has_mbyte) - r->regstart = (*mb_ptr2char)(OPERAND(regnext_scan)); + r->regstart = utf_ptr2char(OPERAND(regnext_scan)); else r->regstart = *OPERAND(regnext_scan); } @@ -2417,7 +2417,7 @@ collection: /* produce a multibyte character, including any * following composing characters */ - startc = mb_ptr2char(regparse); + startc = utf_ptr2char(regparse); len = (*mb_ptr2len)(regparse); if (enc_utf8 && utf_char2len(startc) != len) startc = -1; /* composing chars */ @@ -2907,7 +2907,7 @@ static int peekchr(void) * Then backslashing it won't do anything. */ if (has_mbyte) - curchr = (*mb_ptr2char)(regparse + 1); + curchr = utf_ptr2char(regparse + 1); else curchr = c; } @@ -2916,7 +2916,7 @@ static int peekchr(void) default: if (has_mbyte) - curchr = (*mb_ptr2char)(regparse); + curchr = utf_ptr2char(regparse); } return curchr; @@ -3469,7 +3469,7 @@ static long bt_regexec_both(char_u *line, int c; if (has_mbyte) - c = (*mb_ptr2char)(prog->regmust); + c = utf_ptr2char(prog->regmust); else c = *prog->regmust; s = line + col; @@ -3505,7 +3505,7 @@ static long bt_regexec_both(char_u *line, int c; if (has_mbyte) - c = (*mb_ptr2char)(regline + col); + c = utf_ptr2char(regline + col); else c = regline[col]; if (prog->regstart == NUL @@ -3861,7 +3861,7 @@ regmatch ( if (WITH_NL(op)) op -= ADD_NL; if (has_mbyte) - c = (*mb_ptr2char)(reginput); + c = utf_ptr2char(reginput); else c = *reginput; switch (op) { @@ -5474,7 +5474,7 @@ do_class: } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; } else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) { - if ((cstrchr(opnd, (*mb_ptr2char)(scan)) == NULL) == testval) { + if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { break; } scan += len; @@ -6783,7 +6783,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, c = *src++; } } else if (has_mbyte) - c = mb_ptr2char(src - 1); + c = utf_ptr2char(src - 1); /* Write to buffer, if copy is set. */ if (func_one != (fptr_T)NULL) @@ -6879,7 +6879,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, dst += 2; } else { if (has_mbyte) - c = mb_ptr2char(s); + c = utf_ptr2char(s); else c = *s; -- cgit From cd3b2e4b6bea9501b3bd7ddf7b4d7ca31f1e6dd5 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sat, 30 Jun 2018 13:29:09 +0300 Subject: lint: clean-up after parent commit --- src/nvim/regexp.c | 51 +++++++++++++++++++++++++++++++-------------------- 1 file changed, 31 insertions(+), 20 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index ca4db722ad..1b711bd881 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -775,10 +775,11 @@ static int get_equi_class(char_u **pp) if (has_mbyte) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(p + 2); - else + } else { c = p[2]; + } *pp += l + 4; return c; } @@ -1110,10 +1111,11 @@ static int get_coll_element(char_u **pp) if (has_mbyte) l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(p + 2); - else + } else { c = p[2]; + } *pp += l + 4; return c; } @@ -1299,10 +1301,11 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) } if (OP(scan) == EXACTLY) { - if (has_mbyte) + if (has_mbyte) { r->regstart = utf_ptr2char(OPERAND(scan)); - else + } else { r->regstart = *OPERAND(scan); + } } else if (OP(scan) == BOW || OP(scan) == EOW || OP(scan) == NOTHING @@ -1310,10 +1313,11 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { - if (has_mbyte) + if (has_mbyte) { r->regstart = utf_ptr2char(OPERAND(regnext_scan)); - else + } else { r->regstart = *OPERAND(regnext_scan); + } } } @@ -2906,17 +2910,19 @@ static int peekchr(void) * Next character can never be (made) magic? * Then backslashing it won't do anything. */ - if (has_mbyte) + if (has_mbyte) { curchr = utf_ptr2char(regparse + 1); - else + } else { curchr = c; + } } break; } default: - if (has_mbyte) + if (has_mbyte) { curchr = utf_ptr2char(regparse); + } } return curchr; @@ -3468,10 +3474,11 @@ static long bt_regexec_both(char_u *line, if (prog->regmust != NULL) { int c; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(prog->regmust); - else + } else { c = *prog->regmust; + } s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -3504,10 +3511,11 @@ static long bt_regexec_both(char_u *line, if (prog->reganch) { int c; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(regline + col); - else + } else { c = regline[col]; + } if (prog->regstart == NUL || prog->regstart == c || (rex.reg_ic @@ -3860,10 +3868,11 @@ regmatch ( } else { if (WITH_NL(op)) op -= ADD_NL; - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(reginput); - else + } else { c = *reginput; + } switch (op) { case BOL: if (reginput != regline) @@ -6782,8 +6791,9 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } c = *src++; } - } else if (has_mbyte) + } else if (has_mbyte) { c = utf_ptr2char(src - 1); + } /* Write to buffer, if copy is set. */ if (func_one != (fptr_T)NULL) @@ -6878,10 +6888,11 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } dst += 2; } else { - if (has_mbyte) + if (has_mbyte) { c = utf_ptr2char(s); - else + } else { c = *s; + } if (func_one != (fptr_T)NULL) /* Turbo C complains without the typecast */ -- cgit From 071aab51488e03a0e09a0a60aec6c0abc0277279 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sat, 30 Jun 2018 16:21:37 +0300 Subject: Remove some occrrences of enc_utf8 and has_mbyte Removing uses and related dead code in the locallity of changes of the two parent commits. --- src/nvim/regexp.c | 115 +++++++++++++++++------------------------------------- 1 file changed, 35 insertions(+), 80 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index 1b711bd881..a4fb16280c 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -772,14 +772,9 @@ static int get_equi_class(char_u **pp) char_u *p = *pp; if (p[1] == '=') { - if (has_mbyte) - l = (*mb_ptr2len)(p + 2); + l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '=' && p[l + 3] == ']') { - if (has_mbyte) { - c = utf_ptr2char(p + 2); - } else { - c = p[2]; - } + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -1108,14 +1103,9 @@ static int get_coll_element(char_u **pp) char_u *p = *pp; if (p[0] != NUL && p[1] == '.') { - if (has_mbyte) - l = (*mb_ptr2len)(p + 2); + l = (*mb_ptr2len)(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { - if (has_mbyte) { - c = utf_ptr2char(p + 2); - } else { - c = p[2]; - } + c = utf_ptr2char(p + 2); *pp += l + 4; return c; } @@ -1301,11 +1291,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) } if (OP(scan) == EXACTLY) { - if (has_mbyte) { - r->regstart = utf_ptr2char(OPERAND(scan)); - } else { - r->regstart = *OPERAND(scan); - } + r->regstart = utf_ptr2char(OPERAND(scan)); } else if (OP(scan) == BOW || OP(scan) == EOW || OP(scan) == NOTHING @@ -1313,11 +1299,7 @@ static regprog_T *bt_regcomp(char_u *expr, int re_flags) || OP(scan) == MCLOSE + 0 || OP(scan) == NCLOSE) { char_u *regnext_scan = regnext(scan); if (OP(regnext_scan) == EXACTLY) { - if (has_mbyte) { - r->regstart = utf_ptr2char(OPERAND(regnext_scan)); - } else { - r->regstart = *OPERAND(regnext_scan); - } + r->regstart = utf_ptr2char(OPERAND(regnext_scan)); } } @@ -2416,20 +2398,16 @@ collection: break; } } else { - if (has_mbyte) { - int len; - - /* produce a multibyte character, including any - * following composing characters */ - startc = utf_ptr2char(regparse); - len = (*mb_ptr2len)(regparse); - if (enc_utf8 && utf_char2len(startc) != len) - startc = -1; /* composing chars */ - while (--len >= 0) - regc(*regparse++); - } else { - startc = *regparse++; - regc(startc); + // produce a multibyte character, including any + // following composing characters. + startc = utf_ptr2char(regparse); + int len = utfc_ptr2len(regparse); + if (utf_char2len(startc) != len) { + // composing chars + startc = -1; + } + while (--len >= 0) { + regc(*regparse++); } } } @@ -2910,19 +2888,13 @@ static int peekchr(void) * Next character can never be (made) magic? * Then backslashing it won't do anything. */ - if (has_mbyte) { - curchr = utf_ptr2char(regparse + 1); - } else { - curchr = c; - } + curchr = utf_ptr2char(regparse + 1); } break; } default: - if (has_mbyte) { - curchr = utf_ptr2char(regparse); - } + curchr = utf_ptr2char(regparse); } return curchr; @@ -3474,11 +3446,7 @@ static long bt_regexec_both(char_u *line, if (prog->regmust != NULL) { int c; - if (has_mbyte) { - c = utf_ptr2char(prog->regmust); - } else { - c = *prog->regmust; - } + c = utf_ptr2char(prog->regmust); s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -3509,17 +3477,11 @@ static long bt_regexec_both(char_u *line, /* Simplest case: Anchored match need be tried only once. */ if (prog->reganch) { - int c; - - if (has_mbyte) { - c = utf_ptr2char(regline + col); - } else { - c = regline[col]; - } + int c = utf_ptr2char(regline + col); if (prog->regstart == NUL || prog->regstart == c || (rex.reg_ic - && (((enc_utf8 && utf_fold(prog->regstart) == utf_fold(c))) + && (utf_fold(prog->regstart) == utf_fold(c) || (c < 255 && prog->regstart < 255 && mb_tolower(prog->regstart) == mb_tolower(c))))) { retval = regtry(prog, col); @@ -3866,13 +3828,10 @@ regmatch ( } else if (rex.reg_line_lbr && WITH_NL(op) && *reginput == '\n') { ADVANCE_REGINPUT(); } else { - if (WITH_NL(op)) + if (WITH_NL(op)) { op -= ADD_NL; - if (has_mbyte) { - c = utf_ptr2char(reginput); - } else { - c = *reginput; } + c = utf_ptr2char(reginput); switch (op) { case BOL: if (reginput != regline) @@ -6791,20 +6750,20 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } c = *src++; } - } else if (has_mbyte) { + } else { c = utf_ptr2char(src - 1); } - - /* Write to buffer, if copy is set. */ - if (func_one != (fptr_T)NULL) - /* Turbo C complains without the typecast */ + // Write to buffer, if copy is set. + if (func_one != NULL) { func_one = (fptr_T)(func_one(&cc, c)); - else if (func_all != (fptr_T)NULL) - /* Turbo C complains without the typecast */ - func_all = (fptr_T)(func_all(&cc, c)); - else /* just copy */ - cc = c; - + } else { + if (func_all != NULL) { + func_all = (fptr_T)(func_all(&cc, c)); + } else { + // just copy + cc = c; + } + } if (has_mbyte) { int totlen = mb_ptr2len(src - 1); @@ -6888,11 +6847,7 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, } dst += 2; } else { - if (has_mbyte) { - c = utf_ptr2char(s); - } else { - c = *s; - } + c = utf_ptr2char(s); if (func_one != (fptr_T)NULL) /* Turbo C complains without the typecast */ -- cgit From 5cecd7a93aba83cd477519974fc33fadbdcfdc87 Mon Sep 17 00:00:00 2001 From: ZviRackover Date: Sun, 1 Jul 2018 22:58:42 +0300 Subject: style: fixing minor issues noted in code review. --- src/nvim/regexp.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) (limited to 'src/nvim/regexp.c') diff --git a/src/nvim/regexp.c b/src/nvim/regexp.c index a4fb16280c..be6c43493b 100644 --- a/src/nvim/regexp.c +++ b/src/nvim/regexp.c @@ -1103,7 +1103,7 @@ static int get_coll_element(char_u **pp) char_u *p = *pp; if (p[0] != NUL && p[1] == '.') { - l = (*mb_ptr2len)(p + 2); + l = utfc_ptr2len(p + 2); if (p[l + 2] == '.' && p[l + 3] == ']') { c = utf_ptr2char(p + 2); *pp += l + 4; @@ -3444,9 +3444,7 @@ static long bt_regexec_both(char_u *line, /* If there is a "must appear" string, look for it. */ if (prog->regmust != NULL) { - int c; - - c = utf_ptr2char(prog->regmust); + int c = utf_ptr2char(prog->regmust); s = line + col; // This is used very often, esp. for ":global". Use two versions of @@ -5441,7 +5439,7 @@ do_class: } } else if (rex.reg_line_lbr && *scan == '\n' && WITH_NL(OP(p))) { scan++; - } else if (has_mbyte && (len = (*mb_ptr2len)(scan)) > 1) { + } else if ((len = utfc_ptr2len(scan)) > 1) { if ((cstrchr(opnd, utf_ptr2char(scan)) == NULL) == testval) { break; } @@ -6756,14 +6754,13 @@ static int vim_regsub_both(char_u *source, typval_T *expr, char_u *dest, // Write to buffer, if copy is set. if (func_one != NULL) { func_one = (fptr_T)(func_one(&cc, c)); + } else if (func_all != NULL) { + func_all = (fptr_T)(func_all(&cc, c)); } else { - if (func_all != NULL) { - func_all = (fptr_T)(func_all(&cc, c)); - } else { - // just copy - cc = c; - } + // just copy + cc = c; } + if (has_mbyte) { int totlen = mb_ptr2len(src - 1); -- cgit