mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Factor out isBinDigit and parseHexDigit utility functions
This commit is contained in:
13
src/util.cpp
13
src/util.cpp
@@ -5,6 +5,8 @@
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include "helpers.hpp" // assume
|
||||
|
||||
bool isNewline(int c) {
|
||||
return c == '\r' || c == '\n';
|
||||
}
|
||||
@@ -51,6 +53,17 @@ bool continuesIdentifier(int c) {
|
||||
return startsIdentifier(c) || isDigit(c) || c == '#' || c == '$' || c == '@';
|
||||
}
|
||||
|
||||
uint8_t parseHexDigit(int c) {
|
||||
if (c >= 'A' && c <= 'F') {
|
||||
return c - 'A' + 10;
|
||||
} else if (c >= 'a' && c <= 'f') {
|
||||
return c - 'a' + 10;
|
||||
} else {
|
||||
assume(isDigit(c));
|
||||
return c - '0';
|
||||
}
|
||||
}
|
||||
|
||||
char const *printChar(int c) {
|
||||
// "'A'" + '\0': 4 bytes
|
||||
// "'\\n'" + '\0': 5 bytes
|
||||
|
||||
Reference in New Issue
Block a user