]> PatchyGit - patchyircd.git/commitdiff
util: use std::to_chars
authorEgor <egor@patchysicp.xyz>
Tue, 20 Jan 2026 20:11:10 +0000 (22:11 +0200)
committerEgor <egor@patchysicp.xyz>
Tue, 20 Jan 2026 20:11:10 +0000 (22:11 +0200)
src/common.hpp
src/util.cpp

index 196552c..bb04b8f 100644 (file)
@@ -28,6 +28,7 @@
 
 /* C++ standard */
 #include <algorithm>
+#include <charconv>
 #include <deque>
 #include <functional>
 #include <iostream>
index abc2701..b75623d 100644 (file)
@@ -42,14 +42,9 @@ void append_strf(std::vector<char> *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);