mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Use some more C++20 features (#1231)
This commit is contained in:
@@ -1197,7 +1197,7 @@ static bool processFilename(char const *name)
|
||||
|
||||
if (fstat(input, &stat) == -1) {
|
||||
report("FATAL: Failed to stat \"%s\": %s\n", name, strerror(errno));
|
||||
} else if (!S_ISREG(stat.st_mode)) { // FIXME: Do we want to support other types?
|
||||
} else if (!S_ISREG(stat.st_mode)) { // TODO: Do we want to support other types?
|
||||
report("FATAL: \"%s\" is not a regular file, and thus cannot be modified in-place\n",
|
||||
name);
|
||||
} else if (stat.st_size < 0x150) {
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include <algorithm>
|
||||
#include <cassert>
|
||||
#include <charconv>
|
||||
#include <cinttypes>
|
||||
#include <climits>
|
||||
#include <cstdint>
|
||||
@@ -218,21 +219,18 @@ static void readLine(std::filebuf &file, std::string &buffer) {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME: Normally we'd use `std::from_chars`, but that's not available with GCC 7
|
||||
/*
|
||||
* Parses the initial part of a string_view, advancing the "read index" as it does
|
||||
*/
|
||||
template<typename U> // Should be uint*_t
|
||||
static std::optional<U> parseDec(std::string const &str, std::string::size_type &n) {
|
||||
std::string::size_type start = n;
|
||||
|
||||
uintmax_t value = 0; // Use a larger type to handle overflow more easily
|
||||
for (auto end = std::min(str.length(), str.find_first_not_of("0123456789"sv, n)); n < end;
|
||||
++n) {
|
||||
value = std::min(value * 10 + (str[n] - '0'), (uintmax_t)std::numeric_limits<U>::max);
|
||||
uintmax_t value = 0;
|
||||
auto result = std::from_chars(str.data(), str.data() + str.size(), value);
|
||||
if ((bool)result.ec) {
|
||||
return std::nullopt;
|
||||
}
|
||||
|
||||
return n > start ? std::optional<U>{value} : std::nullopt;
|
||||
n += result.ptr - str.data();
|
||||
return std::optional<U>{value};
|
||||
}
|
||||
|
||||
static std::optional<Rgba> parseColor(std::string const &str, std::string::size_type &n,
|
||||
@@ -334,8 +332,7 @@ static void parseGPLFile(std::filebuf &file) {
|
||||
|
||||
std::string line;
|
||||
readLine(file, line);
|
||||
// FIXME: C++20 will allow `!line.starts_with` instead of `line.rfind` with 0
|
||||
if (line.rfind("GIMP Palette", 0)) {
|
||||
if (!line.starts_with("GIMP Palette")) {
|
||||
error("Palette file does not appear to be a GPL palette file");
|
||||
return;
|
||||
}
|
||||
@@ -350,8 +347,7 @@ static void parseGPLFile(std::filebuf &file) {
|
||||
break;
|
||||
}
|
||||
|
||||
// FIXME: C++20 will allow `line.starts_with` instead of `!line.rfind` with 0
|
||||
if (!line.rfind("#", 0) || !line.rfind("Name:", 0) || !line.rfind("Column:", 0)) {
|
||||
if (line.starts_with("#") || line.starts_with("Name:") || line.starts_with("Column:")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
||||
@@ -402,7 +402,7 @@ int main(int argc, char *argv[])
|
||||
parseScrambleSpec(musl_optarg);
|
||||
break;
|
||||
case 's':
|
||||
// FIXME: nobody knows what this does, figure it out
|
||||
// TODO: implement "smart linking" with `-s`
|
||||
(void)musl_optarg;
|
||||
warning(NULL, 0, "Nobody has any idea what `-s` does");
|
||||
break;
|
||||
|
||||
@@ -330,8 +330,8 @@ static int compareSymbols(void const *a, void const *b)
|
||||
|
||||
char const *sym1_name = sym1->sym->name;
|
||||
char const *sym2_name = sym2->sym->name;
|
||||
bool sym1_local = !!strchr(sym1_name, '.');
|
||||
bool sym2_local = !!strchr(sym2_name, '.');
|
||||
bool sym1_local = strchr(sym1_name, '.');
|
||||
bool sym2_local = strchr(sym2_name, '.');
|
||||
|
||||
if (sym1_local != sym2_local) {
|
||||
size_t sym1_len = strlen(sym1_name);
|
||||
|
||||
Reference in New Issue
Block a user