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.URI; 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 public struct URI 36 { 37 38 /** 39 * Converts an escaped ASCII-encoded URI to a local filename in the 40 * encoding used for filenames. 41 * 42 * Params: 43 * uri = a uri describing a filename (escaped, encoded in ASCII). 44 * hostname = Location to store hostname for the URI. 45 * If there is no hostname in the URI, %NULL will be 46 * stored in this location. 47 * 48 * Returns: a newly-allocated string holding 49 * the resulting filename, or %NULL on an error. 50 * 51 * Throws: GException on failure. 52 */ 53 public static string filenameFromUri(string uri, out string hostname) 54 { 55 char* outhostname = null; 56 GError* err = null; 57 58 auto retStr = g_filename_from_uri(Str.toStringz(uri), &outhostname, &err); 59 60 if (err !is null) 61 { 62 throw new GException( new ErrorG(err) ); 63 } 64 65 hostname = Str.toString(outhostname); 66 67 scope(exit) Str.freeString(retStr); 68 return Str.toString(retStr); 69 } 70 71 /** 72 * Converts an absolute filename to an escaped ASCII-encoded URI, with the path 73 * component following Section 3.3. of RFC 2396. 74 * 75 * Params: 76 * filename = an absolute filename specified in the GLib file 77 * name encoding, which is the on-disk file name bytes on Unix, and UTF-8 78 * on Windows 79 * hostname = A UTF-8 encoded hostname, or %NULL for none. 80 * 81 * Returns: a newly-allocated string holding the resulting 82 * URI, or %NULL on an error. 83 * 84 * Throws: GException on failure. 85 */ 86 public static string filenameToUri(string filename, string hostname) 87 { 88 GError* err = null; 89 90 auto retStr = g_filename_to_uri(Str.toStringz(filename), Str.toStringz(hostname), &err); 91 92 if (err !is null) 93 { 94 throw new GException( new ErrorG(err) ); 95 } 96 97 scope(exit) Str.freeString(retStr); 98 return Str.toString(retStr); 99 } 100 }