1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Simple-XML-Subset-Parser.html
27  * outPack = glib
28  * outFile = SimpleXML
29  * strct   = GMarkupParseContext
30  * realStrct=
31  * ctorStrct=
32  * clss    = SimpleXML
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_markup_parse_context_
41  * 	- g_markup_
42  * omit structs:
43  * omit prefixes:
44  * omit code:
45  * omit signals:
46  * imports:
47  * 	- glib.ListSG
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * 	- glib.Str
51  * structWrap:
52  * 	- GSList* -> ListSG
53  * module aliases:
54  * local aliases:
55  * overrides:
56  */
57 
58 module glib.SimpleXML;
59 
60 public  import gtkc.glibtypes;
61 
62 private import gtkc.glib;
63 private import glib.ConstructionException;
64 
65 
66 private import glib.ListSG;
67 private import glib.ErrorG;
68 private import glib.GException;
69 private import glib.Str;
70 
71 
72 
73 
74 /**
75  * Description
76  * The "GMarkup" parser is intended to parse a simple markup format
77  * that's a subset of XML. This is a small, efficient, easy-to-use
78  * parser. It should not be used if you expect to interoperate with
79  * other applications generating full-scale XML. However, it's very
80  * useful for application data files, config files, etc. where you
81  * know your application will be the only one writing the file.
82  * Full-scale XML parsers should be able to parse the subset used by
83  * GMarkup, so you can easily migrate to full-scale XML at a later
84  * time if the need arises.
85  * GMarkup is not guaranteed to signal an error on all invalid XML;
86  * the parser may accept documents that an XML parser would not.
87  * However, XML documents which are not well-formed[5]
88  * are not considered valid GMarkup documents.
89  * Simplifications to XML include:
90  * Only UTF-8 encoding is allowed
91  * No user-defined entities
92  * Processing instructions, comments and the doctype declaration
93  * are "passed through" but are not interpreted in any way
94  * No DTD or validation.
95  * The markup format does support:
96  * Elements
97  * Attributes
98  * 5 standard entities:
99  *  amp; lt; gt; quot; apos;
100  * Character references
101  * Sections marked as CDATA
102  */
103 public class SimpleXML
104 {
105 	
106 	/** the main Gtk struct */
107 	protected GMarkupParseContext* gMarkupParseContext;
108 	
109 	
110 	public GMarkupParseContext* getSimpleXMLStruct()
111 	{
112 		return gMarkupParseContext;
113 	}
114 	
115 	
116 	/** the main Gtk struct as a void* */
117 	protected void* getStruct()
118 	{
119 		return cast(void*)gMarkupParseContext;
120 	}
121 	
122 	/**
123 	 * Sets our main struct and passes it to the parent class
124 	 */
125 	public this (GMarkupParseContext* gMarkupParseContext)
126 	{
127 		this.gMarkupParseContext = gMarkupParseContext;
128 	}
129 	
130 	/**
131 	 */
132 	
133 	/**
134 	 * Escapes text so that the markup parser will parse it verbatim.
135 	 * Less than, greater than, ampersand, etc. are replaced with the
136 	 * corresponding entities. This function would typically be used
137 	 * when writing out a file to be parsed with the markup parser.
138 	 * Note that this function doesn't protect whitespace and line endings
139 	 * from being processed according to the XML rules for normalization
140 	 * of line endings and attribute values.
141 	 * Note also that this function will produce character references in
142 	 * the range of x1; ... x1f; for all control sequences
143 	 * except for tabstop, newline and carriage return. The character
144 	 * references in this range are not valid XML 1.0, but they are
145 	 * valid XML 1.1 and will be accepted by the GMarkup parser.
146 	 * Params:
147 	 * text = some valid UTF-8 text
148 	 * length = length of text in bytes, or -1 if the text is nul-terminated
149 	 * Returns: a newly allocated string with the escaped text
150 	 */
151 	public static string escapeText(string text, gssize length)
152 	{
153 		// gchar * g_markup_escape_text (const gchar *text,  gssize length);
154 		return Str.toString(g_markup_escape_text(Str.toStringz(text), length));
155 	}
156 	
157 	/**
158 	 * Formats the data in args according to format, escaping
159 	 * all string and character arguments in the fashion
160 	 * of g_markup_escape_text(). See g_markup_printf_escaped().
161 	 * Since 2.4
162 	 * Params:
163 	 * format = printf() style format string
164 	 * args = variable argument list, similar to vprintf()
165 	 * Returns: newly allocated result from formatting operation. Free with g_free().
166 	 */
167 	public static string vprintfEscaped(string format, void* args)
168 	{
169 		// gchar * g_markup_vprintf_escaped (const char *format,  va_list args);
170 		return Str.toString(g_markup_vprintf_escaped(Str.toStringz(format), args));
171 	}
172 	
173 	/**
174 	 * Signals to the GMarkupParseContext that all data has been
175 	 * fed into the parse context with g_markup_parse_context_parse().
176 	 * This function reports an error if the document isn't complete,
177 	 * for example if elements are still open.
178 	 * Returns: TRUE on success, FALSE if an error was set
179 	 * Throws: GException on failure.
180 	 */
181 	public int endParse()
182 	{
183 		// gboolean g_markup_parse_context_end_parse (GMarkupParseContext *context,  GError **error);
184 		GError* err = null;
185 		
186 		auto p = g_markup_parse_context_end_parse(gMarkupParseContext, &err);
187 		
188 		if (err !is null)
189 		{
190 			throw new GException( new ErrorG(err) );
191 		}
192 		
193 		return p;
194 	}
195 	
196 	/**
197 	 * Frees a GMarkupParseContext.
198 	 * This function can't be called from inside one of the
199 	 * GMarkupParser functions or while a subparser is pushed.
200 	 */
201 	public void free()
202 	{
203 		// void g_markup_parse_context_free (GMarkupParseContext *context);
204 		g_markup_parse_context_free(gMarkupParseContext);
205 	}
206 	
207 	/**
208 	 * Retrieves the current line number and the number of the character on
209 	 * that line. Intended for use in error messages; there are no strict
210 	 * semantics for what constitutes the "current" line number other than
211 	 * "the best number we could come up with for error messages."
212 	 * Params:
213 	 * lineNumber = return location for a line number, or NULL. [allow-none]
214 	 * charNumber = return location for a char-on-line number, or NULL. [allow-none]
215 	 */
216 	public void getPosition(out int lineNumber, out int charNumber)
217 	{
218 		// void g_markup_parse_context_get_position (GMarkupParseContext *context,  gint *line_number,  gint *char_number);
219 		g_markup_parse_context_get_position(gMarkupParseContext, &lineNumber, &charNumber);
220 	}
221 	
222 	/**
223 	 * Retrieves the name of the currently open element.
224 	 * If called from the start_element or end_element handlers this will
225 	 * give the element_name as passed to those functions. For the parent
226 	 * elements, see g_markup_parse_context_get_element_stack().
227 	 * Since 2.2
228 	 * Returns: the name of the currently open element, or NULL
229 	 */
230 	public string getElement()
231 	{
232 		// const gchar * g_markup_parse_context_get_element (GMarkupParseContext *context);
233 		return Str.toString(g_markup_parse_context_get_element(gMarkupParseContext));
234 	}
235 	
236 	/**
237 	 * Retrieves the element stack from the internal state of the parser.
238 	 * The returned GSList is a list of strings where the first item is
239 	 * the currently open tag (as would be returned by
240 	 * g_markup_parse_context_get_element()) and the next item is its
241 	 * immediate parent.
242 	 * This function is intended to be used in the start_element and
243 	 * end_element handlers where g_markup_parse_context_get_element()
244 	 * would merely return the name of the element that is being
245 	 * processed.
246 	 * Since 2.16
247 	 * Returns: the element stack, which must not be modified
248 	 */
249 	public ListSG getElementStack()
250 	{
251 		// const GSList * g_markup_parse_context_get_element_stack  (GMarkupParseContext *context);
252 		auto p = g_markup_parse_context_get_element_stack(gMarkupParseContext);
253 		
254 		if(p is null)
255 		{
256 			return null;
257 		}
258 		
259 		return new ListSG(cast(GSList*) p);
260 	}
261 	
262 	/**
263 	 * Returns the user_data associated with context.
264 	 * This will either be the user_data that was provided to
265 	 * g_markup_parse_context_new() or to the most recent call
266 	 * of g_markup_parse_context_push().
267 	 * Since 2.18
268 	 * Returns: the provided user_data. The returned data belongs to the markup context and will be freed when g_markup_context_free() is called.
269 	 */
270 	public void* getUserData()
271 	{
272 		// gpointer g_markup_parse_context_get_user_data  (GMarkupParseContext *context);
273 		return g_markup_parse_context_get_user_data(gMarkupParseContext);
274 	}
275 	
276 	/**
277 	 * Creates a new parse context. A parse context is used to parse
278 	 * marked-up documents. You can feed any number of documents into
279 	 * a context, as long as no errors occur; once an error occurs,
280 	 * the parse context can't continue to parse text (you have to
281 	 * free it and create a new parse context).
282 	 * Params:
283 	 * parser = a GMarkupParser
284 	 * flags = one or more GMarkupParseFlags
285 	 * userData = user data to pass to GMarkupParser functions
286 	 * userDataDnotify = user data destroy notifier called when
287 	 * the parse context is freed
288 	 * Throws: ConstructionException GTK+ fails to create the object.
289 	 */
290 	public this (GMarkupParser* parser, GMarkupParseFlags flags, void* userData, GDestroyNotify userDataDnotify)
291 	{
292 		// GMarkupParseContext * g_markup_parse_context_new (const GMarkupParser *parser,  GMarkupParseFlags flags,  gpointer user_data,  GDestroyNotify user_data_dnotify);
293 		auto p = g_markup_parse_context_new(parser, flags, userData, userDataDnotify);
294 		if(p is null)
295 		{
296 			throw new ConstructionException("null returned by g_markup_parse_context_new(parser, flags, userData, userDataDnotify)");
297 		}
298 		this(cast(GMarkupParseContext*) p);
299 	}
300 	
301 	/**
302 	 * Feed some data to the GMarkupParseContext.
303 	 * The data need not be valid UTF-8; an error will be signaled if
304 	 * it's invalid. The data need not be an entire document; you can
305 	 * feed a document into the parser incrementally, via multiple calls
306 	 * to this function. Typically, as you receive data from a network
307 	 * connection or file, you feed each received chunk of data into this
308 	 * function, aborting the process if an error occurs. Once an error
309 	 * is reported, no further data may be fed to the GMarkupParseContext;
310 	 * all errors are fatal.
311 	 * Params:
312 	 * text = chunk of text to parse
313 	 * textLen = length of text in bytes
314 	 * Returns: FALSE if an error occurred, TRUE on success
315 	 * Throws: GException on failure.
316 	 */
317 	public int parse(string text, gssize textLen)
318 	{
319 		// gboolean g_markup_parse_context_parse (GMarkupParseContext *context,  const gchar *text,  gssize text_len,  GError **error);
320 		GError* err = null;
321 		
322 		auto p = g_markup_parse_context_parse(gMarkupParseContext, Str.toStringz(text), textLen, &err);
323 		
324 		if (err !is null)
325 		{
326 			throw new GException( new ErrorG(err) );
327 		}
328 		
329 		return p;
330 	}
331 	
332 	/**
333 	 * Temporarily redirects markup data to a sub-parser.
334 	 * This function may only be called from the start_element handler of
335 	 * a GMarkupParser. It must be matched with a corresponding call to
336 	 * g_markup_parse_context_pop() in the matching end_element handler
337 	 * (except in the case that the parser aborts due to an error).
338 	 * All tags, text and other data between the matching tags is
339 	 * redirected to the subparser given by parser. user_data is used
340 	 * as the user_data for that parser. user_data is also passed to the
341 	 * error callback in the event that an error occurs. This includes
342 	 * errors that occur in subparsers of the subparser.
343 	 * The end tag matching the start tag for which this call was made is
344 	 * handled by the previous parser (which is given its own user_data)
345 	 * which is why g_markup_parse_context_pop() is provided to allow "one
346 	 * last access" to the user_data provided to this function. In the
347 	 * case of error, the user_data provided here is passed directly to
348 	 * the error callback of the subparser and g_markup_parse_context()
349 	 * should not be called. In either case, if user_data was allocated
350 	 * then it ought to be freed from both of these locations.
351 	 * This function is not intended to be directly called by users
352 	 * interested in invoking subparsers. Instead, it is intended to be
353 	 * used by the subparsers themselves to implement a higher-level
354 	 * interface.
355 	 * As an example, see the following implementation of a simple
356 	 * parser that counts the number of tags encountered.
357 	 * $(DDOC_COMMENT example)
358 	 * In order to allow this parser to be easily used as a subparser, the
359 	 * Since 2.18
360 	 * Params:
361 	 * parser = a GMarkupParser
362 	 * userData = user data to pass to GMarkupParser functions
363 	 */
364 	public void push(GMarkupParser* parser, void* userData)
365 	{
366 		// void g_markup_parse_context_push (GMarkupParseContext *context,  const GMarkupParser *parser,  gpointer user_data);
367 		g_markup_parse_context_push(gMarkupParseContext, parser, userData);
368 	}
369 	
370 	/**
371 	 * Completes the process of a temporary sub-parser redirection.
372 	 * This function exists to collect the user_data allocated by a
373 	 * matching call to g_markup_parse_context_push(). It must be called
374 	 * in the end_element handler corresponding to the start_element
375 	 * handler during which g_markup_parse_context_push() was called.
376 	 * You must not call this function from the error callback -- the
377 	 * user_data is provided directly to the callback in that case.
378 	 * This function is not intended to be directly called by users
379 	 * interested in invoking subparsers. Instead, it is intended to
380 	 * be used by the subparsers themselves to implement a higher-level
381 	 * interface.
382 	 * Since 2.18
383 	 * Returns: the user data passed to g_markup_parse_context_push()
384 	 */
385 	public void* pop()
386 	{
387 		// gpointer g_markup_parse_context_pop (GMarkupParseContext *context);
388 		return g_markup_parse_context_pop(gMarkupParseContext);
389 	}
390 }