Encode and decode `rune`s to/from a Unicode `&entity;`. This code has several procedures to map unicode runes to/from different textual encodings. - SGML/XML/HTML entity - &#<decimal>; - &#x<hexadecimal>; - &<entity name>; (If the lookup tables are compiled in). Reference: [[ https://www.w3.org/2003/entities/2007xml/unicode.xml ]] - URL encode / decode %hex entity Reference: [[ https://datatracker.ietf.org/doc/html/rfc3986/#section-2.1 ]]

Collection Info

View Source
Collection
core
Path
encoding/entity
Entries
18

Source Files

Constants

7

MAX_RUNE_CODEPOINT #

Source
MAX_RUNE_CODEPOINT :: int(unicode.MAX_RUNE)

XML_NAME_TO_RUNE_MAX_LENGTH #

Source
XML_NAME_TO_RUNE_MAX_LENGTH :: 31

`&CounterClockwiseContourIntegral;`

XML_NAME_TO_RUNE_MIN_LENGTH #

Source
XML_NAME_TO_RUNE_MIN_LENGTH :: 2

`&lt;`

Types

4

Procedures

7

decode_xml #

Source
decode_xml :: proc(input: string, options: bit_set[XML_Decode_Option] = XML_Decode_Options{}, allocator := context.allocator) -> (decoded: string, err: Error) {…}

Decode a string that may include SGML/XML/HTML entities. The caller has to free the result.

escape_html #

Source
@(require_results)
escape_html :: proc(s: string, allocator := context.allocator, loc := #caller_location) -> (output: string, was_allocation: bool) {…}

escape_html escapes special characters like '&' to become '&amp;'. It escapes only 5 different characters: & ' < > and "

named_xml_entity_to_rune #

Source
named_xml_entity_to_rune :: proc(name: string) -> (decoded: [2]rune, rune_count: int, ok: bool) {…}

Input: entity_name - a string, like "copy" that describes a user-encoded Unicode entity as used in XML. Returns: "decoded" - The decoded runes if found by name, or all zero otherwise. "rune_count" - The number of decoded runes "ok" - true if found, false if not. IMPORTANT: XML processors (including browsers) treat these names as case-sensitive. So do we.

unescape_entity #

Source
@(require_results)
unescape_entity :: proc(s: string) -> (b: [8]u8, w: int, j: int) {…}

Returns an unescaped string of an encoded XML/HTML entity.