[RFC PATCH v2 2/9] libcamera: base: log: Use `std::from_chars()`
Jacopo Mondi
jacopo.mondi at ideasonboard.com
Mon Feb 3 17:25:51 CET 2025
Hi Barnabás
On Thu, Jan 30, 2025 at 07:58:25PM +0000, Barnabás Pőcze wrote:
> Use the `std::from_chars()` function from `<charconv>` to
> parse the integral log level instead of `strtoul` as it
> provides an easier to use interface and better type safety.
>
> Signed-off-by: Barnabás Pőcze <pobrn at protonmail.com>
> Reviewed-by: Laurent Pinchart <laurent.pinchart at ideasonboard.com>
Reviewed-by: Jacopo Mondi <jacopo.mondi at ideasonboard.com>
Thanks
j
> ---
> src/libcamera/base/log.cpp | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/src/libcamera/base/log.cpp b/src/libcamera/base/log.cpp
> index 1917c3254..31053aee1 100644
> --- a/src/libcamera/base/log.cpp
> +++ b/src/libcamera/base/log.cpp
> @@ -8,6 +8,7 @@
> #include <libcamera/base/log.h>
>
> #include <array>
> +#include <charconv>
> #include <fstream>
> #include <iostream>
> #include <list>
> @@ -685,12 +686,11 @@ LogSeverity Logger::parseLogLevel(const std::string &level)
> "FATAL",
> };
>
> - int severity;
> + unsigned int severity;
>
> if (std::isdigit(level[0])) {
> - char *endptr;
> - severity = strtoul(level.c_str(), &endptr, 10);
> - if (*endptr != '\0' || severity > LogFatal)
> + auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
> + if (ec != std::errc() || *end != '\0' || severity > LogFatal)
> severity = LogInvalid;
> } else {
> severity = LogInvalid;
> --
> 2.48.1
>
>
More information about the libcamera-devel
mailing list