From 42da9b0f1e29eb477ef7a8f32d4491c44eaf087f Mon Sep 17 00:00:00 2001 From: nyashbox Date: Mon, 2 Dec 2024 02:09:35 +0200 Subject: [PATCH] feat(Format): add support for %g and %G format specifiers --- Foundation/include/Poco/Format.h | 2 ++ Foundation/src/Format.cpp | 4 ++++ 2 files changed, 6 insertions(+) diff --git a/Foundation/include/Poco/Format.h b/Foundation/include/Poco/Format.h index 2334b11a0..c8f9835fa 100644 --- a/Foundation/include/Poco/Format.h +++ b/Foundation/include/Poco/Format.h @@ -62,6 +62,8 @@ std::string Foundation_API format(const std::string& fmt, const Any& value); /// * e signed floating-point value in the form [-]d.dddde[]dd[d] /// * E signed floating-point value in the form [-]d.ddddE[]dd[d] /// * f signed floating-point value in the form [-]dddd.dddd + /// * g use the shortest representation: %e or %f + /// * G use the shortest representation: %E or %F /// * s std::string /// * v std::string_view /// * z std::size_t diff --git a/Foundation/src/Format.cpp b/Foundation/src/Format.cpp index 951f7dcb9..1b7cc2bc6 100644 --- a/Foundation/src/Format.cpp +++ b/Foundation/src/Format.cpp @@ -128,6 +128,8 @@ namespace case 'e': str << std::scientific; break; case 'E': str << std::scientific << std::uppercase; break; case 'f': str << std::fixed; break; + case 'g': str << std::defaultfloat; break; + case 'G': str << std::defaultfloat << std::uppercase; break; } } @@ -212,6 +214,8 @@ namespace case 'e': case 'E': case 'f': + case 'g': + case 'G': switch (mod) { case 'l': str << AnyCast(*itVal++); break;