| Top |
The tokenizer retains, but never closes, its input stream. The ordinary constructor accepts UTF-8; the charset constructor can also detect Unicode byte order marks. Invalid UTF-8 and native input errors are propagated. Positions and compliance offsets count Unicode scalars, not UTF-8 bytes.
read_next_token() returns TRUE with a new token, TRUE with a NULL token at
end of input, or FALSE on error. Tokens remain valid across subsequent reads.
The depth limit counts folded, distinct open-element stack entries. By
default, a structural limit makes the tokenizer treat the remaining input
as literal text. See g_mime_html_tokenizer_set_limit_exceeded_behavior().
GMimeHtmlTokenizer *
g_mime_html_tokenizer_new (GMimeStream *stream);
Creates a tokenizer which retains stream
without closing it.
GMimeHtmlTokenizer * g_mime_html_tokenizer_new_with_charset (GMimeStream *stream,const char *charset,gboolean detect_bom,gsize buffer_size,GError **error);
Creates a tokenizer with character-set decoding. The tokenizer retains
stream
without closing it.
stream |
the input stream. |
[transfer none] |
charset |
the input character set |
|
detect_bom |
whether to detect a byte-order mark |
|
buffer_size |
the input buffer size |
|
error |
return location for an error. |
[out][optional] |
gboolean g_mime_html_tokenizer_read_next_token (GMimeHtmlTokenizer *tokenizer,GMimeHtmlToken **token,GError **error);
Reads the next token. A successful read at end of input sets token
to
NULL. On failure, token
is also set to NULL and error
is set.
With GMIME_HTML_LIMIT_EXCEEDED_BEHAVIOR_FAIL, the read that encounters a
structural limit fails with GMIME_ERROR_PARSE_ERROR in the GMIME_ERROR
domain. Subsequent reads return end of input.
tokenizer |
||
token |
the next token, or |
[out][transfer full][nullable] |
error |
return location for an error. |
[out][optional] |
gboolean
g_mime_html_tokenizer_get_decode_character_references
(GMimeHtmlTokenizer *tokenizer);
Gets whether character references in text are decoded. The default is TRUE.
Attribute references are always decoded.
void g_mime_html_tokenizer_set_decode_character_references (GMimeHtmlTokenizer *tokenizer,gboolean value);
Sets whether text references are decoded. Attribute references are always decoded, regardless of this setting.
GMimeHtmlNamespace
g_mime_html_tokenizer_get_namespace (GMimeHtmlTokenizer *tokenizer);
Gets the document namespace. The default is GMIME_HTML_NAMESPACE_HTML;
an HTML element's namespace declaration can update it while parsing.
void g_mime_html_tokenizer_set_namespace (GMimeHtmlTokenizer *tokenizer,GMimeHtmlNamespace ns);
Sets the document namespace used by tree construction.
gboolean
g_mime_html_tokenizer_get_ignore_truncated_tags
(GMimeHtmlTokenizer *tokenizer);
Gets whether incomplete tags at end of input are discarded. The default is
FALSE, preserving truncated tag text.
void g_mime_html_tokenizer_set_ignore_truncated_tags (GMimeHtmlTokenizer *tokenizer,gboolean value);
Sets how truncated tags are handled. This does not disable compliance diagnostics for those tags.
guint
g_mime_html_tokenizer_get_max_element_depth
(GMimeHtmlTokenizer *tokenizer);
Gets the maximum number of distinct open-element stack entries. Consecutive identical elements can share an entry. The default is 4096.
void g_mime_html_tokenizer_set_max_element_depth (GMimeHtmlTokenizer *tokenizer,guint maximum);
Sets the open-element stack limit. Exceeding it reports
GMIME_HTML_COMPLIANCE_VIOLATION_ELEMENT_DEPTH_LIMIT_EXCEEDED when a logger is
installed. By default the remaining input is treated as literal text;
g_mime_html_tokenizer_set_limit_exceeded_behavior() can request failure instead.
gboolean
g_mime_html_tokenizer_get_formatting_recovery_enabled
(GMimeHtmlTokenizer *tokenizer);
void g_mime_html_tokenizer_set_formatting_recovery_enabled (GMimeHtmlTokenizer *tokenizer,gboolean enabled);
Change this option before the first call to g_mime_html_tokenizer_read_next_token().
Recovery follows formatting that a browser may reconstruct after an implicit
close, without emitting extra tokens. It uses bounded state independent of
the element depth limit. If reconstruction cannot continue, the configured
limit-exceeded behavior applies.
With recovery disabled, malformed formatting mixed with SVG or MathML can
cause markup recognized by a browser to be tokenized as text or a comment.
GMimeHtmlLimitExceededBehavior
g_mime_html_tokenizer_get_limit_exceeded_behavior
(GMimeHtmlTokenizer *tokenizer);
void g_mime_html_tokenizer_set_limit_exceeded_behavior (GMimeHtmlTokenizer *tokenizer,GMimeHtmlLimitExceededBehavior value);
By default, a tag that exceeds a limit is the last tag returned and the remainder is literal text. In fail mode the triggering token is not returned. Both modes report the violation to the compliance logger.
gboolean
g_mime_html_tokenizer_get_scripting_enabled
(GMimeHtmlTokenizer *tokenizer);
Gets the scripting mode used to interpret noscript elements. The default is
FALSE. The tokenizer never executes scripts.
void g_mime_html_tokenizer_set_scripting_enabled (GMimeHtmlTokenizer *tokenizer,gboolean enabled);
Sets whether noscript content is treated as raw text. This should match the scripting mode of the intended renderer; it does not execute any scripts.
gint64
g_mime_html_tokenizer_get_position (GMimeHtmlTokenizer *tokenizer);
Gets the number of Unicode scalar values consumed, rather than a byte offset in the input stream. Buffered input may extend beyond this position.
int
g_mime_html_tokenizer_get_line_number (GMimeHtmlTokenizer *tokenizer);
Gets the line number of the next input character. LF advances the line number; a standalone CR does not.
int
g_mime_html_tokenizer_get_line_position
(GMimeHtmlTokenizer *tokenizer);
Gets the column of the next input character, measured in Unicode scalar values rather than bytes.
GMimeHtmlTokenizerState
g_mime_html_tokenizer_get_state (GMimeHtmlTokenizer *tokenizer);
Gets the current lexical state. A new tokenizer starts in
GMIME_HTML_TOKENIZER_STATE_DATA.
void g_mime_html_tokenizer_set_compliance_logger (GMimeHtmlTokenizer *tokenizer,GMimeHtmlComplianceLogger logger,gpointer user_data,GDestroyNotify destroy);
Sets the diagnostic callback, or disables reporting when logger
is NULL.
The previous callback's data is released when replaced. The new data is
released when the callback is replaced or the tokenizer is finalized.
GMimeHtmlComplianceOptions *
g_mime_html_tokenizer_get_compliance_options
(GMimeHtmlTokenizer *tokenizer);
void g_mime_html_tokenizer_set_compliance_options (GMimeHtmlTokenizer *tokenizer,GMimeHtmlComplianceOptions *options);
Retains a reference to options
.