43 return (c ==
' ') || (c ==
'\t') || (c ==
'\n') || (c ==
'\r') || (c ==
'\f') || (c ==
'\v');
53 dst[0] = (uint8_t)value;
100 for (
size_t k = 0U; k < len; ++k) {
101 if (name[k] ==
':') {
108 if ((c >=
'A') && (c <=
'Z')) {
109 c = (char)(c + (
'a' -
'A'));
120 if (name ==
nullptr) {
126 static const struct {
155 for (
size_t k = 0U; k < (
sizeof(k_map) /
sizeof(k_map[0])); ++k) {
156 if (
strcmp(lower, k_map[k].word) == 0) {
189 if ((i < avail) && ((src[i] ==
'x') || (src[i] ==
'X'))) {
195 while ((i < avail) && (src[i] !=
';')) {
198 if ((c >=
'0') && (c <=
'9')) {
199 d = (uint32_t)(uint8_t)c - (uint32_t)(uint8_t)
'0';
200 }
else if ((base == (uint32_t)
k_priv_base_hex) && (c >=
'a') && (c <=
'f')) {
201 d = ((uint32_t)(uint8_t)c - (uint32_t)(uint8_t)
'a') + (uint32_t)
k_priv_hex_offset;
202 }
else if ((base == (uint32_t)
k_priv_base_hex) && (c >=
'A') && (c <=
'F')) {
203 d = ((uint32_t)(uint8_t)c - (uint32_t)(uint8_t)
'A') + (uint32_t)
k_priv_hex_offset;
207 cp = (cp * base) + d;
212 if ((digits == 0U) || (i >= avail) || (src[i] !=
';')) {
225 const size_t window =
233 static const struct {
237 {
"amp", (uint32_t)
'&'},
238 {
"lt", (uint32_t)
'<'},
239 {
"gt", (uint32_t)
'>'},
240 {
"quot", (uint32_t)
'"'},
241 {
"apos", (uint32_t)
'\''},
243 for (
size_t e = 0U; e < (
sizeof(k_named) /
sizeof(k_named[0])); ++e) {
244 const size_t wlen =
strlen(k_named[e].word);
245 if (((wlen + 2U) <= window) && (src[1U + wlen] ==
';') &&
246 (
strncmp(&src[1], k_named[e].word, wlen) == 0)) {
247 *out_cp = k_named[e].cp;
248 *out_used = wlen + 2U;
369 tok->
kind = (uint8_t)kind;
370 tok->
tag = (uint8_t)tag;
442 for (
size_t b = 0U; b < n; ++b) {
480 if (buf[i] == (uint8_t)
'&') {
525 size_t consumed = 0U;
558 for (
size_t k = 0U; (k < len) && equal; ++k) {
559 equal = buf[k] == (uint8_t)lit[k];
566 const size_t n =
strlen(lit);
593 const size_t n =
strlen(lit);
595 while ((pos + n) <= len) {
625 const size_t n =
strlen(lit);
627 while ((pos + n) <= len) {
Annotation-attribute framework macros for ra8-firmware.
#define RA8_INTERNAL
Marker that a function is intended to be static (file-local).
Error Code Definitions for ra8-firmware.
int strncmp(const char *s1, const char *s2, size_t n)
Compare two strings up to a specified length.
int strcmp(const char *s1, const char *s2)
Compare two null-terminated strings.
size_t strlen(const char *s)
Calculate string length.
HTML / CSS reflow + paginate engine for the ra8d2 ereader.
Test-access surface for reflow_tokenize.c internal helpers.
@ k_priv_utf8_lead4
4-byte sequence lead-byte prefix.
@ k_priv_entity_window
Max bytes scanned for one '&...;'.
@ k_priv_hex_offset
Value of hex 'a'/'A' minus the letter.
@ k_priv_utf8_sh18
Shift for three continuation bytes.
@ k_priv_utf8_lead3
3-byte sequence lead-byte prefix.
@ k_priv_uc_4byte
Code points >= need 4 UTF-8 bytes.
@ k_priv_uc_3byte
Code points >= need >= 3 UTF-8 bytes.
@ k_priv_tag_name_cap
Lower-cased tag-name buffer size.
@ k_priv_utf8_mask
Low 6 bits per continuation byte.
@ k_priv_utf8_cont
Continuation-byte prefix.
@ k_priv_entity_min
Shortest valid reference ("<").
@ k_priv_base_dec
Decimal numeric-entity base.
@ k_priv_utf8_sh6
Shift for one continuation byte.
@ k_priv_utf8_sh12
Shift for two continuation bytes.
@ k_priv_base_hex
Hexadecimal numeric-entity base.
@ k_priv_utf8_lead2
2-byte sequence lead-byte prefix.
@ k_priv_uc_2byte
Code points >= need >= 2 UTF-8 bytes.
@ k_priv_uc_max
Highest valid Unicode code point.
static bool internal_bytes_equal(const uint8_t *buf, const char *lit, size_t len)
Test whether buf equals the first len bytes of lit.
bool priv_reflow_tok_starts_with(const uint8_t *buf, size_t i, size_t len, const char *lit)
Test whether buf at i begins with the literal lit.
bool priv_reflow_tok_decode_entity(const char *src, size_t avail, uint32_t *out_cp, size_t *out_used)
Decode one XML entity reference beginning at &.
bool priv_reflow_tok_stash_run(reflow_t *engine, const uint8_t *buf, size_t start, size_t end, uint32_t *out_off, uint32_t *out_len)
Entity-decode and whitespace-collapse a text run into the pool.
static bool internal_stash_one(reflow_t *engine, const uint8_t *buf, size_t i, size_t end, bool *last_ws, size_t *consumed)
Stash one source position of a text run (entity or literal byte).
size_t priv_reflow_tok_utf8_encode(uint32_t cp, uint8_t *dst)
UTF-8 encode a code point into dst (up to 4 bytes).
size_t priv_reflow_tok_find_lit(const uint8_t *buf, size_t i, size_t len, const char *lit)
Return the index of the first occurrence of lit (its start), or len.
bool priv_reflow_tok_emit(reflow_t *engine, reflow_token_kind_t kind, reflow_html_tag_t tag, uint8_t style, uint32_t off, uint32_t len)
Append one token to the engine's token pool.
bool priv_reflow_tok_is_block(reflow_html_tag_t tag)
Test whether a tag is a block-flow container in the v1 subset.
static bool internal_feed_utf8(reflow_t *engine, uint32_t cp, bool *last_ws)
Feed a code point's UTF-8 bytes through the whitespace-collapse.
reflow_html_tag_t priv_reflow_tok_classify(const char *name, size_t len)
Map a (possibly namespace-prefixed) tag name to its enum.
size_t priv_reflow_tok_skip_past(const uint8_t *buf, size_t i, size_t len, const char *lit)
Return the index just past the first occurrence of lit.
uint8_t priv_reflow_tok_style_for(reflow_html_tag_t tag)
Return the style bit an inline tag contributes to its subtree.
bool priv_reflow_tok_is_xml_whitespace(char c)
True for the ASCII characters XHTML treats as whitespace.
bool priv_reflow_tok_feed(reflow_t *engine, char ch, bool *last_ws)
Write one byte through the whitespace-collapse state machine.
static bool internal_decode_numeric(const char *src, size_t avail, uint32_t *out_cp, size_t *out_used)
Decode a &#dec; / &#xhex; numeric character reference.
static size_t internal_local_lower(const char *name, size_t len, char *dst)
Lower-case ASCII and copy the local part of a tag name.
reflow_html_tag_t
Recognised HTML element kinds.
@ k_reflow_tag_i
Italic (inline).
@ k_reflow_tag_th
Table header cell.
@ k_reflow_tag_td
Table cell.
@ k_reflow_tag_blockquote
Blockquote indent.
@ k_reflow_tag_p
Paragraph block.
@ k_reflow_tag_h5
Heading level 5.
@ k_reflow_tag_h1
Heading level 1.
@ k_reflow_tag_strong
Bold emphasis (inline).
@ k_reflow_tag_hr
Horizontal rule (void).
@ k_reflow_tag_link
<link> (void; stylesheet ref).
@ k_reflow_tag_h4
Heading level 4.
@ k_reflow_tag_tr
Table row.
@ k_reflow_tag_ul
Unordered list block.
@ k_reflow_tag_li
List item.
@ k_reflow_tag_table
Table (grid layout).
@ k_reflow_tag_em
Italic emphasis (inline).
@ k_reflow_tag_b
Bold (inline).
@ k_reflow_tag_h2
Heading level 2.
@ k_reflow_tag_h6
Heading level 6.
@ k_reflow_tag_br
Line break (void).
@ k_reflow_tag_img
Image (placeholder rect).
@ k_reflow_tag_h3
Heading level 3.
@ k_reflow_tag_ol
Ordered list block.
@ k_reflow_tag_a
Anchor (renders underlined).
@ k_reflow_tag_unknown
Anything not in this enum.
@ k_reflow_color_inherit
No per-run CSS colour.
@ k_reflow_max_tokens
Max parsed token count.
@ k_reflow_text_pool_bytes
Bytes of text pool.
reflow_token_kind_t
Parsed token classification.
@ k_reflow_style_italic
Italic face.
@ k_reflow_style_bold
Bold face.
@ k_reflow_style_underline
Underlined run.
Reflow / pagination engine state.
uint8_t text_pool[k_reflow_text_pool_bytes]
Text bytes.
uint32_t text_pool_used
Bytes consumed in text_pool.
uint32_t token_count
Tokens used.
reflow_token_t tokens[k_reflow_max_tokens]
Parsed tokens.
One parsed token in the engine's token stream.
uint16_t css_font_px
Block-start CSS font px (0 = none -> UA default).
uint32_t text_off
Byte offset into the text pool.
uint32_t text_len
Byte length within the text pool.
uint32_t color
0xRRGGBB CSS colour, or k_reflow_color_inherit.
uint8_t kind
reflow_token_kind_t.
uint8_t tag
reflow_html_tag_t (0 if N/A).
uint8_t style
Font-style bitmask.
uint16_t reserved16
Padding to 4-byte stride.
uint8_t reserved
Block align / <a> link id.