LCDGFX LCD display driver  1.2.0
Lightweight graphics library for SSD1306, SSD1325, SSD1327, SSD1331, SSD1351, SH1106, SH1107, IL9163, ST7735, ST7789, ILI9341, PCD8544 displays over I2C/SPI
font_utf8.h File Reference

Stateless UTF-8 decoder helpers. More...

#include <stdint.h>
#include <stddef.h>
Include dependency graph for font_utf8.h:

Go to the source code of this file.

Macros

#define NANO_UTF8_INVALID   0xFFFFFFFFu
 Sentinel value returned by nano_utf8_decode() when the input is malformed, truncated, or contains an invalid sequence.
 

Functions

static uint32_t nano_utf8_decode (const char **p, const char *end)
 Decode a single UTF-8 codepoint from p in a stateless way. More...
 

Detailed Description

Stateless UTF-8 decoder helpers.

Definition in file font_utf8.h.

Function Documentation

◆ nano_utf8_decode()

static uint32_t nano_utf8_decode ( const char **  p,
const char *  end 
)
inlinestatic

Decode a single UTF-8 codepoint from p in a stateless way.

Unlike NanoFont::unicode16FromUtf8(), which keeps internal static state and returns a 16-bit truncated codepoint, this helper decodes a full 21-bit Unicode codepoint and never mutates global state, so it is safe to use from re-entrant contexts.

On entry p must point at the first byte of a UTF-8 sequence. On successful return p is advanced past the decoded sequence and the codepoint is returned. The decoder stops at the NUL byte; if end is non-NULL the decoder never reads past end.

The following inputs are reported as invalid (return value NANO_UTF8_INVALID, p advanced by one byte to allow resynchronisation):

  • lone continuation bytes (0x80..0xBF) at the start of a sequence;
  • truncated multi-byte sequences (NUL or end before all trailing bytes have been seen);
  • bytes 0xC0, 0xC1, 0xF5..0xFF (always invalid in UTF-8);
  • overlong encodings (e.g. U+0000 encoded as two bytes);
  • codepoints in the surrogate range U+D800..U+DFFF;
  • codepoints above U+10FFFF.
Parameters
pin/out pointer to the next byte to decode. Must not be NULL.
endoptional end-of-buffer guard, may be NULL for NUL-terminated input.
Returns
decoded codepoint, or NANO_UTF8_INVALID.

Definition at line 73 of file font_utf8.h.