mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Replace all ctype.h functions with locale-independent ones
This commit is contained in:
@@ -32,7 +32,6 @@
|
||||
|
||||
%code {
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
#include <inttypes.h>
|
||||
#include <optional>
|
||||
#include <stdio.h>
|
||||
@@ -42,6 +41,7 @@
|
||||
|
||||
#include "extern/utf8decoder.hpp"
|
||||
#include "helpers.hpp"
|
||||
#include "util.hpp" // toLower, toUpper
|
||||
|
||||
#include "asm/charmap.hpp"
|
||||
#include "asm/fixpoint.hpp"
|
||||
@@ -1599,11 +1599,11 @@ string_literal:
|
||||
}
|
||||
| OP_STRUPR LPAREN string RPAREN {
|
||||
$$ = std::move($3);
|
||||
std::transform(RANGE($$), $$.begin(), [](char c) { return toupper(c); });
|
||||
std::transform(RANGE($$), $$.begin(), toUpper);
|
||||
}
|
||||
| OP_STRLWR LPAREN string RPAREN {
|
||||
$$ = std::move($3);
|
||||
std::transform(RANGE($$), $$.begin(), [](char c) { return tolower(c); });
|
||||
std::transform(RANGE($$), $$.begin(), toLower);
|
||||
}
|
||||
| OP_STRRPL LPAREN string COMMA string COMMA string RPAREN {
|
||||
$$ = act_StringReplace($3, $5, $7);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
#include "helpers.hpp" // unreachable_
|
||||
#include "platform.hpp" // strcasecmp
|
||||
#include "util.hpp" // isBlankSpace, isLower, isDigit
|
||||
#include "util.hpp"
|
||||
|
||||
#include "fix/warning.hpp"
|
||||
|
||||
@@ -103,12 +103,10 @@ static void skipMBCSpace(char const *&ptr) {
|
||||
}
|
||||
|
||||
static char normalizeMBCChar(char c) {
|
||||
if (isLower(c)) {
|
||||
c = c - 'a' + 'A'; // Uppercase for comparison with `mbc_Name`s
|
||||
} else if (c == '_') {
|
||||
c = ' '; // Treat underscores as spaces
|
||||
if (c == '_') {
|
||||
return ' '; // Treat underscores as spaces
|
||||
}
|
||||
return c;
|
||||
return toUpper(c); // Uppercase for comparison with `mbc_Name`s
|
||||
}
|
||||
|
||||
[[noreturn]]
|
||||
|
||||
@@ -58,6 +58,14 @@ bool isAlphanumeric(int c) {
|
||||
return isLetter(c) || isDigit(c);
|
||||
}
|
||||
|
||||
char toLower(char c) {
|
||||
return isUpper(c) ? c - 'A' + 'a' : c;
|
||||
}
|
||||
|
||||
char toUpper(char c) {
|
||||
return isLower(c) ? c - 'a' + 'A' : c;
|
||||
}
|
||||
|
||||
bool startsIdentifier(int c) {
|
||||
// This returns false for anonymous labels, which internally start with a '!',
|
||||
// and for section fragment literal labels, which internally start with a '$'.
|
||||
|
||||
Reference in New Issue
Block a user