📄 markup.sgml
字号:
void (*passthrough) (GMarkupParseContext *context, const gchar *passthrough_text, gsize text_len, gpointer user_data, GError **error); /* Called on error, including one set by other * methods in the vtable. The GError should not be freed. */ void (*error) (GMarkupParseContext *context, GError *error, gpointer user_data);};</programlisting><para>Any of the fields in <link linkend="GMarkupParser">GMarkupParser</link> can be <literal>NULL</literal>, in which case theywill be ignored. Except for the <parameter>error</parameter> function, any of thesecallbacks can set an error; in particular the<literal>G_MARKUP_ERROR_UNKNOWN_ELEMENT</literal>, <literal>G_MARKUP_ERROR_UNKNOWN_ATTRIBUTE</literal>,and <literal>G_MARKUP_ERROR_INVALID_CONTENT</literal> errors are intended to be set from these callbacks. If you set an error from a callback,<link linkend="g-markup-parse-context-parse">g_markup_parse_context_parse</link>() will report that error back to its caller.</para><informaltable pgwide="1" frame="none" role="struct"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry>void (*<structfield>start_element</structfield>) (GMarkupParseContext *context, const gchar *element_name, const gchar **attribute_names, const gchar **attribute_values, gpointer user_data, GError **error)</entry><entry>Callback to invoke when the opening tag of an elementis seen.</entry></row><row><entry>void (*<structfield>end_element</structfield>) (GMarkupParseContext *context, const gchar *element_name, gpointer user_data, GError **error)</entry><entry>Callback to invoke when the closing tag of an element is seen</entry></row><row><entry>void (*<structfield>text</structfield>) (GMarkupParseContext *context, const gchar *text, gsize text_len, gpointer user_data, GError **error)</entry><entry>Callback to invoke when some text is seen (text is alwaysinside an element)</entry></row><row><entry>void (*<structfield>passthrough</structfield>) (GMarkupParseContext *context, const gchar *passthrough_text, gsize text_len, gpointer user_data, GError **error)</entry><entry>Callback to invoke for comments and processinginstructions; if you're re-writing the parsed document, write thepassthrough text back out in the same position</entry></row><row><entry>void (*<structfield>error</structfield>) (GMarkupParseContext *context, GError *error, gpointer user_data)</entry><entry>Callback to invoke when an error occurs</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-escape-text">g_markup_escape_text ()</title><programlisting><link linkend="gchar">gchar</link>* g_markup_escape_text (const <link linkend="gchar">gchar</link> *text, <link linkend="gssize">gssize</link> length);</programlisting><para>Escapes text so that the markup parser will parse it verbatim.Less than, greater than, ampersand, etc. are replaced with thecorresponding entities. This function would typically be usedwhen writing out a file to be parsed with the markup parser.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>text</parameter> :</entry><entry> some valid UTF-8 text</entry></row><row><entry align="right"><parameter>length</parameter> :</entry><entry> length of <parameter>text</parameter> in bytes</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> escaped text</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-parse-context-end-parse">g_markup_parse_context_end_parse ()</title><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_end_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context, <link linkend="GError">GError</link> **error);</programlisting><para>Signals to the <link linkend="GMarkupParseContext">GMarkupParseContext</link> that all data has beenfed into the parse context with <link linkend="g-markup-parse-context-parse">g_markup_parse_context_parse</link>().This function reports an error if the document isn't complete,for example if elements are still open.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>context</parameter> :</entry><entry> a <link linkend="GMarkupParseContext">GMarkupParseContext</link></entry></row><row><entry align="right"><parameter>error</parameter> :</entry><entry> return location for a <link linkend="GError">GError</link></entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <literal>TRUE</literal> on success, <literal>FALSE</literal> if an error was set</entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-parse-context-free">g_markup_parse_context_free ()</title><programlisting>void g_markup_parse_context_free (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context);</programlisting><para>Frees a <link linkend="GMarkupParseContext">GMarkupParseContext</link>. Can't be called from insideone of the <link linkend="GMarkupParser">GMarkupParser</link> functions.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>context</parameter> :</entry><entry> a <link linkend="GMarkupParseContext">GMarkupParseContext</link></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-parse-context-get-position">g_markup_parse_context_get_position ()</title><programlisting>void g_markup_parse_context_get_position (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context, <link linkend="gint">gint</link> *line_number, <link linkend="gint">gint</link> *char_number);</programlisting><para>Retrieves the current line number and the number of the character onthat line. Intended for use in error messages; there are no strictsemantics for what constitutes the "current" line number other than"the best number we could come up with for error messages."</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>context</parameter> :</entry><entry> a <link linkend="GMarkupParseContext">GMarkupParseContext</link></entry></row><row><entry align="right"><parameter>line_number</parameter> :</entry><entry> return location for a line number, or <literal>NULL</literal></entry></row><row><entry align="right"><parameter>char_number</parameter> :</entry><entry> return location for a char-on-line number, or <literal>NULL</literal></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-parse-context-new">g_markup_parse_context_new ()</title><programlisting><link linkend="GMarkupParseContext">GMarkupParseContext</link>* g_markup_parse_context_new (const <link linkend="GMarkupParser">GMarkupParser</link> *parser, <link linkend="GMarkupParseFlags">GMarkupParseFlags</link> flags, <link linkend="gpointer">gpointer</link> user_data, <link linkend="GDestroyNotify">GDestroyNotify</link> user_data_dnotify);</programlisting><para>Creates a new parse context. A parse context is used to parsemarked-up documents. You can feed any number of documents intoa context, as long as no errors occur; once an error occurs,the parse context can't continue to parse text (you have to free itand create a new parse context).</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>parser</parameter> :</entry><entry> a <link linkend="GMarkupParser">GMarkupParser</link></entry></row><row><entry align="right"><parameter>flags</parameter> :</entry><entry> one or more <link linkend="GMarkupParseFlags">GMarkupParseFlags</link></entry></row><row><entry align="right"><parameter>user_data</parameter> :</entry><entry> user data to pass to <link linkend="GMarkupParser">GMarkupParser</link> functions</entry></row><row><entry align="right"><parameter>user_data_dnotify</parameter> :</entry><entry> user data destroy notifier called when the parse context is freed</entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> a new <link linkend="GMarkupParseContext">GMarkupParseContext</link></entry></row></tbody></tgroup></informaltable></refsect2><refsect2><title><anchor id="g-markup-parse-context-parse">g_markup_parse_context_parse ()</title><programlisting><link linkend="gboolean">gboolean</link> g_markup_parse_context_parse (<link linkend="GMarkupParseContext">GMarkupParseContext</link> *context, const <link linkend="gchar">gchar</link> *text, <link linkend="gssize">gssize</link> text_len, <link linkend="GError">GError</link> **error);</programlisting><para>Feed some data to the <link linkend="GMarkupParseContext">GMarkupParseContext</link>. The data need notbe valid UTF-8; an error will be signaled if it's invalid.The data need not be an entire document; you can feed a documentinto the parser incrementally, via multiple calls to this function.Typically, as you receive data from a network connection or file,you feed each received chunk of data into this function, abortingthe process if an error occurs. Once an error is reported, no furtherdata may be fed to the <link linkend="GMarkupParseContext">GMarkupParseContext</link>; all errors are fatal.</para><para></para><informaltable pgwide="1" frame="none" role="params"><tgroup cols="2"><colspec colwidth="2*"><colspec colwidth="8*"><tbody><row><entry align="right"><parameter>context</parameter> :</entry><entry> a <link linkend="GMarkupParseContext">GMarkupParseContext</link></entry></row><row><entry align="right"><parameter>text</parameter> :</entry><entry> chunk of text to parse</entry></row><row><entry align="right"><parameter>text_len</parameter> :</entry><entry> length of <parameter>text</parameter> in bytes</entry></row><row><entry align="right"><parameter>error</parameter> :</entry><entry> return location for a <link linkend="GError">GError</link></entry></row><row><entry align="right"><emphasis>Returns</emphasis> :</entry><entry> <literal>FALSE</literal> if an error occurred, <literal>TRUE</literal> on success</entry></row></tbody></tgroup></informaltable></refsect2></refsect1></refentry>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -