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