aboutsummaryrefslogtreecommitdiff
path: root/src/nvim/search.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/nvim/search.c')
-rw-r--r--src/nvim/search.c98
1 files changed, 34 insertions, 64 deletions
diff --git a/src/nvim/search.c b/src/nvim/search.c
index d635763acc..b09931b337 100644
--- a/src/nvim/search.c
+++ b/src/nvim/search.c
@@ -360,17 +360,16 @@ int ignorecase_opt(char_u *pat, int ic_in, int scs)
return ic;
}
-/*
- * Return TRUE if pattern "pat" has an uppercase character.
- */
-int pat_has_uppercase(char_u *pat)
+/// Returns true if pattern `pat` has an uppercase character.
+bool pat_has_uppercase(char_u *pat)
+ FUNC_ATTR_NONNULL_ALL
{
char_u *p = pat;
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))) {
return true;
}
@@ -391,7 +390,7 @@ int pat_has_uppercase(char_u *pat)
p++;
}
}
- return FALSE;
+ return false;
}
const char *last_csearch(void)
@@ -744,37 +743,29 @@ int searchit(
} else
break;
- /*
- * We found a valid match, now check if there is
- * another one after it.
- * If vi-compatible searching, continue at the end
- * of the match, otherwise continue one position
- * forward.
- */
+ // We found a valid match, now check if there is
+ // another one after it.
+ // If vi-compatible searching, continue at the end
+ // of the match, otherwise continue one position
+ // forward.
if (vim_strchr(p_cpo, CPO_SEARCH) != NULL) {
- if (nmatched > 1)
+ if (nmatched > 1) {
break;
+ }
matchcol = endpos.col;
- /* for empty match: advance one char */
+ // for empty match: advance one char
if (matchcol == matchpos.col
&& ptr[matchcol] != NUL) {
- if (has_mbyte)
- matchcol +=
- (*mb_ptr2len)(ptr + matchcol);
- else
- ++matchcol;
+ matchcol += mb_ptr2len(ptr + matchcol);
}
} else {
- /* Stop when the match is in a next line. */
- if (matchpos.lnum > 0)
+ // Stop when the match is in a next line.
+ if (matchpos.lnum > 0) {
break;
+ }
matchcol = matchpos.col;
if (ptr[matchcol] != NUL) {
- if (has_mbyte)
- matchcol +=
- (*mb_ptr2len)(ptr + matchcol);
- else
- ++matchcol;
+ matchcol += mb_ptr2len(ptr + matchcol);
}
}
if (ptr[matchcol] == NUL
@@ -3229,37 +3220,18 @@ static int in_html_tag(int end_tag)
int lc = NUL;
pos_T pos;
- if (enc_dbcs) {
- char_u *lp = NULL;
-
- /* We search forward until the cursor, because searching backwards is
- * very slow for DBCS encodings. */
- for (p = line; p < line + curwin->w_cursor.col; MB_PTR_ADV(p)) {
- if (*p == '>' || *p == '<') {
- lc = *p;
- lp = p;
- }
- }
- if (*p != '<') { // check for '<' under cursor
- if (lc != '<') {
- return false;
- }
- p = lp;
- }
- } else {
- for (p = line + curwin->w_cursor.col; p > line; ) {
- if (*p == '<') { // find '<' under/before cursor
- break;
- }
- MB_PTR_BACK(line, p);
- if (*p == '>') { // find '>' before cursor
- break;
- }
+ for (p = line + curwin->w_cursor.col; p > line; ) {
+ if (*p == '<') { // find '<' under/before cursor
+ break;
}
- if (*p != '<') {
- return false;
+ MB_PTR_BACK(line, p);
+ if (*p == '>') { // find '>' before cursor
+ break;
}
}
+ if (*p != '<') {
+ return false;
+ }
pos.lnum = curwin->w_cursor.lnum;
pos.col = (colnr_T)(p - line);
@@ -3655,16 +3627,14 @@ find_next_quote(
for (;; ) {
c = line[col];
- if (c == NUL)
+ if (c == NUL) {
return -1;
- else if (escape != NULL && vim_strchr(escape, c))
- ++col;
- else if (c == quotechar)
+ } else if (escape != NULL && vim_strchr(escape, c)) {
+ col++;
+ } else if (c == quotechar) {
break;
- if (has_mbyte)
- col += (*mb_ptr2len)(line + col);
- else
- ++col;
+ }
+ col += mb_ptr2len(line + col);
}
return col;
}