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.IConv; 26 27 private import glib.Str; 28 private import glib.c.functions; 29 public import glib.c.types; 30 public import gtkc.glibtypes; 31 32 33 /** 34 * The GIConv struct wraps an iconv() conversion descriptor. It contains 35 * private data and should only be accessed using the following functions. 36 */ 37 38 /** 39 * Same as the standard UNIX routine iconv(), but 40 * may be implemented via libiconv on UNIX flavors that lack 41 * a native implementation. 42 * 43 * GLib provides g_convert() and g_locale_to_utf8() which are likely 44 * more convenient than the raw iconv wrappers. 45 * 46 * Params: 47 * inbuf = bytes to convert 48 * outbuf = converted output bytes 49 * 50 * Returns: count of non-reversible conversions, or -1 on error 51 */ 52 public size_t iconv(GIConv converter, ref string inbuf, ref string outbuf) 53 { 54 char* outinbuf = Str.toStringz(inbuf); 55 size_t inbytesLeft; 56 char* outoutbuf = Str.toStringz(outbuf); 57 size_t outbytesLeft; 58 59 auto p = g_iconv(converter, &outinbuf, &inbytesLeft, &outoutbuf, &outbytesLeft); 60 61 inbuf = Str.toString(outinbuf, inbytesLeft); 62 outbuf = Str.toString(outoutbuf, outbytesLeft); 63 64 return p; 65 } 66 67 /** 68 * Same as the standard UNIX routine iconv_close(), but 69 * may be implemented via libiconv on UNIX flavors that lack 70 * a native implementation. Should be called to clean up 71 * the conversion descriptor from g_iconv_open() when 72 * you are done converting things. 73 * 74 * GLib provides g_convert() and g_locale_to_utf8() which are likely 75 * more convenient than the raw iconv wrappers. 76 * 77 * Returns: -1 on error, 0 on success 78 */ 79 public int close(GIConv converter) 80 { 81 return g_iconv_close(converter); 82 } 83 84 /** 85 * Same as the standard UNIX routine iconv_open(), but 86 * may be implemented via libiconv on UNIX flavors that lack 87 * a native implementation. 88 * 89 * GLib provides g_convert() and g_locale_to_utf8() which are likely 90 * more convenient than the raw iconv wrappers. 91 * 92 * Params: 93 * toCodeset = destination codeset 94 * fromCodeset = source codeset 95 * 96 * Returns: a "conversion descriptor", or (GIConv)-1 if 97 * opening the converter failed. 98 */ 99 public GIConv open(string toCodeset, string fromCodeset) 100 { 101 return g_iconv_open(Str.toStringz(toCodeset), Str.toStringz(fromCodeset)); 102 }