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