tree-wide: replace string functions with fundamental functions

This commit is contained in:
Rose
2024-01-11 13:36:25 +09:00
committed by Yu Watanabe
parent 658169e6d3
commit aa9ff6c28d
7 changed files with 30 additions and 38 deletions
+7 -11
View File
@@ -1509,24 +1509,20 @@ ssize_t strlevenshtein(const char *x, const char *y) {
}
char *strrstr(const char *haystack, const char *needle) {
const char *f = NULL;
size_t l;
/* Like strstr() but returns the last rather than the first occurrence of "needle" in "haystack". */
if (!haystack || !needle)
return NULL;
l = strlen(needle);
/* Special case: for the empty string we return the very last possible occurrence, i.e. *after* the
* last char, not before. */
if (l == 0)
if (*needle == 0)
return strchr(haystack, 0);
for (const char *p = haystack; *p; p++)
if (strneq(p, needle, l))
f = p;
return (char*) f;
for (const char *p = strstr(haystack, needle), *q; p; p = q) {
q = strstr(p + 1, needle);
if (!q)
return (char *) p;
}
return NULL;
}