source: appstream-generator/build/girepo/glib/URI.d @ 4841

Last change on this file since 4841 was 4841, checked in by Juanma, 2 years ago

Initial release

File size: 7.1 KB
Line 
1/*
2 * Licensed under the GNU Lesser General Public License Version 3
3 *
4 * This library is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the license, or
7 * (at your option) any later version.
8 *
9 * This software is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 * GNU Lesser General Public License for more details.
13 *
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this library.  If not, see <http://www.gnu.org/licenses/>.
16 */
17
18// generated automatically - do not change
19
20
21module glib.URI;
22
23private import gi.glib;
24public  import gi.glibtypes;
25private import glib.ErrorG;
26private import glib.GException;
27private import glib.Str;
28
29
30/** */
31public struct URI
32{
33
34        /**
35         * Converts an escaped ASCII-encoded URI to a local filename in the
36         * encoding used for filenames.
37         *
38         * Params:
39         *     uri = a uri describing a filename (escaped, encoded in ASCII).
40         *     hostname = Location to store hostname for the URI, or %NULL.
41         *         If there is no hostname in the URI, %NULL will be
42         *         stored in this location.
43         *
44         * Returns: a newly-allocated string holding
45         *     the resulting filename, or %NULL on an error.
46         *
47         * Throws: GException on failure.
48         */
49        public static string filenameFromUri(string uri, out string hostname)
50        {
51                char* outhostname = null;
52                GError* err = null;
53               
54                auto retStr = g_filename_from_uri(Str.toStringz(uri), &outhostname, &err);
55               
56                if (err !is null)
57                {
58                        throw new GException( new ErrorG(err) );
59                }
60               
61                hostname = Str.toString(outhostname);
62               
63                scope(exit) Str.freeString(retStr);
64                return Str.toString(retStr);
65        }
66
67        /**
68         * Converts an absolute filename to an escaped ASCII-encoded URI, with the path
69         * component following Section 3.3. of RFC 2396.
70         *
71         * Params:
72         *     filename = an absolute filename specified in the GLib file name encoding,
73         *         which is the on-disk file name bytes on Unix, and UTF-8 on
74         *         Windows
75         *     hostname = A UTF-8 encoded hostname, or %NULL for none.
76         *
77         * Returns: a newly-allocated string holding the resulting
78         *     URI, or %NULL on an error.
79         *
80         * Throws: GException on failure.
81         */
82        public static string filenameToUri(string filename, string hostname)
83        {
84                GError* err = null;
85               
86                auto retStr = g_filename_to_uri(Str.toStringz(filename), Str.toStringz(hostname), &err);
87               
88                if (err !is null)
89                {
90                        throw new GException( new ErrorG(err) );
91                }
92               
93                scope(exit) Str.freeString(retStr);
94                return Str.toString(retStr);
95        }
96
97        /**
98         * Escapes a string for use in a URI.
99         *
100         * Normally all characters that are not "unreserved" (i.e. ASCII alphanumerical
101         * characters plus dash, dot, underscore and tilde) are escaped.
102         * But if you specify characters in @reserved_chars_allowed they are not
103         * escaped. This is useful for the "reserved" characters in the URI
104         * specification, since those are allowed unescaped in some portions of
105         * a URI.
106         *
107         * Params:
108         *     unescaped = the unescaped input string.
109         *     reservedCharsAllowed = a string of reserved characters that
110         *         are allowed to be used, or %NULL.
111         *     allowUtf8 = %TRUE if the result can include UTF-8 characters.
112         *
113         * Returns: an escaped version of @unescaped. The returned string should be
114         *     freed when no longer needed.
115         *
116         * Since: 2.16
117         */
118        public static string uriEscapeString(string unescaped, string reservedCharsAllowed, bool allowUtf8)
119        {
120                auto retStr = g_uri_escape_string(Str.toStringz(unescaped), Str.toStringz(reservedCharsAllowed), allowUtf8);
121               
122                scope(exit) Str.freeString(retStr);
123                return Str.toString(retStr);
124        }
125
126        /**
127         * Splits an URI list conforming to the text/uri-list
128         * mime type defined in RFC 2483 into individual URIs,
129         * discarding any comments. The URIs are not validated.
130         *
131         * Params:
132         *     uriList = an URI list
133         *
134         * Returns: a newly allocated %NULL-terminated list
135         *     of strings holding the individual URIs. The array should be freed
136         *     with g_strfreev().
137         *
138         * Since: 2.6
139         */
140        public static string[] uriListExtractUris(string uriList)
141        {
142                auto retStr = g_uri_list_extract_uris(Str.toStringz(uriList));
143               
144                scope(exit) Str.freeStringArray(retStr);
145                return Str.toStringArray(retStr);
146        }
147
148        /**
149         * Gets the scheme portion of a URI string. RFC 3986 decodes the scheme as:
150         * |[
151         * URI = scheme ":" hier-part [ "?" query ] [ "#" fragment ]
152         * ]|
153         * Common schemes include "file", "http", "svn+ssh", etc.
154         *
155         * Params:
156         *     uri = a valid URI.
157         *
158         * Returns: The "Scheme" component of the URI, or %NULL on error.
159         *     The returned string should be freed when no longer needed.
160         *
161         * Since: 2.16
162         */
163        public static string uriParseScheme(string uri)
164        {
165                auto retStr = g_uri_parse_scheme(Str.toStringz(uri));
166               
167                scope(exit) Str.freeString(retStr);
168                return Str.toString(retStr);
169        }
170
171        /**
172         * Unescapes a segment of an escaped string.
173         *
174         * If any of the characters in @illegal_characters or the character zero appears
175         * as an escaped character in @escaped_string then that is an error and %NULL
176         * will be returned. This is useful it you want to avoid for instance having a
177         * slash being expanded in an escaped path element, which might confuse pathname
178         * handling.
179         *
180         * Params:
181         *     escapedString = A string, may be %NULL
182         *     escapedStringEnd = Pointer to end of @escaped_string, may be %NULL
183         *     illegalCharacters = An optional string of illegal characters not to be allowed, may be %NULL
184         *
185         * Returns: an unescaped version of @escaped_string or %NULL on error.
186         *     The returned string should be freed when no longer needed.  As a
187         *     special case if %NULL is given for @escaped_string, this function
188         *     will return %NULL.
189         *
190         * Since: 2.16
191         */
192        public static string uriUnescapeSegment(string escapedString, string escapedStringEnd, string illegalCharacters)
193        {
194                auto retStr = g_uri_unescape_segment(Str.toStringz(escapedString), Str.toStringz(escapedStringEnd), Str.toStringz(illegalCharacters));
195               
196                scope(exit) Str.freeString(retStr);
197                return Str.toString(retStr);
198        }
199
200        /**
201         * Unescapes a whole escaped string.
202         *
203         * If any of the characters in @illegal_characters or the character zero appears
204         * as an escaped character in @escaped_string then that is an error and %NULL
205         * will be returned. This is useful it you want to avoid for instance having a
206         * slash being expanded in an escaped path element, which might confuse pathname
207         * handling.
208         *
209         * Params:
210         *     escapedString = an escaped string to be unescaped.
211         *     illegalCharacters = a string of illegal characters not to be
212         *         allowed, or %NULL.
213         *
214         * Returns: an unescaped version of @escaped_string. The returned string
215         *     should be freed when no longer needed.
216         *
217         * Since: 2.16
218         */
219        public static string uriUnescapeString(string escapedString, string illegalCharacters)
220        {
221                auto retStr = g_uri_unescape_string(Str.toStringz(escapedString), Str.toStringz(illegalCharacters));
222               
223                scope(exit) Str.freeString(retStr);
224                return Str.toString(retStr);
225        }
226}
Note: See TracBrowser for help on using the repository browser.