Don't count single quote ' as garbage (#1801)

Also copy the "blank space" (space or tab) vs "whitespace" (space,
tab, or newline) convention from `<ctype.h>`
This commit is contained in:
Rangi
2025-08-14 10:10:59 -04:00
committed by GitHub
parent ea1358bbe6
commit db6793f444
15 changed files with 98 additions and 72 deletions

View File

@@ -8,6 +8,7 @@
#include "helpers.hpp" // unreachable_
#include "platform.hpp" // strcasecmp
#include "util.hpp" // isBlankSpace
#include "fix/warning.hpp"
@@ -93,14 +94,14 @@ bool mbc_HasRAM(MbcType type) {
return search != mbcData.end() && search->second.second;
}
static void skipWhitespace(char const *&ptr) {
while (*ptr == ' ' || *ptr == '\t') {
static void skipBlankSpace(char const *&ptr) {
while (isBlankSpace(*ptr)) {
++ptr;
}
}
static void skipMBCSpace(char const *&ptr) {
while (*ptr == ' ' || *ptr == '\t' || *ptr == '_') {
while (isBlankSpace(*ptr) || *ptr == '_') {
++ptr;
}
}
@@ -166,7 +167,7 @@ MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor)
uint16_t mbc;
char const *ptr = name;
skipWhitespace(ptr); // Trim off leading whitespace
skipBlankSpace(ptr); // Trim off leading blank space
#define tryReadSlice(expected) \
do { \
@@ -318,7 +319,7 @@ MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor)
// clang-format on
for (;;) {
skipWhitespace(ptr); // Trim off trailing whitespace
skipBlankSpace(ptr); // Trim off trailing blank space
// If done, start processing "features"
if (!*ptr) {
@@ -501,9 +502,9 @@ MbcType mbc_ParseName(char const *name, uint8_t &tpp1Major, uint8_t &tpp1Minor)
break;
}
skipWhitespace(ptr); // Trim off trailing whitespace
skipBlankSpace(ptr); // Trim off trailing blank space
// If there is still something past the whitespace, error out
// If there is still something left, error out
if (*ptr) {
fatalUnknownMBC(fullName);
}