diff options
author | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-19 19:31:03 +0100 |
---|---|---|
committer | Lizzy Fleckenstein <lizzy@vlhl.dev> | 2023-12-19 19:41:57 +0100 |
commit | 42c69b59e1fdcf70219bc04a3124d2f35d9463ac (patch) | |
tree | 554838f5c4a759262563e3fb505d0a7097acf8ea /stage3/string.h | |
parent | 3102878c86c810c0bf877d72aceefeb28a44271d (diff) | |
download | cuddles-42c69b59e1fdcf70219bc04a3124d2f35d9463ac.tar.xz |
ls command
Diffstat (limited to 'stage3/string.h')
-rw-r--r-- | stage3/string.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/stage3/string.h b/stage3/string.h index fc91522..1a28494 100644 --- a/stage3/string.h +++ b/stage3/string.h @@ -3,12 +3,43 @@ #include "def.h" +// compares two strings by length and ASCII values. return value: +// < 0 if s1 < s2 +// = 0 if s1 = s2 +// > 0 if s1 > s2 isize str_cmp(str s1, str s2); + +// returns index of first of occurrence in s of any of the chars in tokens +// returns length of s if not found usize str_find(str s, str tokens); + +// parses a number in base base and returns number of chars processed +// resulting number is stored in *x usize str_parse_num(str s, u8 base, u64 *x); + +// this is a splitting function +// returns the next non-empty substring of *s that is delimited by the tokens in sep +// the returned string does not contain any of the separators +// returns an emtpy string when end is reached +// advances s to after the substring plus first delimiting token str str_walk(str *s, str sep); + +// advances the string while its first token matches any of the chars in tokens +// this can be used to consume whitespace, for example str str_eat(str s, str tokens); + +// advances the string s by x chars, increasing the data pointer and decreasing the length +// note: this is not bounds checked str str_advance(str s, usize x); + +// returns true if s starts with start bool str_start(str s, str start); +// construct a str from a \0 terminated string at runtime +// avoid this for literals: use the S macro from def.h instead without a runtime cost +str str_intro(char *c); + +// copy a string to the heap +str str_clone(str s); + #endif |