search.c: remove dead code #5307

has_mbyte is always true.
This commit is contained in:
Justin M. Keyes 2019-03-02 03:13:00 +01:00 committed by GitHub
parent ed4132d7e9
commit d44ab5fdea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 58 additions and 36 deletions

View File

@ -360,17 +360,16 @@ int ignorecase_opt(char_u *pat, int ic_in, int scs)
return ic; return ic;
} }
/* /// Returns true if pattern `pat` has an uppercase character.
* Return TRUE if pattern "pat" has an uppercase character. bool pat_has_uppercase(char_u *pat)
*/ FUNC_ATTR_NONNULL_ALL
int pat_has_uppercase(char_u *pat)
{ {
char_u *p = pat; char_u *p = pat;
while (*p != NUL) { 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))) { if (mb_isupper(utf_ptr2char(p))) {
return true; return true;
} }
@ -391,7 +390,7 @@ int pat_has_uppercase(char_u *pat)
p++; p++;
} }
} }
return FALSE; return false;
} }
const char *last_csearch(void) const char *last_csearch(void)
@ -744,37 +743,29 @@ int searchit(
} else } else
break; break;
/* // We found a valid match, now check if there is
* We found a valid match, now check if there is // another one after it.
* another one after it. // If vi-compatible searching, continue at the end
* If vi-compatible searching, continue at the end // of the match, otherwise continue one position
* of the match, otherwise continue one position // forward.
* forward.
*/
if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) { if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) {
if (nmatched > 1) if (nmatched > 1) {
break; break;
}
matchcol = endpos.col; matchcol = endpos.col;
/* for empty match: advance one char */ // for empty match: advance one char
if (matchcol == matchpos.col if (matchcol == matchpos.col
&& ptr[matchcol] != NUL) { && ptr[matchcol] != NUL) {
if (has_mbyte) matchcol += mb_ptr2len(ptr + matchcol);
matchcol +=
(*mb_ptr2len)(ptr + matchcol);
else
++matchcol;
} }
} else { } else {
/* Stop when the match is in a next line. */ // Stop when the match is in a next line.
if (matchpos.lnum > 0) if (matchpos.lnum > 0) {
break; break;
}
matchcol = matchpos.col; matchcol = matchpos.col;
if (ptr[matchcol] != NUL) { if (ptr[matchcol] != NUL) {
if (has_mbyte) matchcol += mb_ptr2len(ptr + matchcol);
matchcol +=
(*mb_ptr2len)(ptr + matchcol);
else
++matchcol;
} }
} }
if (ptr[matchcol] == NUL if (ptr[matchcol] == NUL
@ -3636,16 +3627,14 @@ find_next_quote(
for (;; ) { for (;; ) {
c = line[col]; c = line[col];
if (c == NUL) if (c == NUL) {
return -1; return -1;
else if (escape != NULL && vim_strchr(escape, c)) } else if (escape != NULL && vim_strchr(escape, c)) {
++col; col++;
else if (c == quotechar) } else if (c == quotechar) {
break; break;
if (has_mbyte) }
col += (*mb_ptr2len)(line + col); col += mb_ptr2len(line + col);
else
++col;
} }
return col; return col;
} }

33
test/unit/search_spec.lua Normal file
View File

@ -0,0 +1,33 @@
local helpers = require("test.unit.helpers")(after_each)
local itp = helpers.gen_itp(it)
local to_cstr = helpers.to_cstr
local eq = helpers.eq
local search = helpers.cimport("./src/nvim/search.h")
itp('pat_has_uppercase', function()
-- works on empty string
eq(false, search.pat_has_uppercase(to_cstr("")))
-- works with utf uppercase
eq(false, search.pat_has_uppercase(to_cstr("ä")))
eq(true, search.pat_has_uppercase(to_cstr("Ä")))
eq(true, search.pat_has_uppercase(to_cstr("äaÅ")))
-- works when pat ends with backslash
eq(false, search.pat_has_uppercase(to_cstr("\\")))
eq(false, search.pat_has_uppercase(to_cstr("ab$\\")))
-- skips escaped characters
eq(false, search.pat_has_uppercase(to_cstr("\\Ab")))
eq(true, search.pat_has_uppercase(to_cstr("\\AU")))
-- skips _X escaped characters
eq(false, search.pat_has_uppercase(to_cstr("\\_Ab")))
eq(true, search.pat_has_uppercase(to_cstr("\\_AU")))
-- skips %X escaped characters
eq(false, search.pat_has_uppercase(to_cstr("aa\\%Ab")))
eq(true, search.pat_has_uppercase(to_cstr("aab\\%AU")))
end)