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-URI-Functions.html
27  * outPack = glib
28  * outFile = URI
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = URI
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_uri_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * 	- glib.ErrorG
48  * 	- glib.GException
49  * structWrap:
50  * module aliases:
51  * local aliases:
52  * overrides:
53  */
54 
55 module glib.URI;
56 
57 public  import gtkc.glibtypes;
58 
59 private import gtkc.glib;
60 private import glib.ConstructionException;
61 
62 
63 private import glib.Str;
64 private import glib.ErrorG;
65 private import glib.GException;
66 
67 
68 
69 
70 /**
71  * Functions for manipulating Universal Resource Identifiers (URIs) as
72  * defined by
73  * RFC 3986. It is highly recommended that you have read and
74  * understand RFC 3986 for understanding this API.
75  */
76 public class URI
77 {
78 	
79 	/**
80 	 */
81 	
82 	/**
83 	 * Since 2.16
84 	 * Params:
85 	 * uri = a valid URI.
86 	 * Returns: The "Scheme" component of the URI, or NULL on error. The returned string should be freed when no longer needed.
87 	 */
88 	public static string parseScheme(string uri)
89 	{
90 		// char * g_uri_parse_scheme (const char *uri);
91 		return Str.toString(g_uri_parse_scheme(Str.toStringz(uri)));
92 	}
93 	
94 	/**
95 	 * Escapes a string for use in a URI.
96 	 * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
97 	 * characters plus dash, dot, underscore and tilde) are escaped.
98 	 * But if you specify characters in reserved_chars_allowed they are not
99 	 * escaped. This is useful for the "reserved" characters in the URI
100 	 * specification, since those are allowed unescaped in some portions of
101 	 * a URI.
102 	 * Since 2.16
103 	 * Params:
104 	 * unescaped = the unescaped input string.
105 	 * reservedCharsAllowed = a string of reserved characters that
106 	 * are allowed to be used, or NULL. [allow-none]
107 	 * allowUtf8 = TRUE if the result can include UTF-8 characters.
108 	 * Returns: an escaped version of unescaped. The returned string should be freed when no longer needed.
109 	 */
110 	public static string escapeString(string unescaped, string reservedCharsAllowed, int allowUtf8)
111 	{
112 		// char * g_uri_escape_string (const char *unescaped,  const char *reserved_chars_allowed,  gboolean allow_utf8);
113 		return Str.toString(g_uri_escape_string(Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8));
114 	}
115 	
116 	/**
117 	 * Unescapes a whole escaped string.
118 	 * If any of the characters in illegal_characters or the character zero appears
119 	 * as an escaped character in escaped_string then that is an error and NULL
120 	 * will be returned. This is useful it you want to avoid for instance having a
121 	 * slash being expanded in an escaped path element, which might confuse pathname
122 	 * handling.
123 	 * Since 2.16
124 	 * Params:
125 	 * escapedString = an escaped string to be unescaped.
126 	 * illegalCharacters = a string of illegal characters not to be
127 	 * allowed, or NULL. [allow-none]
128 	 * Returns: an unescaped version of escaped_string. The returned string should be freed when no longer needed.
129 	 */
130 	public static string unescapeString(string escapedString, string illegalCharacters)
131 	{
132 		// char * g_uri_unescape_string (const char *escaped_string,  const char *illegal_characters);
133 		return Str.toString(g_uri_unescape_string(Str.toStringz(escapedString), Str.toStringz(illegalCharacters)));
134 	}
135 	
136 	/**
137 	 * Unescapes a segment of an escaped string.
138 	 * If any of the characters in illegal_characters or the character zero appears
139 	 * as an escaped character in escaped_string then that is an error and NULL
140 	 * will be returned. This is useful it you want to avoid for instance having a
141 	 * slash being expanded in an escaped path element, which might confuse pathname
142 	 * handling.
143 	 * Since 2.16
144 	 * Params:
145 	 * escapedString = A string, may be NULL. [allow-none]
146 	 * escapedStringEnd = Pointer to end of escaped_string, may be NULL. [allow-none]
147 	 * illegalCharacters = An optional string of illegal characters not to be allowed, may be NULL. [allow-none]
148 	 * Returns: an unescaped version of escaped_string or NULL on error. The returned string should be freed when no longer needed. As a special case if NULL is given for escaped_string, this function will return NULL.
149 	 */
150 	public static string unescapeSegment(string escapedString, string escapedStringEnd, string illegalCharacters)
151 	{
152 		// char * g_uri_unescape_segment (const char *escaped_string,  const char *escaped_string_end,  const char *illegal_characters);
153 		return Str.toString(g_uri_unescape_segment(Str.toStringz(escapedString), Str.toStringz(escapedStringEnd), Str.toStringz(illegalCharacters)));
154 	}
155 	
156 	/**
157 	 * Splits an URI list conforming to the text/uri-list
158 	 * mime type defined in RFC 2483 into individual URIs,
159 	 * discarding any comments. The URIs are not validated.
160 	 * Since 2.6
161 	 * Params:
162 	 * uriList = an URI list
163 	 * Returns: a newly allocated NULL-terminated list of strings holding the individual URIs. The array should be freed with g_strfreev(). [transfer full]
164 	 */
165 	public static string[] listExtractUris(string uriList)
166 	{
167 		// gchar ** g_uri_list_extract_uris (const gchar *uri_list);
168 		return Str.toStringArray(g_uri_list_extract_uris(Str.toStringz(uriList)));
169 	}
170 	
171 	/**
172 	 * Converts an escaped ASCII-encoded URI to a local filename in the
173 	 * encoding used for filenames.
174 	 * Params:
175 	 * uri = a uri describing a filename (escaped, encoded in ASCII).
176 	 * hostname = Location to store hostname for the URI, or NULL.
177 	 * If there is no hostname in the URI, NULL will be
178 	 * stored in this location. [out][allow-none]
179 	 * Returns: a newly-allocated string holding the resulting filename, or NULL on an error. [type filename]
180 	 * Throws: GException on failure.
181 	 */
182 	public static string gFilenameFromUri(string uri, out string hostname)
183 	{
184 		// gchar * g_filename_from_uri (const gchar *uri,  gchar **hostname,  GError **error);
185 		char* outhostname = null;
186 		GError* err = null;
187 		
188 		auto p = g_filename_from_uri(Str.toStringz(uri), &outhostname, &err);
189 		
190 		if (err !is null)
191 		{
192 			throw new GException( new ErrorG(err) );
193 		}
194 		
195 		hostname = Str.toString(outhostname);
196 		return Str.toString(p);
197 	}
198 	
199 	/**
200 	 * Converts an absolute filename to an escaped ASCII-encoded URI, with the path
201 	 * component following Section 3.3. of RFC 2396.
202 	 * Params:
203 	 * filename = an absolute filename specified in the GLib file name encoding,
204 	 * which is the on-disk file name bytes on Unix, and UTF-8 on
205 	 * Windows
206 	 * hostname = A UTF-8 encoded hostname, or NULL for none. [allow-none]
207 	 * Returns: a newly-allocated string holding the resulting URI, or NULL on an error.
208 	 * Throws: GException on failure.
209 	 */
210 	public static string gFilenameToUri(string filename, string hostname)
211 	{
212 		// gchar * g_filename_to_uri (const gchar *filename,  const gchar *hostname,  GError **error);
213 		GError* err = null;
214 		
215 		auto p = g_filename_to_uri(Str.toStringz(filename), Str.toStringz(hostname), &err);
216 		
217 		if (err !is null)
218 		{
219 			throw new GException( new ErrorG(err) );
220 		}
221 		
222 		return Str.toString(p);
223 	}
224 }