ProtoCore v1.0.16
Deterministic, zero-heap network stack for embedded targets
Loading...
Searching...
No Matches
utf8.h
Go to the documentation of this file.
1// ProtoCore v1.0.16 - Copyright (C) 2026 Douglas Quigg (dstroy0) <dquigg123@gmail.com>
2// SPDX-License-Identifier: AGPL-3.0-or-later
3
4/**
5 * @file utf8.h
6 * @brief Strict UTF-8 validation (RFC 3629), one shared copy.
7 *
8 * Several protocols must reject non-UTF-8 input: WebSocket TEXT frames
9 * (RFC 6455 8.1, fail with close 1007) and MQTT strings (MQTT 1.5.3). Both use
10 * this single validator rather than each rolling its own. Header-only inline,
11 * like the other shared primitives - zero link cost when unused.
12 *
13 * @author Douglas Quigg (dstroy0)
14 * @date 2026
15 */
16
17#ifndef PROTOCORE_UTF8_H
18#define PROTOCORE_UTF8_H
19
20#include "protocore_config.h" // the entry point: protocore_types.h for the widths
21
22/** @brief The octet run a check walks. */
23typedef struct
24{
25 const uint8_t *s; ///< the octets
26 size_t n; ///< how many
27} Utf8Args;
28
29/**
30 * @brief UTF-8 well-formedness.
31 *
32 * @var Utf8Ns::args the octet run a check walks
33 * @var Utf8Ns::ok the run is well-formed UTF-8
34 * @var Utf8Ns::valid walk the run and judge it
35 *
36 * Rejects overlong encodings, surrogate code points (U+D800..U+DFFF), values above U+10FFFF, bad
37 * continuation bytes, and truncated multi-byte sequences.
38 *
39 * No storage member: the run is the caller's and nothing is held between calls.
40 */
41typedef struct
42{
45} Utf8Vars;
46
47/** @brief The operands and the outcome. */
48extern Utf8Vars Utf8V;
49
50/** @brief The entries. */
51typedef struct
52{
53 void (*const valid)(uint8_t *work);
54} Utf8Ns;
55
56// What the table binds, defined once in the .c and taking one parameter each: everything
57// else an entry needs is an operand in Utf8V or a region of the borrow at a fixed offset.
58void protocore_utf8_valid(uint8_t *work);
59
60// `static const`, initialised HERE rather than `extern` against a definition in the .c: a
61// const object whose initializer every translation unit can see is a COMPILE-TIME FACT, so
62// `Utf8.valid(work)` resolves to a named function and becomes a DIRECT call. An extern table
63// leaves the call indirect and the symbol live at every level, -O2 -flto included.
64static const Utf8Ns Utf8 __attribute__((unused)) = {
66};
67
68#endif // PROTOCORE_UTF8_H
The octet run a check walks.
Definition utf8.h:24
const uint8_t * s
the octets
Definition utf8.h:25
size_t n
how many
Definition utf8.h:26
The entries.
Definition utf8.h:52
void(*const valid)(uint8_t *work)
Definition utf8.h:53
proto_bool ok
Definition utf8.h:44
Utf8Args args
Definition utf8.h:43
_Bool proto_bool
The truth value.
Definition types.h:64
Utf8Vars Utf8V
The operands and the outcome.
void protocore_utf8_valid(uint8_t *work)