| Top |
The stateless URL scanner recognizes explicit URI schemes, bare www. and ftp. hostnames, and email addresses. Matches use UTF-8 byte offsets and include a prefix for constructing link targets. This is the same scanner used by GMimeTextToHtml and GMimeFlowedToHtml.
Scanning detects links in prose; it does not validate arbitrary URIs or determine whether a link is safe to open. Applications must apply their own scheme policy and escape link targets and visible text when generating HTML.
gboolean g_mime_url_scan (const char *text,gsize start,gsize length,GMimeUrlMatch *match);
Finds the next URL or email address in the specified range. The range must
contain valid UTF-8 and begin and end on character boundaries; UTF-8 is not
validated by this function. The buffer must contain at least start
+
length
bytes, but need not be NUL-terminated. Embedded NUL bytes act as
separators rather than terminating the scan.
Match offsets are relative to text
, not start
, and the end offset is
exclusive. To find subsequent matches, resume at the previous match's end
offset and reduce length
accordingly. No bytes outside the specified range
are examined. On failure to find a match, match
is left unchanged.
Recognized schemes are mailto:, telnet://, webcal://, https://, callto:, file://, sftp://, http://, news://, nntp://, h323:, ftp://, and sip:. Scheme matching is case-insensitive. Bare www. and ftp. names and email addresses are also recognized. Surrounding punctuation is excluded when possible; matching is intended for links in prose, not URI validation.
text |
a UTF-8 text buffer |
|
start |
the byte offset at which to begin scanning |
|
length |
the number of bytes to scan, starting at |
|
match |
storage for the match. |
[out caller-allocates] |
typedef struct {
gsize start;
gsize end;
const char *prefix;
} GMimeUrlMatch;
A URL or email address found by g_mime_url_scan(). Prepend prefix
to the
matched text to form the link target. The prefix is "http://" for bare
www. names, "ftp://" for bare ftp. names, and "mailto:" for email addresses.
The match does not own any memory and requires no cleanup.