diff options
Diffstat (limited to 'strio.h')
-rw-r--r-- | strio.h | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/strio.h b/strio.h index c8bb21f..029f026 100644 --- a/strio.h +++ b/strio.h @@ -10,10 +10,13 @@ void str_putf(Str s, FILE *f); void str_put(Str s); int str_to_u64(Str s, uint64_t *out); +int str_to_i64(Str s, int64_t *out); + void str_cat_i64(Str *out, int64_t c, char pad_char, int min_width, Arena *a); void str_cat_u64(Str *out, uint64_t c, char pad_char, int min_width, Arena *a); void str_cat_fmtv(Str *out, Arena *arena, const char *fmt, va_list ap); void str_cat_fmt(Str *out, Arena *arena, const char *fmt, ...); + Str str_fmtv(Arena *arena, const char *fmt, va_list ap); Str str_fmt(Arena *arena, const char *fmt, ...); const char *cstr_fmt(Arena *arena, const char *fmt, ...); @@ -89,6 +92,18 @@ int str_to_u64(Str s, uint64_t *out) { return 0; } +int str_to_i64(Str s, int64_t *out) { + int64_t sign = 1; + if (s.n > 0 && s.s[0] == '-') { + s = str_skip(s, 1); + sign = -1; + } + uint64_t u64; + if (str_to_u64(s, &u64)) return -1; + *out = u64 * sign; + return 0; +} + static void str_cat_u64_(char buf[32], int *n, uint64_t c) { int i = 0; buf[31] = '\0'; |