Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,19 @@ static uint32_t raylib_key_unshifted_codepoint(int rl_key)

// Encode a single Unicode codepoint into a UTF-8 byte buffer.
// Returns the number of bytes written (1–4).
// Invalid codepoints (> U+10FFFF) are replaced with U+FFFD.
static int utf8_encode(uint32_t cp, char out[4])
{
// Unicode defines the maximum valid codepoint as U+10FFFF.
// Codepoints above this value are invalid and should be replaced
// with the Unicode replacement character U+FFFD.
const uint32_t MAX_UNICODE = 0x10FFFF;
const uint32_t REPLACEMENT_CHAR = 0xFFFD;

if (cp > MAX_UNICODE) {
cp = REPLACEMENT_CHAR;
}

if (cp < 0x80) {
out[0] = (char)cp;
return 1;
Expand Down
Loading