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