ra8-firmware 0.1.0
Bare-metal firmware for the Renesas RA8 family (RA8D2 / RA8P1)
Loading...
Searching...
No Matches
mdl_extract_internal.h File Reference

Shared bounded markup lexer helpers for media extraction units. More...

#include <stddef.h>
#include <string.h>
#include "ra8_attributes.h"
Include dependency graph for mdl_extract_internal.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

static char internal_lc (char c)
 ASCII lower-case (locale-independent).
static bool internal_is_attr_boundary (char c)
 True if c ends an HTML attribute token on its left side.
static bool internal_is_name_end (char c)
 True if c terminates a tag name (so "<a" != "<article").
static const char * internal_find_ci (const char *hay, size_t hay_len, const char *needle)
 Case-insensitive search for needle in [hay, hay+hay_len).
static size_t internal_skip_ws (const char *tag, size_t tag_len, size_t k)
 Advance past spaces/tabs in [k, tag_len).
static bool internal_read_eq_value (const char *tag, size_t tag_len, size_t k, char *out, size_t out_cap)
 From position k just after an attr name, read ="value".
static bool internal_find_attr_value (const char *tag, size_t tag_len, const char *attr, char *out, size_t out_cap)
 Read the value of attr inside one tag [tag, tag+tag_len).
static bool internal_contains_ok (const char *url, const char *needle)
 True if needle is empty/NULL or a substring of url.
static bool internal_copy_fits (char *out, size_t out_cap, const char *src)
 Copy src into out if it fits (incl.

Detailed Description

Shared bounded markup lexer helpers for media extraction units.

Centralizes allocation-free ASCII matching, attribute parsing, and bounded string copies used by the image and titled-anchor scanners. Every definition is internal inline code in the including unit.

Since
Version 0.1.0

Definition in file mdl_extract_internal.h.

Function Documentation

◆ internal_contains_ok()

bool internal_contains_ok ( const char * url,
const char * needle )
inlinestatic

True if needle is empty/NULL or a substring of url.

Applies the optional substring filter without modifying either input. Both NUL-terminated inputs remain borrowed for the call.

Parameters
[in]urlNUL-terminated URL input.
[in]needleOptional substring filter.
Returns
True when needle is absent, empty, or occurs in url.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 226 of file mdl_extract_internal.h.

References RA8_INTERNAL, and strstr().

Referenced by internal_emit_hit(), and internal_emit_tag_url().

◆ internal_copy_fits()

bool internal_copy_fits ( char * out,
size_t out_cap,
const char * src )
inlinestatic

Copy src into out if it fits (incl.

NUL).

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[out]outCaller-owned result storage.
[in]out_capDestination capacity including any terminator.
[in]srcReadable source bytes.
Returns
True when src and its terminator fit completely in out.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 250 of file mdl_extract_internal.h.

References memcpy(), RA8_INTERNAL, and strlen().

Referenced by internal_emit_tag_url(), internal_merge_hit(), internal_selector_copy(), and mdl_extract_resolve_url().

◆ internal_find_attr_value()

bool internal_find_attr_value ( const char * tag,
size_t tag_len,
const char * attr,
char * out,
size_t out_cap )
inlinestatic

Read the value of attr inside one tag [tag, tag+tag_len).

Returns
true and fills out (NUL-terminated) if a quoted value was found.

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]tagReadable tag byte span.
[in]tag_lenReadable tag length.
[in]attrAttribute name to locate.
[out]outCaller-owned result storage.
[in]out_capDestination capacity including any terminator.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 188 of file mdl_extract_internal.h.

References internal_find_ci(), internal_is_attr_boundary(), internal_read_eq_value(), RA8_INTERNAL, and strlen().

Referenced by internal_anchor_title(), internal_emit_hit(), internal_emit_tag_url(), internal_extract_class(), and internal_extract_meta().

◆ internal_find_ci()

const char * internal_find_ci ( const char * hay,
size_t hay_len,
const char * needle )
inlinestatic

Case-insensitive search for needle in [hay, hay+hay_len).

Definition at line 80 of file mdl_extract_internal.h.

References internal_lc(), and strlen().

Referenced by internal_anchor_title(), internal_extract_class(), internal_extract_label(), internal_extract_meta(), internal_find_attr_value(), internal_scan_tags(), and mdl_extract_hits().

◆ internal_is_attr_boundary()

bool internal_is_attr_boundary ( char c)
inlinestatic

True if c ends an HTML attribute token on its left side.

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]cInput ASCII byte.
Returns
True when c may delimit the left edge of an attribute.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 53 of file mdl_extract_internal.h.

References RA8_INTERNAL.

Referenced by internal_find_attr_value().

◆ internal_is_name_end()

bool internal_is_name_end ( char c)
inlinestatic

True if c terminates a tag name (so "<a" != "<article").

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]cInput ASCII byte.
Returns
True when c terminates an HTML tag name.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 73 of file mdl_extract_internal.h.

References RA8_INTERNAL.

Referenced by internal_scan_tags(), and mdl_extract_hits().

◆ internal_lc()

char internal_lc ( char c)
inlinestatic

ASCII lower-case (locale-independent).

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]cInput ASCII byte.
Returns
Lower-case ASCII mapping of c, or c unchanged outside A-Z.
Return values
0The input character was NUL.
otherLower-case mapping or unchanged input character.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 32 of file mdl_extract_internal.h.

References RA8_INTERNAL.

Referenced by internal_find_ci().

◆ internal_read_eq_value()

bool internal_read_eq_value ( const char * tag,
size_t tag_len,
size_t k,
char * out,
size_t out_cap )
inlinestatic

From position k just after an attr name, read ="value".

Returns
true and fills out (NUL-terminated) if a quoted value was parsed.

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]tagReadable tag byte span.
[in]tag_lenReadable tag length.
[in,out]kCurrent bounded scan offset.
[out]outCaller-owned result storage.
[in]out_capDestination capacity including any terminator.
Return values
trueThe documented predicate holds or the requested operation completed.
falseThe predicate does not hold or validation rejected the operation.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 143 of file mdl_extract_internal.h.

References internal_skip_ws().

Referenced by internal_find_attr_value().

◆ internal_skip_ws()

size_t internal_skip_ws ( const char * tag,
size_t tag_len,
size_t k )
inlinestatic

Advance past spaces/tabs in [k, tag_len).

Applies locale-independent HTML token rules to caller-owned text. Offsets and copies remain inside supplied spans and capacities.

Parameters
[in]tagReadable tag byte span.
[in]tag_lenReadable tag length.
[in,out]kCurrent bounded scan offset.
Returns
First offset at or after k that is not a space or tab.
Return values
tag_lenOnly whitespace remains through the end of the span.
otherFirst non-whitespace offset in the span.
Precondition
Every required pointer is non-null and remains valid for the call.
Lengths and capacities describe complete referenced objects without overflow.
Postcondition
Documented outputs and the return value describe the same outcome.
A rejected or failed operation is never reported as successful.
Note
Thread safety follows ownership of the supplied context; no synchronization is added.
Since
Version 0.1.0

Definition at line 114 of file mdl_extract_internal.h.

References RA8_INTERNAL.

Referenced by internal_read_eq_value().