From 20169ed6d5551d2fee59d9e4bc8caa73a8b8da7c Mon Sep 17 00:00:00 2001 From: 3gg <3gg@shellblade.net> Date: Sat, 4 Feb 2023 14:36:42 -0800 Subject: Add itoa. --- cstring/include/cstring.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/cstring/include/cstring.h b/cstring/include/cstring.h index 9425d51..75a5388 100644 --- a/cstring/include/cstring.h +++ b/cstring/include/cstring.h @@ -4,6 +4,7 @@ #include #include #include +#include /// A fixed-size string. /// The string is null-terminated so that it can be used with the usual C APIs. @@ -90,6 +91,14 @@ \ static inline bool STRING##_eq_cstr(STRING a, const char* b) { \ return (a.length == strlen(b)) && strncmp(a.str, b, a.length) == 0; \ + } \ + \ + static inline STRING STRING##_itoa(int n) { \ + STRING str = (STRING){0}; \ + const int written = snprintf(str.str, SIZE, "%d", n); \ + assert(written >= 0); \ + str.length = (size_t)written; \ + return str; \ } DEF_STRING(sstring, 32) // Small. -- cgit v1.2.3