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 module glib.UriParamsIter;
26 
27 private import glib.ErrorG;
28 private import glib.GException;
29 private import glib.Str;
30 private import glib.c.functions;
31 public  import glib.c.types;
32 
33 
34 /**
35  * Many URI schemes include one or more attribute/value pairs as part of the URI
36  * value. For example `scheme://server/path?query=string&is=there` has two
37  * attributes – `query=string` and `is=there` – in its query part.
38  * 
39  * A #GUriParamsIter structure represents an iterator that can be used to
40  * iterate over the attribute/value pairs of a URI query string. #GUriParamsIter
41  * structures are typically allocated on the stack and then initialized with
42  * g_uri_params_iter_init(). See the documentation for g_uri_params_iter_init()
43  * for a usage example.
44  *
45  * Since: 2.66
46  */
47 public class UriParamsIter
48 {
49 	/** the main Gtk struct */
50 	protected GUriParamsIter* gUriParamsIter;
51 	protected bool ownedRef;
52 
53 	/** Get the main Gtk struct */
54 	public GUriParamsIter* getUriParamsIterStruct(bool transferOwnership = false)
55 	{
56 		if (transferOwnership)
57 			ownedRef = false;
58 		return gUriParamsIter;
59 	}
60 
61 	/** the main Gtk struct as a void* */
62 	protected void* getStruct()
63 	{
64 		return cast(void*)gUriParamsIter;
65 	}
66 
67 	/**
68 	 * Sets our main struct and passes it to the parent class.
69 	 */
70 	public this (GUriParamsIter* gUriParamsIter, bool ownedRef = false)
71 	{
72 		this.gUriParamsIter = gUriParamsIter;
73 		this.ownedRef = ownedRef;
74 	}
75 
76 
77 	/**
78 	 * Initializes an attribute/value pair iterator.
79 	 *
80 	 * The iterator keeps pointers to the @params and @separators arguments, those
81 	 * variables must thus outlive the iterator and not be modified during the
82 	 * iteration.
83 	 *
84 	 * If %G_URI_PARAMS_WWW_FORM is passed in @flags, `+` characters in the param
85 	 * string will be replaced with spaces in the output. For example, `foo=bar+baz`
86 	 * will give attribute `foo` with value `bar baz`. This is commonly used on the
87 	 * web (the `https` and `http` schemes only), but is deprecated in favour of
88 	 * the equivalent of encoding spaces as `%20`.
89 	 *
90 	 * Unlike with g_uri_parse_params(), %G_URI_PARAMS_CASE_INSENSITIVE has no
91 	 * effect if passed to @flags for g_uri_params_iter_init(). The caller is
92 	 * responsible for doing their own case-insensitive comparisons.
93 	 *
94 	 * |[<!-- language="C" -->
95 	 * GUriParamsIter iter;
96 	 * GError *error = NULL;
97 	 * gchar *unowned_attr, *unowned_value;
98 	 *
99 	 * g_uri_params_iter_init (&iter, "foo=bar&baz=bar&Foo=frob&baz=bar2", -1, "&", G_URI_PARAMS_NONE);
100 	 * while (g_uri_params_iter_next (&iter, &unowned_attr, &unowned_value, &error))
101 	 * {
102 	 * g_autofree gchar *attr = g_steal_pointer (&unowned_attr);
103 	 * g_autofree gchar *value = g_steal_pointer (&unowned_value);
104 	 * // do something with attr and value; this code will be called 4 times
105 	 * // for the params string in this example: once with attr=foo and value=bar,
106 	 * // then with baz/bar, then Foo/frob, then baz/bar2.
107 	 * }
108 	 * if (error)
109 	 * // handle parsing error
110 	 * ]|
111 	 *
112 	 * Params:
113 	 *     params = a `%`-encoded string containing `attribute=value`
114 	 *         parameters
115 	 *     length = the length of @params, or `-1` if it is nul-terminated
116 	 *     separators = the separator byte character set between parameters. (usually
117 	 *         `&`, but sometimes `;` or both `&;`). Note that this function works on
118 	 *         bytes not characters, so it can't be used to delimit UTF-8 strings for
119 	 *         anything but ASCII characters. You may pass an empty set, in which case
120 	 *         no splitting will occur.
121 	 *     flags = flags to modify the way the parameters are handled.
122 	 *
123 	 * Since: 2.66
124 	 */
125 	public void init(string params, ptrdiff_t length, string separators, GUriParamsFlags flags)
126 	{
127 		g_uri_params_iter_init(gUriParamsIter, Str.toStringz(params), length, Str.toStringz(separators), flags);
128 	}
129 
130 	/**
131 	 * Advances @iter and retrieves the next attribute/value. %FALSE is returned if
132 	 * an error has occurred (in which case @error is set), or if the end of the
133 	 * iteration is reached (in which case @attribute and @value are set to %NULL
134 	 * and the iterator becomes invalid). If %TRUE is returned,
135 	 * g_uri_params_iter_next() may be called again to receive another
136 	 * attribute/value pair.
137 	 *
138 	 * Note that the same @attribute may be returned multiple times, since URIs
139 	 * allow repeated attributes.
140 	 *
141 	 * Params:
142 	 *     attribute = on return, contains
143 	 *         the attribute, or %NULL.
144 	 *     value = on return, contains
145 	 *         the value, or %NULL.
146 	 *
147 	 * Returns: %FALSE if the end of the parameters has been reached or an error was
148 	 *     encountered. %TRUE otherwise.
149 	 *
150 	 * Since: 2.66
151 	 *
152 	 * Throws: GException on failure.
153 	 */
154 	public bool next(out string attribute, out string value)
155 	{
156 		char* outattribute = null;
157 		char* outvalue = null;
158 		GError* err = null;
159 
160 		auto __p = g_uri_params_iter_next(gUriParamsIter, &outattribute, &outvalue, &err) != 0;
161 
162 		if (err !is null)
163 		{
164 			throw new GException( new ErrorG(err) );
165 		}
166 
167 		attribute = Str.toString(outattribute);
168 		value = Str.toString(outvalue);
169 
170 		return __p;
171 	}
172 }