1
0
Fork 0

Codechange: replace manual trim and std::from_chars with ParseInteger

pull/14191/head
Rubidium 2025-05-03 07:48:01 +02:00 committed by rubidium42
parent 414f6a3067
commit 4109b6848b
1 changed files with 4 additions and 4 deletions

View File

@ -8,6 +8,7 @@
/** @file fileio.cpp Standard In/Out file operations */ /** @file fileio.cpp Standard In/Out file operations */
#include "stdafx.h" #include "stdafx.h"
#include "core/string_consumer.hpp"
#include "fileio_func.h" #include "fileio_func.h"
#include "spriteloader/spriteloader.hpp" #include "spriteloader/spriteloader.hpp"
#include "debug.h" #include "debug.h"
@ -23,7 +24,6 @@
#include <unistd.h> #include <unistd.h>
#include <pwd.h> #include <pwd.h>
#endif #endif
#include <charconv>
#include <sys/stat.h> #include <sys/stat.h>
#include <filesystem> #include <filesystem>
@ -514,13 +514,13 @@ bool TarScanner::AddFile(const std::string &filename, size_t, [[maybe_unused]] c
std::string size = ExtractString(th.size); std::string size = ExtractString(th.size);
size_t skip = 0; size_t skip = 0;
if (!size.empty()) { if (!size.empty()) {
StrTrimInPlace(size); auto value = ParseInteger<size_t>(size, 8);
auto [_, err] = std::from_chars(size.data(), size.data() + size.size(), skip, 8); if (!value.has_value()) {
if (err != std::errc()) {
Debug(misc, 0, "The file '{}' has an invalid size for '{}'", filename, name); Debug(misc, 0, "The file '{}' has an invalid size for '{}'", filename, name);
fclose(f); fclose(f);
return false; return false;
} }
skip = *value;
} }
switch (th.typeflag) { switch (th.typeflag) {