CE interactive shell
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m36s
All checks were successful
Build documentation / build-and-deploy (push) Successful in 2m36s
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
@@ -45,3 +46,47 @@ int memcmp (const void* s1, const void* s2, size_t n) {
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
void strtokenize (const char* str, char delim, void* ctx, strtokenize_cb_func_t cb) {
|
||||
const char* start = str;
|
||||
const char* end;
|
||||
|
||||
while (*start) {
|
||||
while (*start == delim && *start)
|
||||
start++;
|
||||
|
||||
if (!*start)
|
||||
break;
|
||||
|
||||
end = start;
|
||||
while (*end != delim && *end)
|
||||
end++;
|
||||
|
||||
if (!cb (ctx, start, (size_t)(end - start)))
|
||||
break;
|
||||
|
||||
start = end;
|
||||
}
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/a/34873406 */
|
||||
int strcmp (const char* s1, const char* s2) {
|
||||
while (*s1 && (*s1 == *s2)) {
|
||||
s1++;
|
||||
s2++;
|
||||
}
|
||||
return *(const unsigned char*)s1 - *(const unsigned char*)s2;
|
||||
}
|
||||
|
||||
/* https://stackoverflow.com/a/2490637 */
|
||||
char* strcat (char* dest, const char* src) {
|
||||
char* rdest = dest;
|
||||
|
||||
while (*dest)
|
||||
dest++;
|
||||
|
||||
while ((*dest++ = *src++))
|
||||
;
|
||||
|
||||
return rdest;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user