The compiler now skips UTF8 BOM.

This commit is contained in:
Christoffer Lerno
2024-08-09 22:39:24 +02:00
parent f3e5268083
commit d997445284
2 changed files with 8 additions and 2 deletions

View File

@@ -26,6 +26,7 @@
- Add `+++` `&&&` `|||` as replacement for `$concat`, `$and` and `$or`.
- Add `methodsof` to type info for struct, union and bitstruct.
- Added `@tag` `tagof` and `has_tagof` to user defined types and members.
- The compiler now skips UTF8 BOM.
### Fixes

View File

@@ -243,10 +243,15 @@ char *file_read_all(const char *path, size_t *return_size)
error_exit("Failed to read file \"%s\".\n", path);
}
assert(bytes_read == file_size);
buffer[bytes_read] = '\0';
// Filter '\r' early.
size_t offset = 0;
// Filter BOM
if (buffer[0] == (char)0xEF && buffer[1] == (char)0xBB && buffer[2] == (char)0xBF)
{
offset += 3;
}
// Filter '\r' early.
for (size_t i = 0; i < file_size - offset; i++)
{
char c = buffer[i + offset];