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 * Note that the behaviour of iconv() for characters which are valid in the 47 * input character set, but which have no representation in the output character 48 * set, is implementation defined. This function may return success (with a 49 * positive number of non-reversible conversions as replacement characters were 50 * used), or it may return -1 and set an error such as %EILSEQ, in such a 51 * situation. 52 * 53 * Params: 54 * inbuf = bytes to convert 55 * outbuf = converted output bytes 56 * 57 * Returns: count of non-reversible conversions, or -1 on error 58 */ 59 public size_t iconv(GIConv converter, ref string inbuf, ref string outbuf) 60 { 61 char* outinbuf = Str.toStringz(inbuf); 62 size_t inbytesLeft; 63 char* outoutbuf = Str.toStringz(outbuf); 64 size_t outbytesLeft; 65 66 auto __p = g_iconv(converter, &outinbuf, &inbytesLeft, &outoutbuf, &outbytesLeft); 67 68 inbuf = Str.toString(outinbuf, inbytesLeft); 69 outbuf = Str.toString(outoutbuf, outbytesLeft); 70 71 return __p; 72 } 73 74 /** 75 * Same as the standard UNIX routine iconv_close(), but 76 * may be implemented via libiconv on UNIX flavors that lack 77 * a native implementation. Should be called to clean up 78 * the conversion descriptor from g_iconv_open() when 79 * you are done converting things. 80 * 81 * GLib provides g_convert() and g_locale_to_utf8() which are likely 82 * more convenient than the raw iconv wrappers. 83 * 84 * Returns: -1 on error, 0 on success 85 */ 86 public int close(GIConv converter) 87 { 88 return g_iconv_close(converter); 89 } 90 91 /** 92 * Same as the standard UNIX routine iconv_open(), but 93 * may be implemented via libiconv on UNIX flavors that lack 94 * a native implementation. 95 * 96 * GLib provides g_convert() and g_locale_to_utf8() which are likely 97 * more convenient than the raw iconv wrappers. 98 * 99 * Params: 100 * toCodeset = destination codeset 101 * fromCodeset = source codeset 102 * 103 * Returns: a "conversion descriptor", or (GIConv)-1 if 104 * opening the converter failed. 105 */ 106 public GIConv open(string toCodeset, string fromCodeset) 107 { 108 return g_iconv_open(Str.toStringz(toCodeset), Str.toStringz(fromCodeset)); 109 }