summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--userland/libc/include/tb/sv.h1
-rw-r--r--userland/libc/tb/sv.c18
2 files changed, 19 insertions, 0 deletions
diff --git a/userland/libc/include/tb/sv.h b/userland/libc/include/tb/sv.h
index e1ca453..0ffe266 100644
--- a/userland/libc/include/tb/sv.h
+++ b/userland/libc/include/tb/sv.h
@@ -36,4 +36,5 @@ struct sv sv_trim_left(struct sv s, size_t n);
struct sv sv_clone(struct sv s);
struct sv sv_clone_from_c(const char *s);
char *sv_copy_to_c(struct sv s, char *out, size_t buffer_length);
+uint64_t sv_parse_unsigned_number(struct sv input, struct sv *rest);
#endif
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 = {