Last active
December 15, 2021 06:29
-
-
Save tripulse/9a0fa8574caea687f57c5a582fc6cf44 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct strnsplit { | |
const char* ptr; | |
size_t len; | |
}; | |
const char* strnsplit( | |
const char* restrict str, | |
int c, | |
size_t len, | |
size_t *part_len, | |
struct strnsplit* ctx | |
) { | |
if(str != NULL) { | |
ctx->ptr = str; | |
ctx->len = len; | |
} | |
if(ctx->len == 0) { | |
*part_len = 0; | |
return NULL; | |
} | |
const char* begin = ctx->ptr; | |
do { | |
--ctx->len; | |
if(*ctx->ptr++ == c) | |
break; | |
} while(ctx->len > 0); | |
*part_len = ctx->ptr - begin; | |
return begin; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment