diff options
author | ZviRackover <zvirack@gmail.com> | 2018-06-30 16:21:37 +0300 |
---|---|---|
committer | ZviRackover <zvirack@gmail.com> | 2018-08-06 20:48:07 +0300 |
commit | 071aab51488e03a0e09a0a60aec6c0abc0277279 (patch) | |
tree | 6323eb69ad229bb7c9c43ee26c4fa566ef6fd6f8 | |
parent | cd3b2e4b6bea9501b3bd7ddf7b4d7ca31f1e6dd5 (diff) | |
download | rneovim-071aab51488e03a0e09a0a60aec6c0abc0277279.tar.gz rneovim-071aab51488e03a0e09a0a60aec6c0abc0277279.tar.bz2 rneovim-071aab51488e03a0e09a0a60aec6c0abc0277279.zip |
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.
-rw-r--r-- | src/nvim/cursor.c | 5 | ||||
-rw-r--r-- | src/nvim/edit.c | 22 | ||||
-rw-r--r-- | src/nvim/misc1.c | 28 | ||||
-rw-r--r-- | src/nvim/regexp.c | 115 | ||||
-rw-r--r-- | src/nvim/regexp_nfa.c | 9 | ||||
-rw-r--r-- | src/nvim/search.c | 4 | ||||
-rw-r--r-- | src/nvim/spell.c | 188 | ||||
-rw-r--r-- | src/nvim/syntax.c | 10 |
8 files changed, 121 insertions, 260 deletions
diff --git a/src/nvim/cursor.c b/src/nvim/cursor.c index a7f2f5a247..0fda941a51 100644 --- a/src/nvim/cursor.c +++ b/src/nvim/cursor.c @@ -476,10 +476,7 @@ bool leftcol_changed(void) int gchar_cursor(void) { - if (has_mbyte) { - return utf_ptr2char(get_cursor_pos_ptr()); - } - return (int)(*get_cursor_pos_ptr()); + return utf_ptr2char(get_cursor_pos_ptr()); } /* diff --git a/src/nvim/edit.c b/src/nvim/edit.c index 281f26c9df..b5c702828c 100644 --- a/src/nvim/edit.c +++ b/src/nvim/edit.c @@ -2311,24 +2311,14 @@ static void ins_compl_longest_match(compl_T *match) p = compl_leader; s = match->cp_str; while (*p != NUL) { - if (has_mbyte) { - c1 = utf_ptr2char(p); - c2 = utf_ptr2char(s); - } else { - c1 = *p; - c2 = *s; - } - if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2)) - : (c1 != c2)) { + c1 = utf_ptr2char(p); + c2 = utf_ptr2char(s); + + if (match->cp_icase ? (mb_tolower(c1) != mb_tolower(c2)) : (c1 != c2)) { break; } - if (has_mbyte) { - MB_PTR_ADV(p); - MB_PTR_ADV(s); - } else { - ++p; - ++s; - } + MB_PTR_ADV(p); + MB_PTR_ADV(s); } if (*p != NUL) { diff --git a/src/nvim/misc1.c b/src/nvim/misc1.c index 01f9cb9e32..72490a376f 100644 --- a/src/nvim/misc1.c +++ b/src/nvim/misc1.c @@ -701,13 +701,12 @@ open_line ( replace_push(NUL); /* end of extra blanks */ if (curbuf->b_p_ai || (flags & OPENLINE_DELSPACES)) { while ((*p_extra == ' ' || *p_extra == '\t') - && (!enc_utf8 - || !utf_iscomposing(utf_ptr2char(p_extra + 1))) - ) { - if (REPLACE_NORMAL(State)) + && !utf_iscomposing(utf_ptr2char(p_extra + 1))) { + if (REPLACE_NORMAL(State)) { replace_push(*p_extra); - ++p_extra; - ++less_cols_off; + } + p_extra++; + less_cols_off++; } } if (*p_extra != NUL) { @@ -1749,12 +1748,7 @@ del_lines ( int gchar_pos(pos_T *pos) { - char_u *ptr = ml_get_pos(pos); - - if (has_mbyte) { - return utf_ptr2char(ptr); - } - return (int)(*ptr); + return utf_ptr2char(ml_get_pos(pos)); } /* @@ -2390,12 +2384,12 @@ int get_keystroke(void) } break; } - if (has_mbyte) { - if (MB_BYTE2LEN(n) > len) - continue; /* more bytes to get */ - buf[len >= buflen ? buflen - 1 : len] = NUL; - n = utf_ptr2char(buf); + if (MB_BYTE2LEN(n) > len) { + // more bytes to get. + continue; } + buf[len >= buflen ? buflen - 1 : len] = NUL; + n = utf_ptr2char(buf); #ifdef UNIX if (n == intr_char) n = ESC; 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 */ diff --git a/src/nvim/regexp_nfa.c b/src/nvim/regexp_nfa.c index 1a44a6119e..0e0ebdd64b 100644 --- a/src/nvim/regexp_nfa.c +++ b/src/nvim/regexp_nfa.c @@ -5033,13 +5033,8 @@ static int nfa_regmatch(nfa_regprog_T *prog, nfa_state_T *start, int curc; int clen; - if (has_mbyte) { - curc = utf_ptr2char(reginput); - clen = (*mb_ptr2len)(reginput); - } else { - curc = *reginput; - clen = 1; - } + curc = utf_ptr2char(reginput); + clen = utfc_ptr2len(reginput); if (curc == NUL) { clen = 0; go_to_nextline = false; diff --git a/src/nvim/search.c b/src/nvim/search.c index 472b98a501..95929f0eb4 100644 --- a/src/nvim/search.c +++ b/src/nvim/search.c @@ -1120,8 +1120,8 @@ int do_search( msgbuf = xmalloc(STRLEN(p) + 40); { msgbuf[0] = dirc; - if (enc_utf8 && utf_iscomposing(utf_ptr2char(p))) { - /* Use a space to draw the composing char on. */ + if (utf_iscomposing(utf_ptr2char(p))) { + // Use a space to draw the composing char on. msgbuf[1] = ' '; STRCPY(msgbuf + 2, p); } else diff --git a/src/nvim/spell.c b/src/nvim/spell.c index 3d393acadb..80406e5329 100644 --- a/src/nvim/spell.c +++ b/src/nvim/spell.c @@ -2619,16 +2619,11 @@ static bool spell_iswordp(char_u *p, win_T *wp) // Unlike spell_iswordp() this doesn't check for "midword" characters. bool spell_iswordp_nmw(const char_u *p, win_T *wp) { - int c; - - if (has_mbyte) { - c = utf_ptr2char(p); - if (c > 255) { - return spell_mb_isword_class(mb_get_class(p), wp); - } - return spelltab.st_isw[c]; + int c = utf_ptr2char(p); + if (c > 255) { + return spell_mb_isword_class(mb_get_class(p), wp); } - return spelltab.st_isw[*p]; + return spelltab.st_isw[c]; } // Returns true if word class indicates a word character. @@ -4316,7 +4311,7 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so && sp->ts_twordlen > sp->ts_tcharlen) { p = tword + sp->ts_twordlen - sp->ts_tcharlen; c = utf_ptr2char(p); - if (enc_utf8 && utf_iscomposing(c)) { + if (utf_iscomposing(c)) { // Inserting a composing char doesn't // count that much. sp->ts_score -= SCORE_INS - SCORE_INSCOMP; @@ -4388,19 +4383,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so // score if the same character is following "nn" -> "n". It's // a bit illogical for soundfold tree but it does give better // results. - if (has_mbyte) { - c = utf_ptr2char(fword + sp->ts_fidx); - stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); - if (enc_utf8 && utf_iscomposing(c)) { - stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; - } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { - stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; - } - } else { - ++stack[depth].ts_fidx; - if (fword[sp->ts_fidx] == fword[sp->ts_fidx + 1]) - stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; + c = utf_ptr2char(fword + sp->ts_fidx); + stack[depth].ts_fidx += MB_PTR2LEN(fword + sp->ts_fidx); + if (utf_iscomposing(c)) { + stack[depth].ts_score -= SCORE_DEL - SCORE_DELCOMP; + } else if (c == utf_ptr2char(fword + stack[depth].ts_fidx)) { + stack[depth].ts_score -= SCORE_DEL - SCORE_DELDUP; } + break; } // FALLTHROUGH @@ -4515,24 +4505,14 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so break; } - if (has_mbyte) { - n = MB_CPTR2LEN(p); - c = utf_ptr2char(p); - if (p[n] == NUL) { - c2 = NUL; - } else if (!soundfold && !spell_iswordp(p + n, curwin)) { - c2 = c; // don't swap non-word char - } else { - c2 = utf_ptr2char(p + n); - } + n = MB_CPTR2LEN(p); + c = utf_ptr2char(p); + if (p[n] == NUL) { + c2 = NUL; + } else if (!soundfold && !spell_iswordp(p + n, curwin)) { + c2 = c; // don't swap non-word char } else { - if (p[1] == NUL) { - c2 = NUL; - } else if (!soundfold && !spell_iswordp(p + 1, curwin)) { - c2 = c; // don't swap non-word char - } else { - c2 = p[1]; - } + c2 = utf_ptr2char(p + n); } // When the second character is NUL we can't swap. @@ -4578,39 +4558,25 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP: // Undo the STATE_SWAP swap: "21" -> "12". p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - c = utf_ptr2char(p + n); - memmove(p + MB_PTR2LEN(p + n), p, n); - mb_char2bytes(c, p); - } else { - c = *p; - *p = p[1]; - p[1] = c; - } + n = MB_PTR2LEN(p); + c = utf_ptr2char(p + n); + memmove(p + MB_PTR2LEN(p + n), p, n); + mb_char2bytes(c, p); + // FALLTHROUGH case STATE_SWAP3: // Swap two bytes, skipping one: "123" -> "321". We change // "fword" here, it's changed back afterwards at STATE_UNSWAP3. p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_CPTR2LEN(p); - c = utf_ptr2char(p); - fl = MB_CPTR2LEN(p + n); - c2 = utf_ptr2char(p + n); - if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { - c3 = c; // don't swap non-word char - } else { - c3 = utf_ptr2char(p + n + fl); - } + n = MB_CPTR2LEN(p); + c = utf_ptr2char(p); + fl = MB_CPTR2LEN(p + n); + c2 = utf_ptr2char(p + n); + if (!soundfold && !spell_iswordp(p + n + fl, curwin)) { + c3 = c; // don't swap non-word char } else { - c = *p; - c2 = p[1]; - if (!soundfold && !spell_iswordp(p + 2, curwin)) - c3 = c; // don't swap non-word char - else - c3 = p[2]; + c3 = utf_ptr2char(p + n + fl); } // When characters are identical: "121" then SWAP3 result is @@ -4654,22 +4620,15 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNSWAP3: // Undo STATE_SWAP3: "321" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - c2 = utf_ptr2char(p + n); - fl = MB_PTR2LEN(p + n); - c = utf_ptr2char(p + n + fl); - tl = MB_PTR2LEN(p + n + fl); - memmove(p + fl + tl, p, n); - mb_char2bytes(c, p); - mb_char2bytes(c2, p + tl); - p = p + tl; - } else { - c = *p; - *p = p[2]; - p[2] = c; - ++p; - } + n = MB_PTR2LEN(p); + c2 = utf_ptr2char(p + n); + fl = MB_PTR2LEN(p + n); + c = utf_ptr2char(p + n + fl); + tl = MB_PTR2LEN(p + n + fl); + memmove(p + fl + tl, p, n); + mb_char2bytes(c, p); + mb_char2bytes(c2, p + tl); + p = p + tl; if (!soundfold && !spell_iswordp(p, curwin)) { // Middle char is not a word char, skip the rotate. First and @@ -4717,19 +4676,12 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3L: // Undo ROT3L: "231" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_PTR2LEN(p); - n += MB_PTR2LEN(p + n); - c = utf_ptr2char(p + n); - tl = MB_PTR2LEN(p + n); - memmove(p + tl, p, n); - mb_char2bytes(c, p); - } else { - c = p[2]; - p[2] = p[1]; - p[1] = *p; - *p = c; - } + n = MB_PTR2LEN(p); + n += MB_PTR2LEN(p + n); + c = utf_ptr2char(p + n); + tl = MB_PTR2LEN(p + n); + memmove(p + tl, p, n); + mb_char2bytes(c, p); // Rotate three bytes right: "123" -> "312". We change "fword" // here, it's changed back afterwards at STATE_UNROT3R. @@ -4745,21 +4697,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so sp->ts_state = STATE_UNROT3R; ++depth; p = fword + sp->ts_fidx; - if (has_mbyte) { - n = MB_CPTR2LEN(p); - n += MB_CPTR2LEN(p + n); - c = utf_ptr2char(p + n); - tl = MB_CPTR2LEN(p + n); - memmove(p + tl, p, n); - mb_char2bytes(c, p); - stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; - } else { - c = p[2]; - p[2] = p[1]; - p[1] = *p; - *p = c; - stack[depth].ts_fidxtry = sp->ts_fidx + 3; - } + n = MB_CPTR2LEN(p); + n += MB_CPTR2LEN(p + n); + c = utf_ptr2char(p + n); + tl = MB_CPTR2LEN(p + n); + memmove(p + tl, p, n); + mb_char2bytes(c, p); + stack[depth].ts_fidxtry = sp->ts_fidx + n + tl; } else { PROF_STORE(sp->ts_state) sp->ts_state = STATE_REP_INI; @@ -4769,19 +4713,13 @@ static void suggest_trie_walk(suginfo_T *su, langp_T *lp, char_u *fword, bool so case STATE_UNROT3R: // Undo ROT3R: "312" -> "123" p = fword + sp->ts_fidx; - if (has_mbyte) { - c = utf_ptr2char(p); - tl = MB_PTR2LEN(p); - n = MB_PTR2LEN(p + tl); - n += MB_PTR2LEN(p + tl + n); - memmove(p, p + tl, n); - mb_char2bytes(c, p + n); - } else { - c = *p; - *p = p[1]; - p[1] = p[2]; - p[2] = c; - } + c = utf_ptr2char(p); + tl = MB_PTR2LEN(p); + n = MB_PTR2LEN(p + tl); + n += MB_PTR2LEN(p + tl + n); + memmove(p, p + tl, n); + mb_char2bytes(c, p + n); + // FALLTHROUGH case STATE_REP_INI: @@ -5666,11 +5604,7 @@ add_suggestion ( break; MB_PTR_BACK(goodword, pgood); MB_PTR_BACK(su->su_badptr, pbad); - if (has_mbyte) { - if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { - break; - } - } else if (*pgood != *pbad) { + if (utf_ptr2char(pgood) != utf_ptr2char(pbad)) { break; } } diff --git a/src/nvim/syntax.c b/src/nvim/syntax.c index 2f142e65c9..d7c23742ba 100644 --- a/src/nvim/syntax.c +++ b/src/nvim/syntax.c @@ -4101,13 +4101,9 @@ get_syn_options( return NULL; } } else if (flagtab[fidx].argtype == 11 && arg[5] == '=') { - /* cchar=? */ - if (has_mbyte) { - *conceal_char = utf_ptr2char(arg + 6); - arg += mb_ptr2len(arg + 6) - 1; - } else { - *conceal_char = arg[6]; - } + // cchar=? + *conceal_char = utf_ptr2char(arg + 6); + arg += mb_ptr2len(arg + 6) - 1; if (!vim_isprintc_strict(*conceal_char)) { EMSG(_("E844: invalid cchar value")); return NULL; |