From 857e9bb6a9ea54d1a90b4e47ac0756f323e0f118 Mon Sep 17 00:00:00 2001 From: Christian Seiler Date: Fri, 15 May 2026 17:52:36 +0200 Subject: [PATCH] C++/Embedded: don't use std::format This makes the code size quite large - instead fall back to snprintf(), which is plenty sufficient for our needs. --- cpp/src/monoformat_parseonly.cpp | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/cpp/src/monoformat_parseonly.cpp b/cpp/src/monoformat_parseonly.cpp index c50c6d3..985d705 100644 --- a/cpp/src/monoformat_parseonly.cpp +++ b/cpp/src/monoformat_parseonly.cpp @@ -4,7 +4,7 @@ #include #include -#include +#include #include namespace monoformat { @@ -1029,17 +1029,19 @@ std::expected handleCurrentTime(std::span& bu } } - std::string text; + char text[32] = {}; if (showHours && showMinutes && showSeconds) { - text = std::format("{:02d}:{:02d}:{:02d}", hours, minutes, seconds); + std::snprintf(text, sizeof(text), "%02d:%02d:%02d", int(hours), int(minutes), int(seconds)); } else if (showHours && showMinutes) { - text = std::format("{:02d}:{:02d}", hours, minutes); + std::snprintf(text, sizeof(text), "%02d:%02d", int(hours), int(minutes)); } else if (showHours) { - text = std::format("{:02d}", hours); + std::snprintf(text, sizeof(text), "%02d", int(hours)); } else if (showMinutes && showSeconds) { - text = std::format("{:02d}:{:02d}", minutes, seconds); + std::snprintf(text, sizeof(text), "%02d:%02d", int(minutes), int(seconds)); } else if (showSeconds) { - text = std::format("{:02d}", seconds); + std::snprintf(text, sizeof(text), "%02d", int(seconds)); + } else if (showMinutes) { + std::snprintf(text, sizeof(text), "%02d", int(minutes)); } else { return {}; }