diff options
| author | Anton Kling <anton@kling.gg> | 2024-12-09 20:57:31 +0100 | 
|---|---|---|
| committer | Anton Kling <anton@kling.gg> | 2024-12-09 20:57:31 +0100 | 
| commit | 635f756fa91e22f6c4fd653e5ed2a808eb7335ae (patch) | |
| tree | 78128eacd8645f098198b1792ec239552fbdf6c6 /userland/libc/tb/sv.c | |
| parent | e7272b29feb855f4678c5c510d331f297351d3a2 (diff) | |
libc: sv add number parsing
Diffstat (limited to 'userland/libc/tb/sv.c')
| -rw-r--r-- | userland/libc/tb/sv.c | 18 | 
1 files changed, 18 insertions, 0 deletions
| diff --git a/userland/libc/tb/sv.c b/userland/libc/tb/sv.c index 4ff24fb..0d47924 100644 --- a/userland/libc/tb/sv.c +++ b/userland/libc/tb/sv.c @@ -49,6 +49,24 @@ struct sv sv_skip_chars(const struct sv input, const char *chars) {    return r;  } +uint64_t sv_parse_unsigned_number(struct sv input, struct sv *rest) { +  uint64_t r = 0; +  size_t i = 0; +  for (; i < input.length; i++) { +    if (!isdigit(input.s[i])) { +      break; +    } +    r *= 10; +    r += input.s[i] - '0'; +  } +  input.length -= i; +  input.s += i; +  if (rest) { +    *rest = input; +  } +  return r; +} +  struct sv sv_split_function(const struct sv input, struct sv *rest,                              int (*function)(int)) {    struct sv r = { |