refactor: Replace vim_strrchr() with strrchar() (#8718)

ref #1474
This commit is contained in:
ZviRackover 2018-08-11 17:14:10 +03:00 committed by Justin M. Keyes
parent 6aefae8c4e
commit 22311457ab
7 changed files with 28 additions and 36 deletions

View File

@ -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"

View File

@ -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;
}

View File

@ -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) {

View File

@ -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) {

View File

@ -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)

View File

@ -455,25 +455,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.
*/

View File

@ -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))