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.
backup
Christian Seiler 4 weeks ago
parent 1130186c9e
commit 857e9bb6a9
  1. 16
      cpp/src/monoformat_parseonly.cpp

@ -4,7 +4,7 @@
#include <string_view> #include <string_view>
#include <string> #include <string>
#include <format> #include <cstdio>
#include <iostream> #include <iostream>
namespace monoformat { namespace monoformat {
@ -1029,17 +1029,19 @@ std::expected<void, ParseError> handleCurrentTime(std::span<std::byte const>& bu
} }
} }
std::string text; char text[32] = {};
if (showHours && showMinutes && showSeconds) { 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) { } 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) { } else if (showHours) {
text = std::format("{:02d}", hours); std::snprintf(text, sizeof(text), "%02d", int(hours));
} else if (showMinutes && showSeconds) { } 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) { } 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 { } else {
return {}; return {};
} }

Loading…
Cancel
Save