libcamera: base: log: Use std::from_chars()
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@protonmail.com> Reviewed-by: Laurent Pinchart <laurent.pinchart@ideasonboard.com> Reviewed-by: Jacopo Mondi <jacopo.mondi@ideasonboard.com>
This commit is contained in:
parent
d40250e03b
commit
8fa119e0b5
1 changed files with 4 additions and 4 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <libcamera/base/log.h>
|
#include <libcamera/base/log.h>
|
||||||
|
|
||||||
#include <array>
|
#include <array>
|
||||||
|
#include <charconv>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
@ -686,12 +687,11 @@ LogSeverity Logger::parseLogLevel(const std::string &level)
|
||||||
"FATAL",
|
"FATAL",
|
||||||
};
|
};
|
||||||
|
|
||||||
int severity;
|
unsigned int severity;
|
||||||
|
|
||||||
if (std::isdigit(level[0])) {
|
if (std::isdigit(level[0])) {
|
||||||
char *endptr;
|
auto [end, ec] = std::from_chars(level.data(), level.data() + level.size(), severity);
|
||||||
severity = strtoul(level.c_str(), &endptr, 10);
|
if (ec != std::errc() || *end != '\0' || severity > LogFatal)
|
||||||
if (*endptr != '\0' || severity > LogFatal)
|
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
} else {
|
} else {
|
||||||
severity = LogInvalid;
|
severity = LogInvalid;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue