[misc] strstr, startswith
This commit is contained in:
parent
1ca8e24fe0
commit
75329eed95
@ -267,6 +267,42 @@ rfind(
|
||||
return (size_t)(str) + i;
|
||||
}
|
||||
|
||||
char *
|
||||
strstr(const char * haystack, const char * needle) {
|
||||
const char * out = NULL;
|
||||
const char * ptr;
|
||||
const char * acc;
|
||||
const char * p;
|
||||
size_t s = strlen(needle);
|
||||
for (ptr = haystack; *ptr != '\0'; ++ptr) {
|
||||
size_t accept = 0;
|
||||
out = ptr;
|
||||
p = ptr;
|
||||
for (acc = needle; (*acc != '\0') && (*p != '\0'); ++acc) {
|
||||
if (*p == *acc) {
|
||||
accept++;
|
||||
p++;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (accept == s) {
|
||||
return (char *)out;
|
||||
}
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
uint8_t startswith(const char * str, const char * accept) {
|
||||
size_t s = strlen(accept);
|
||||
for (size_t i = 0; i < s; ++i) {
|
||||
if (*str != *accept) return 0;
|
||||
str++;
|
||||
accept++;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
size_t
|
||||
strspn(
|
||||
const char * str,
|
||||
|
@ -48,6 +48,8 @@ extern size_t rfind(const char * str, const char accept);
|
||||
extern size_t strspn(const char * str, const char * accept);
|
||||
extern char * strpbrk(const char * str, const char * accept);
|
||||
extern uint32_t krand();
|
||||
extern char * strstr(const char * haystack, const char * needle);
|
||||
extern uint8_t startswith(const char * str, const char * accept);
|
||||
|
||||
/* VGA driver */
|
||||
extern void cls();
|
||||
|
Loading…
Reference in New Issue
Block a user