aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorZviRackover <zvirack@gmail.com>2018-08-11 17:14:10 +0300
committerJustin M. Keyes <justinkz@gmail.com>2018-08-11 16:14:10 +0200
commit22311457ab60be9335f8e630c8b794340d39e466 (patch)
treeb0b1a1a32009fd80cfeb2b77ffeae9202b21bbff /src
parent6aefae8c4e6e273ae96f1135b74a081543b548e5 (diff)
downloadrneovim-22311457ab60be9335f8e630c8b794340d39e466.tar.gz
rneovim-22311457ab60be9335f8e630c8b794340d39e466.tar.bz2
rneovim-22311457ab60be9335f8e630c8b794340d39e466.zip
refactor: Replace vim_strrchr() with strrchar() (#8718)
ref #1474
Diffstat (limited to 'src')
-rw-r--r--src/nvim/edit.c6
-rw-r--r--src/nvim/ex_cmds.c13
-rw-r--r--src/nvim/ex_docmd.c11
-rw-r--r--src/nvim/path.c6
-rw-r--r--src/nvim/spellfile.c5
-rw-r--r--src/nvim/strings.c19
-rw-r--r--src/nvim/vim.h4
7 files changed, 28 insertions, 36 deletions
diff --git a/src/nvim/edit.c b/src/nvim/edit.c
index 0d99aa8fb2..6231ecd977 100644
--- a/src/nvim/edit.c
+++ b/src/nvim/edit.c
@@ -6398,8 +6398,10 @@ stuff_inserted (
/* may want to stuff the command character, to start Insert mode */
if (c != NUL)
stuffcharReadbuff(c);
- if ((esc_ptr = (char_u *)vim_strrchr(ptr, ESC)) != NULL)
- *esc_ptr = NUL; /* remove the ESC */
+ if ((esc_ptr = STRRCHR(ptr, ESC)) != NULL) {
+ // remove the ESC.
+ *esc_ptr = NUL;
+ }
/* when the last char is either "0" or "^" it will be quoted if no ESC
* comes after it OR if it will inserted more than once and "ptr"
diff --git a/src/nvim/ex_cmds.c b/src/nvim/ex_cmds.c
index 1420a9aae4..4dcecae9d8 100644
--- a/src/nvim/ex_cmds.c
+++ b/src/nvim/ex_cmds.c
@@ -307,9 +307,12 @@ static int linelen(int *has_tab)
;
save = *last;
*last = NUL;
- len = linetabsize(line); /* get line length */
- if (has_tab != NULL) /* check for embedded TAB */
- *has_tab = (vim_strrchr(first, TAB) != NULL);
+ // Get line length.
+ len = linetabsize(line);
+ // Check for embedded TAB.
+ if (has_tab != NULL) {
+ *has_tab = STRRCHR(first, TAB) != NULL;
+ }
*last = save;
return len;
@@ -5016,8 +5019,8 @@ void fix_help_buffer(void)
if (fnamencmp(f1, f2, t1 - f1) != 0) {
continue;
}
- const char_u *const e1 = vim_strrchr(t1, '.');
- const char_u *const e2 = vim_strrchr(path_tail(f2), '.');
+ const char_u *const e1 = STRRCHR(t1, '.');
+ const char_u *const e2 = STRRCHR(path_tail(f2), '.');
if (e1 == NULL || e2 == NULL) {
continue;
}
diff --git a/src/nvim/ex_docmd.c b/src/nvim/ex_docmd.c
index 3d3d02fd71..c31242f2ac 100644
--- a/src/nvim/ex_docmd.c
+++ b/src/nvim/ex_docmd.c
@@ -8607,11 +8607,14 @@ eval_vars (
break;
}
- resultlen = STRLEN(result); /* length of new string */
- if (src[*usedlen] == '<') { /* remove the file name extension */
- ++*usedlen;
- if ((s = vim_strrchr(result, '.')) != NULL && s >= path_tail(result))
+ // Length of new string.
+ resultlen = STRLEN(result);
+ // Remove the file name extension.
+ if (src[*usedlen] == '<') {
+ (*usedlen)++;
+ if ((s = STRRCHR(result, '.')) != NULL && s >= path_tail(result)) {
resultlen = (size_t)(s - result);
+ }
} else if (!skip_mod) {
valid |= modify_fname(src, usedlen, &result, &resultbuf, &resultlen);
if (result == NULL) {
diff --git a/src/nvim/path.c b/src/nvim/path.c
index 0b90329686..cc4a5f62a7 100644
--- a/src/nvim/path.c
+++ b/src/nvim/path.c
@@ -1770,7 +1770,7 @@ void path_fix_case(char_u *name)
}
// Open the directory where the file is located.
- char_u *slash = vim_strrchr(name, '/');
+ char_u *slash = STRRCHR(name, '/');
char_u *tail;
Directory dir;
bool ok;
@@ -2213,10 +2213,10 @@ static int path_to_absolute(const char_u *fname, char_u *buf, size_t len,
// expand it if forced or not an absolute path
if (force || !path_is_absolute(fname)) {
- p = vim_strrchr(fname, '/');
+ p = STRRCHR(fname, '/');
#ifdef WIN32
if (p == NULL) {
- p = vim_strrchr(fname, '\\');
+ p = STRRCHR(fname, '\\');
}
#endif
if (p != NULL) {
diff --git a/src/nvim/spellfile.c b/src/nvim/spellfile.c
index b96e8a5948..87fe73f692 100644
--- a/src/nvim/spellfile.c
+++ b/src/nvim/spellfile.c
@@ -880,9 +880,10 @@ void suggest_load_files(void)
// don't try again and again.
slang->sl_sugloaded = true;
- dotp = vim_strrchr(slang->sl_fname, '.');
- if (dotp == NULL || fnamecmp(dotp, ".spl") != 0)
+ dotp = STRRCHR(slang->sl_fname, '.');
+ if (dotp == NULL || fnamecmp(dotp, ".spl") != 0) {
continue;
+ }
STRCPY(dotp, ".sug");
fd = mch_fopen((char *)slang->sl_fname, "r");
if (fd == NULL)
diff --git a/src/nvim/strings.c b/src/nvim/strings.c
index 3f31914c03..3b075f8b70 100644
--- a/src/nvim/strings.c
+++ b/src/nvim/strings.c
@@ -456,25 +456,6 @@ char_u *vim_strchr(const char_u *const string, const int c)
}
/*
- * Search for last occurrence of "c" in "string".
- * Return NULL if not found.
- * Does not handle multi-byte char for "c"!
- */
-char_u *vim_strrchr(const char_u *string, int c)
- FUNC_ATTR_NONNULL_ALL FUNC_ATTR_PURE
-{
- const char_u *retval = NULL;
- const char_u *p = string;
-
- while (*p) {
- if (*p == c)
- retval = p;
- MB_PTR_ADV(p);
- }
- return (char_u *) retval;
-}
-
-/*
* Sort an array of strings.
*/
diff --git a/src/nvim/vim.h b/src/nvim/vim.h
index 1fe4e53faf..bddf092789 100644
--- a/src/nvim/vim.h
+++ b/src/nvim/vim.h
@@ -207,7 +207,7 @@ enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext()
// defines to avoid typecasts from (char_u *) to (char *) and back
-// (vim_strchr() and vim_strrchr() are now in alloc.c)
+// (vim_strchr() is now in strings.c)
#define STRLEN(s) strlen((char *)(s))
#define STRCPY(d, s) strcpy((char *)(d), (char *)(s))
@@ -238,6 +238,8 @@ enum { FOLD_TEXT_LEN = 51 }; //!< buffer size for get_foldtext()
# endif
#endif
+#define STRRCHR(s, c) (char_u *)strrchr((const char *)(s), (c))
+
#define STRCAT(d, s) strcat((char *)(d), (char *)(s))
#define STRNCAT(d, s, n) strncat((char *)(d), (char *)(s), (size_t)(n))
#define STRLCAT(d, s, n) xstrlcat((char *)(d), (char *)(s), (size_t)(n))