Compare commits

..

2 Commits

Author SHA1 Message Date
Christian Seiler 857e9bb6a9 C++/Embedded: don't use std::format 4 weeks ago
Christian Seiler 1130186c9e C++/CMake: don't build structured code in embedded systems 4 weeks ago
  1. 14
      cpp/src/CMakeLists.txt
  2. 16
      cpp/src/monoformat_parseonly.cpp

@ -1,12 +1,10 @@
set(monoformat_SOURCES
monoformat_schema.cpp
monoformat_structured.cpp
monoformat_parseonly.cpp
monoformat_fontreader.cpp
)
set(monoformat_HEADERS
monoformat_schema.hpp
monoformat_structured.hpp
monoformat_parsehelpers.hpp
monoformat_parseonly.hpp
monoformat_fontreader.hpp
@ -14,6 +12,18 @@ set(monoformat_HEADERS
monoformat_utf8.hpp
)
option(MONOFORMAT_EMBEDDED "Only build for embedded devices" FALSE)
if(NOT MONOFORMAT_EMBEDDED)
list(APPEND monoformat_SOURCES
monoformat_structured.cpp
)
list(APPEND monoformat_HEADERS
monoformat_structured.hpp
)
endif()
add_library(monoformat ${monoformat_SOURCES} ${monoformat_HEADERS})
target_compile_features(monoformat PUBLIC cxx_std_23)
target_include_directories(monoformat PUBLIC ${CMAKE_CURRENT_SOURCE_DIR})

@ -4,7 +4,7 @@
#include <string_view>
#include <string>
#include <format>
#include <cstdio>
#include <iostream>
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) {
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 {};
}

Loading…
Cancel
Save