From: Egor Date: Tue, 20 Jan 2026 20:11:10 +0000 (+0200) Subject: util: use std::to_chars X-Git-Url: https://git.patchysicp.xyz/?a=commitdiff_plain;h=7d412444574959441dcfe41d9fa501b758105e85;p=patchyircd.git util: use std::to_chars --- diff --git a/src/common.hpp b/src/common.hpp index 196552c..bb04b8f 100644 --- a/src/common.hpp +++ b/src/common.hpp @@ -28,6 +28,7 @@ /* C++ standard */ #include +#include #include #include #include diff --git a/src/util.cpp b/src/util.cpp index abc2701..b75623d 100644 --- a/src/util.cpp +++ b/src/util.cpp @@ -42,14 +42,9 @@ void append_strf(std::vector *v, const char *s, ...) { append_strn(v, s, end-s); unsigned c = va_arg(ap, unsigned); char buf[11] = {0}; - char *p = &buf[10]; - if (!c) - *--p = '0'; - while (c) { - *--p = '0' + c%10; - c /= 10; - } - append_str(v, p); + auto res = std::to_chars(std::begin(buf), std::end(buf), c); + if (res.ec == std::errc()) + append_strn(v, buf, res.ptr-buf); s = end + 2; } else if (end[1] == '%') { // %% append_strn(v, s, end-s+1);