mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Make charmap-converting a non-UTF8 string non-fatal
This commit is contained in:
@@ -13,6 +13,9 @@
|
|||||||
|
|
||||||
uint32_t calchash(const char *s);
|
uint32_t calchash(const char *s);
|
||||||
char const *print(int c);
|
char const *print(int c);
|
||||||
|
/*
|
||||||
|
* @return The number of bytes read, or 0 if invalid data was found
|
||||||
|
*/
|
||||||
size_t readUTF8Char(uint8_t *dest, char const *src);
|
size_t readUTF8Char(uint8_t *dest, char const *src);
|
||||||
|
|
||||||
#endif /* RGBDS_UTIL_H */
|
#endif /* RGBDS_UTIL_H */
|
||||||
|
|||||||
@@ -229,6 +229,10 @@ size_t charmap_Convert(char const *input, uint8_t *output)
|
|||||||
} else if (*input) { /* No match found */
|
} else if (*input) { /* No match found */
|
||||||
size_t codepointLen = readUTF8Char(output, input);
|
size_t codepointLen = readUTF8Char(output, input);
|
||||||
|
|
||||||
|
if (codepointLen == 0) {
|
||||||
|
error("Input string is not valid UTF-8!");
|
||||||
|
break;
|
||||||
|
}
|
||||||
input += codepointLen; /* OK because UTF-8 has no NUL in multi-byte chars */
|
input += codepointLen; /* OK because UTF-8 has no NUL in multi-byte chars */
|
||||||
output += codepointLen;
|
output += codepointLen;
|
||||||
outputLen += codepointLen;
|
outputLen += codepointLen;
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ size_t readUTF8Char(uint8_t *dest, char const *src)
|
|||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
if (decode(&state, &codep, src[i]) == 1)
|
if (decode(&state, &codep, src[i]) == 1)
|
||||||
fatalerror("invalid UTF-8 character\n");
|
return 0;
|
||||||
|
|
||||||
dest[i] = src[i];
|
dest[i] = src[i];
|
||||||
i++;
|
i++;
|
||||||
|
|||||||
Reference in New Issue
Block a user