|
ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
|
Attribute and CSS-identity helpers for the no-heap XHTML tokenizer: quoted-attribute scanning, <img src> / <a href> capture, CSS element-identity + inline-style extraction, link interning, and embedded-face resolution. More...
#include <stddef.h>#include <stdint.h>#include <string.h>#include "ra8_attributes.h"#include "ra8_err.h"#include "reflow.h"#include "reflow_tokenize_internal.h"Go to the source code of this file.
Functions | |
| static bool | internal_attr_name_at (const uint8_t *tag, size_t i, const char *name, size_t name_len) |
True iff attribute name (case-insensitive) begins at tag[i]. | |
| static bool | internal_attr_quoted_value (const uint8_t *tag, size_t tag_len, size_t pos, size_t *vstart, size_t *vlen) |
| Parse = "value" after an attribute name; return the value span. | |
| bool | priv_reflow_tok_find_attr (const uint8_t *tag, size_t tag_len, const char *name, size_t name_len, size_t *out_voff, size_t *out_vlen) |
| Locate a named attribute's quoted value span within a tag (no copy). | |
| void | priv_reflow_tok_capture_attr (reflow_t *engine, const uint8_t *tag, size_t tag_len, const char *name, size_t name_len, uint32_t *out_off, uint32_t *out_len) |
| Copy a named attribute's quoted value from a tag span into the text pool. | |
| ra8_css_element_t | priv_reflow_tok_css_element (reflow_html_tag_t kind, const uint8_t *tag, size_t span) |
| Build a CSS element identity from a just-opened tag's attributes. | |
| ra8_css_style_t | priv_reflow_tok_css_inline (const uint8_t *tag, size_t span) |
| Parse a just-opened tag's inline style="..." into a CSS declaration. | |
| uint8_t | priv_reflow_tok_intern_link (reflow_t *engine, uint32_t href_off, uint32_t href_len) |
| Intern an <a> href slice into the link-target table. | |
| bool | priv_reflow_tok_rel_is_stylesheet (const uint8_t *rel, size_t len) |
| True if a rel attribute value contains the stylesheet token. | |
| uint8_t | priv_reflow_tok_resolve_face_slot (const reflow_t *engine, const ra8_css_style_t *comp) |
| Map a cascaded run's (font-family + emphasis) to an embedded face slot. | |
Attribute and CSS-identity helpers for the no-heap XHTML tokenizer: quoted-attribute scanning, <img src> / <a href> capture, CSS element-identity + inline-style extraction, link interning, and embedded-face resolution.
Companion translation unit to reflow_tokenize.c. It groups the routines that read a raw <...> start-tag span: locating a named quoted attribute, copying its value into the engine text pool, building the ra8_css_element_t identity (tag + id + class) the cascade matches against, parsing the inline style="..." declaration, interning an <a href> into the link-target table, detecting a <link rel> stylesheet, and mapping a cascaded font-family + emphasis to an embedded face slot. None of these touch the tokenizer's mutable tok_ctx_t; the markup handlers in reflow_tokenize.c call the cross-TU helpers promoted into reflow_tokenize_internal.h. Pure forward-pass scanning – no recursion (NASA P10 Rule 1) and bounded loops (Rule 2).
[Ring 4 / Reflow] {World: NS}
Definition in file reflow_tokenize_attr.c.
|
static |
True iff attribute name (case-insensitive) begins at tag[i].
Matches name with a non-name byte (or the leading '<') immediately before it, so a substring like "xsrc" does not match "src" and "xid" does not match "id".
| [in] | tag | Raw tag span. |
| [in] | i | Candidate start offset (i + name_len must be in range). |
| [in] | name | Lower-case attribute name to match. |
| [in] | name_len | Length of name, bytes. |
name as an attribute name. | true | Match. |
| false | No match. |
name must already be lower-case. Definition at line 66 of file reflow_tokenize_attr.c.
Referenced by priv_reflow_tok_find_attr().
|
static |
Parse = "value" after an attribute name; return the value span.
Skips whitespace, requires =, skips whitespace, requires a quote, then scans to the matching quote. The span excludes the quotes.
| [in] | tag | Raw tag span. |
| [in] | tag_len | Length of tag, bytes. |
| [in] | pos | Offset just past the attribute name. |
| [out] | vstart | Receives the value start offset. |
| [out] | vlen | Receives the value length, bytes. |
| true | *vstart / *vlen describe the value. |
| false | No = "..." followed the name. |
tag. Definition at line 100 of file reflow_tokenize_attr.c.
References priv_reflow_tok_is_xml_whitespace().
Referenced by priv_reflow_tok_find_attr().
| void priv_reflow_tok_capture_attr | ( | reflow_t * | engine, |
| const uint8_t * | tag, | ||
| size_t | tag_len, | ||
| const char * | name, | ||
| size_t | name_len, | ||
| uint32_t * | out_off, | ||
| uint32_t * | out_len ) |
Copy a named attribute's quoted value from a tag span into the text pool.
Copy a named attribute's quoted value from a tag span into the pool.
Scans the raw <...> span for attribute name (case-insensitive, not preceded by another name character) and copies its quoted value verbatim into the engine text pool. Used for <img src> / <a href> / element id. On no match, a malformed attribute, an empty value, or a full pool the outputs are zeroed, which callers treat as "attribute absent".
| [in,out] | engine | Engine whose text pool receives the value bytes. |
| [in] | tag | Raw tag span starting at '<'. |
| [in] | tag_len | Length of tag, bytes. |
| [in] | name | Lower-case attribute name to find. |
| [in] | name_len | Length of name, bytes. |
| [out] | out_off | Receives the text-pool offset of the value (0 if none). |
| [out] | out_len | Receives the value byte length (0 if none). |
name value was stored in the pool. Definition at line 196 of file reflow_tokenize_attr.c.
References k_reflow_text_pool_bytes, memcpy(), priv_reflow_tok_find_attr(), reflow_t::text_pool, and reflow_t::text_pool_used.
Referenced by internal_handle_void(), and internal_open_attrs().
| ra8_css_element_t priv_reflow_tok_css_element | ( | reflow_html_tag_t | kind, |
| const uint8_t * | tag, | ||
| size_t | span ) |
Build a CSS element identity from a just-opened tag's attributes.
Locates the id and class attribute value spans in place (no copy) so the cascade can match #id / .class selectors; the returned pointers alias tag. A missing attribute leaves its pointer NULL and its length zero. The element's tag enum is stored so type selectors also work.
| [in] | kind | Classified tag. |
| [in] | tag | Raw tag span starting at '<'. |
| [in] | span | Length of tag, bytes. |
| ra8_css_element_t | Fully populated struct; absent attributes have NULL pointer and zero length. |
span bytes. tag. tag. Definition at line 243 of file reflow_tokenize_attr.c.
References ra8_css_element_t::class_len, ra8_css_element_t::class_str, ra8_css_element_t::id, ra8_css_element_t::id_len, priv_reflow_tok_find_attr(), and ra8_css_element_t::tag.
Referenced by internal_handle_start().
| ra8_css_style_t priv_reflow_tok_css_inline | ( | const uint8_t * | tag, |
| size_t | span ) |
Parse a just-opened tag's inline style="..." into a CSS declaration.
Locates the style attribute within the raw tag span and delegates to ra8_css_parse_inline() to parse its value into a declaration struct. When the attribute is absent or the parser fails the returned struct has set == 0, indicating no inline declarations override the cascade.
| [in] | tag | Raw tag span starting at '<'. |
| [in] | span | Length of tag, bytes. |
| ra8_css_style_t | Struct with set == 0 if no style attribute is present. |
span bytes. tag. Definition at line 279 of file reflow_tokenize_attr.c.
References priv_reflow_tok_find_attr(), and ra8_css_parse_inline().
Referenced by internal_open_styled().
| bool priv_reflow_tok_find_attr | ( | const uint8_t * | tag, |
| size_t | tag_len, | ||
| const char * | name, | ||
| size_t | name_len, | ||
| size_t * | out_voff, | ||
| size_t * | out_vlen ) |
Locate a named attribute's quoted value span within a tag (no copy).
The non-copying core of priv_reflow_tok_capture_attr(): returns the value's offset + length *within tag* so callers can either copy it to the pool or scan it in place (e.g. an inline style).
| [in] | tag | Raw tag span starting at '<'. |
| [in] | tag_len | Length of tag, bytes. |
| [in] | name | Lower-case attribute name to find. |
| [in] | name_len | Length of name, bytes. |
| [out] | out_voff | Receives the value offset within tag. |
| [out] | out_vlen | Receives the value length, bytes. |
name value was found. | true | *out_voff / *out_vlen describe the value within tag. |
| false | Attribute absent or malformed. |
tag. Definition at line 153 of file reflow_tokenize_attr.c.
References internal_attr_name_at(), and internal_attr_quoted_value().
Referenced by internal_handle_link(), priv_reflow_tok_capture_attr(), priv_reflow_tok_css_element(), and priv_reflow_tok_css_inline().
| uint8_t priv_reflow_tok_intern_link | ( | reflow_t * | engine, |
| uint32_t | href_off, | ||
| uint32_t | href_len ) |
Intern an <a> href slice into the link-target table.
Appends a {href_off, href_len} entry and returns its 1-based id (stored in subsequent text tokens' reserved byte). An empty href or a full table returns 0 (the run renders as plain underlined text – not tappable).
| [in,out] | engine | Engine whose link-target table grows. |
| [in] | href_off | Href text-pool offset. |
| [in] | href_len | Href byte length. |
| 0 | Empty href or the table is full. |
| 1..k_reflow_max_links | The newly assigned 1-based link id. |
Definition at line 315 of file reflow_tokenize_attr.c.
References reflow_link_target_t::href_len, reflow_link_target_t::href_off, k_reflow_max_links, reflow_t::link_target_count, and reflow_t::link_targets.
Referenced by internal_open_attrs().
| bool priv_reflow_tok_rel_is_stylesheet | ( | const uint8_t * | rel, |
| size_t | len ) |
True if a rel attribute value contains the stylesheet token.
Case-sensitive substring scan (EPUB <link> rels are authored lowercase; this also accepts the alternate stylesheet form). Bounded by the value length. The inner loop iterates at most len times so the scan is O(len) with no dynamic allocation.
| [in] | rel | Attribute-value bytes (not NUL-terminated). |
| [in] | len | Length of rel, bytes. |
rel. | true | The substring "stylesheet" was found in rel. |
| false | The substring is absent or len is too short to contain it. |
rel addresses len readable bytes. rel is non-null (a zero len is a valid empty-value case). Definition at line 347 of file reflow_tokenize_attr.c.
Referenced by internal_handle_link().
| uint8_t priv_reflow_tok_resolve_face_slot | ( | const reflow_t * | engine, |
| const ra8_css_style_t * | comp ) |
Map a cascaded run's (font-family + emphasis) to an embedded face slot.
Returns 0 (the engine's default bound face) when no embedded face is registered, the run has no resolved font-family, no @font-face matches, or the matched @font-face was never registered (its src had no manifest font). Otherwise returns 1 + the registry index, which the render pass uses to pick the matching stbtt_fontinfo.
| [in] | engine | Engine whose face registry + parsed sheet are consulted. |
| [in] | comp | The element's cascaded style (family + emphasis bits). |
| 0 | No registered face matches the cascaded family + emphasis combination. |
engine and comp are non-null. Definition at line 382 of file reflow_tokenize_attr.c.
References reflow_t::css, reflow_face_t::css_face_idx, reflow_t::face_count, reflow_t::faces, ra8_css_style_t::family_len, ra8_css_style_t::family_off, k_ra8_css_set_family, k_reflow_style_bold, k_reflow_style_italic, ra8_css_sheet_t::names, ra8_css_match_face(), ra8_css_style_t::set, and ra8_css_style_t::style.
Referenced by internal_open_styled().