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  * Conversion parameters:
26  * inFile  = glib-Character-Set-Conversion.html
27  * outPack = glib
28  * outFile = CharacterSet
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = CharacterSet
33  * interf  = 
34  * class Code: Yes
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * 	- g_iconv
45  * omit signals:
46  * imports:
47  * 	- glib.Str
48  * 	- glib.ErrorG
49  * 	- glib.GException
50  * structWrap:
51  * module aliases:
52  * local aliases:
53  * overrides:
54  */
55 
56 module glib.CharacterSet;
57 
58 public  import gtkc.glibtypes;
59 
60 private import gtkc.glib;
61 private import glib.ConstructionException;
62 
63 private import glib.Str;
64 private import glib.ErrorG;
65 private import glib.GException;
66 
67 
68 
69 /**
70  * The g_convert() family of function wraps the functionality of iconv(). In
71  * addition to pure character set conversions, GLib has functions to deal
72  * with the extra complications of encodings for file names.
73  *
74  * File Name Encodings
75  *
76  * Historically, Unix has not had a defined encoding for file
77  * names: a file name is valid as long as it does not have path
78  * separators in it ("/"). However, displaying file names may
79  * require conversion: from the character set in which they were
80  * created, to the character set in which the application
81  * operates. Consider the Spanish file name
82  * "Presentación.sxi". If the
83  * application which created it uses ISO-8859-1 for its encoding,
84  *
85  * Character: P r e s e n t a c i ó n . s x i
86  * Hex code: 50 72 65 73 65 6e 74 61 63 69 f3 6e 2e 73 78 69
87  *
88  * However, if the application use UTF-8, the actual file name on
89  * disk would look like this:
90  *
91  * Character: P r e s e n t a c i ó n . s x i
92  * Hex code: 50 72 65 73 65 6e 74 61 63 69 c3 b3 6e 2e 73 78 69
93  *
94  * Glib uses UTF-8 for its strings, and GUI toolkits like GTK+
95  * that use Glib do the same thing. If you get a file name from
96  * the file system, for example, from readdir(3) or from g_dir_read_name(),
97  * and you wish to display the file name to the user, you
98  * will need to convert it into UTF-8. The
99  * opposite case is when the user types the name of a file he
100  * wishes to save: the toolkit will give you that string in
101  * UTF-8 encoding, and you will need to convert it to the
102  * character set used for file names before you can create the
103  * file with open(2) or fopen(3).
104  *
105  * By default, Glib assumes that file names on disk are in UTF-8
106  * encoding. This is a valid assumption for file systems which
107  * were created relatively recently: most applications use UTF-8
108  * encoding for their strings, and that is also what they use for
109  * the file names they create. However, older file systems may
110  * still contain file names created in "older" encodings, such as
111  * ISO-8859-1. In this case, for compatibility reasons, you may
112  * want to instruct Glib to use that particular encoding for file
113  * names rather than UTF-8. You can do this by specifying the
114  * encoding for file names in the G_FILENAME_ENCODING
115  * environment variable. For example, if your installation uses
116  * ISO-8859-1 for file names, you can put this in your
117  * ~/.profile:
118  *
119  * export G_FILENAME_ENCODING=ISO-8859-1
120  *
121  * Glib provides the functions g_filename_to_utf8() and
122  * g_filename_from_utf8() to perform the necessary conversions. These
123  * functions convert file names from the encoding specified in
124  * G_FILENAME_ENCODING to UTF-8 and vice-versa.
125  *  Figure 2, “Conversion between File Name Encodings” illustrates how
126  * these functions are used to convert between UTF-8 and the
127  * encoding for file names in the file system.
128  *
129  * Figure 2. Conversion between File Name Encodings
130  *
131  * Checklist for Application Writers
132  *
133  * This section is a practical summary of the detailed
134  * description above. You can use this as a checklist of
135  * things to do to make sure your applications process file
136  * name encodings correctly.
137  *
138  * If you get a file name from the file system from a function
139  * such as readdir(3) or gtk_file_chooser_get_filename(),
140  * you do not need to do any conversion to pass that
141  * file name to functions like open(2), rename(2), or
142  * fopen(3) — those are "raw" file names which the file
143  * system understands.
144  *
145  * If you need to display a file name, convert it to UTF-8 first by
146  * using g_filename_to_utf8(). If conversion fails, display a string like
147  * "Unknown file name". Do not
148  * convert this string back into the encoding used for file names if you
149  * wish to pass it to the file system; use the original file name instead.
150  * For example, the document window of a word processor could display
151  * "Unknown file name" in its title bar but still let the user save the
152  * file, as it would keep the raw file name internally. This can happen
153  * if the user has not set the G_FILENAME_ENCODING
154  * environment variable even though he has files whose names are not
155  * encoded in UTF-8.
156  *
157  * If your user interface lets the user type a file name for saving or
158  * renaming, convert it to the encoding used for file names in the file
159  * system by using g_filename_from_utf8(). Pass the converted file name
160  * to functions like fopen(3). If conversion fails, ask the user to enter
161  * a different file name. This can happen if the user types Japanese
162  * characters when G_FILENAME_ENCODING is set to
163  * ISO-8859-1, for example.
164  */
165 public class CharacterSet
166 {
167 	
168 	/**
169 	 * Same as the standard UNIX routine iconv(), but
170 	 * may be implemented via libiconv on UNIX flavors that lack
171 	 * a native implementation.
172 	 * GLib provides g_convert() and g_locale_to_utf8() which are likely
173 	 * more convenient than the raw iconv wrappers.
174 	 * Params:
175 	 * converter = conversion descriptor from g_iconv_open()
176 	 * inbuf = bytes to convert
177 	 * outbuf = converted output bytes
178 	 * Returns: count of non-reversible conversions, or -1 on error
179 	 */
180 	public static gsize iconv(GIConv converter, ref char[] inbuf, ref char[] outbuf)
181 	{
182 		// gsize g_iconv (GIConv converter,  gchar **inbuf,  gsize *inbytes_left,  gchar **outbuf,  gsize *outbytes_left);
183 		gchar* outinbuf = inbuf.ptr;
184 		size_t inbytesLeft = inbuf.length;
185 		gchar* outoutbuf = outbuf.ptr;
186 		size_t outbytesLeft = outbuf.length;
187 		
188 		auto p = g_iconv(converter, &outinbuf, &inbytesLeft, &outoutbuf, &outbytesLeft);
189 		
190 		inbuf = outinbuf[0 .. inbytesLeft];
191 		outbuf = outoutbuf[0 .. outbytesLeft];
192 		return p;
193 	}
194 	
195 	/**
196 	 */
197 	
198 	/**
199 	 * Converts a string from one character set to another.
200 	 * Note that you should use g_iconv() for streaming
201 	 * conversions[3].
202 	 * Params:
203 	 * str = the string to convert
204 	 * len = the length of the string, or -1 if the string is
205 	 * nul-terminated[2].
206 	 * toCodeset = name of character set into which to convert str
207 	 * fromCodeset = character set of str.
208 	 * bytesRead = location to store the number of bytes in the
209 	 * input string that were successfully converted, or NULL.
210 	 * Even if the conversion was successful, this may be
211 	 * less than len if there were partial characters
212 	 * at the end of the input. If the error
213 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
214 	 * stored will the byte offset after the last valid
215 	 * input sequence. [out]
216 	 * bytesWritten = the number of bytes stored in the output buffer (not
217 	 * including the terminating nul). [out]
218 	 * Returns: If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL and error will be set.
219 	 * Throws: GException on failure.
220 	 */
221 	public static string convert(string str, gssize len, string toCodeset, string fromCodeset, out gsize bytesRead, out gsize bytesWritten)
222 	{
223 		// gchar * g_convert (const gchar *str,  gssize len,  const gchar *to_codeset,  const gchar *from_codeset,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
224 		GError* err = null;
225 		
226 		auto p = g_convert(Str.toStringz(str), len, Str.toStringz(toCodeset), Str.toStringz(fromCodeset), &bytesRead, &bytesWritten, &err);
227 		
228 		if (err !is null)
229 		{
230 			throw new GException( new ErrorG(err) );
231 		}
232 		
233 		return Str.toString(p);
234 	}
235 	
236 	/**
237 	 * Converts a string from one character set to another, possibly
238 	 * including fallback sequences for characters not representable
239 	 * in the output. Note that it is not guaranteed that the specification
240 	 * for the fallback sequences in fallback will be honored. Some
241 	 * systems may do an approximate conversion from from_codeset
242 	 * to to_codeset in their iconv() functions,
243 	 * in which case GLib will simply return that approximate conversion.
244 	 * Note that you should use g_iconv() for streaming
245 	 * conversions[3].
246 	 * Params:
247 	 * str = the string to convert
248 	 * len = the length of the string, or -1 if the string is
249 	 * nul-terminated[2].
250 	 * toCodeset = name of character set into which to convert str
251 	 * fromCodeset = character set of str.
252 	 * fallback = UTF-8 string to use in place of character not
253 	 * present in the target encoding. (The string must be
254 	 * representable in the target encoding).
255 	 * If NULL, characters not in the target encoding will
256 	 * be represented as Unicode escapes \uxxxx or \Uxxxxyyyy.
257 	 * bytesRead = location to store the number of bytes in the
258 	 * input string that were successfully converted, or NULL.
259 	 * Even if the conversion was successful, this may be
260 	 * less than len if there were partial characters
261 	 * at the end of the input.
262 	 * bytesWritten = the number of bytes stored in the output buffer (not
263 	 * including the terminating nul).
264 	 * Returns: If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL and error will be set.
265 	 * Throws: GException on failure.
266 	 */
267 	public static string convertWithFallback(string str, gssize len, string toCodeset, string fromCodeset, string fallback, out gsize bytesRead, out gsize bytesWritten)
268 	{
269 		// gchar * g_convert_with_fallback (const gchar *str,  gssize len,  const gchar *to_codeset,  const gchar *from_codeset,  const gchar *fallback,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
270 		GError* err = null;
271 		
272 		auto p = g_convert_with_fallback(Str.toStringz(str), len, Str.toStringz(toCodeset), Str.toStringz(fromCodeset), Str.toStringz(fallback), &bytesRead, &bytesWritten, &err);
273 		
274 		if (err !is null)
275 		{
276 			throw new GException( new ErrorG(err) );
277 		}
278 		
279 		return Str.toString(p);
280 	}
281 	
282 	/**
283 	 * Converts a string from one character set to another.
284 	 * Note that you should use g_iconv() for streaming
285 	 * conversions[3].
286 	 * Params:
287 	 * str = the string to convert
288 	 * converter = conversion descriptor from g_iconv_open()
289 	 * bytesRead = location to store the number of bytes in the
290 	 * input string that were successfully converted, or NULL.
291 	 * Even if the conversion was successful, this may be
292 	 * less than len if there were partial characters
293 	 * at the end of the input. If the error
294 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
295 	 * stored will the byte offset after the last valid
296 	 * input sequence.
297 	 * Returns: If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL and error will be set.
298 	 * Throws: GException on failure.
299 	 */
300 	public static string convertWithIconv(string str, GIConv converter, out gsize bytesRead)
301 	{
302 		// gchar * g_convert_with_iconv (const gchar *str,  gssize len,  GIConv converter,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
303 		gsize bytesWritten;
304 		GError* err = null;
305 		
306 		auto p = g_convert_with_iconv(cast(char*)str.ptr, cast(int) str.length, converter, &bytesRead, &bytesWritten, &err);
307 		
308 		if (err !is null)
309 		{
310 			throw new GException( new ErrorG(err) );
311 		}
312 		
313 		return Str.toString(p, bytesWritten);
314 	}
315 	
316 	/**
317 	 * Same as the standard UNIX routine iconv_open(), but
318 	 * may be implemented via libiconv on UNIX flavors that lack
319 	 * a native implementation.
320 	 * GLib provides g_convert() and g_locale_to_utf8() which are likely
321 	 * more convenient than the raw iconv wrappers.
322 	 * Params:
323 	 * toCodeset = destination codeset
324 	 * fromCodeset = source codeset
325 	 * Returns: a "conversion descriptor", or (GIConv)-1 if opening the converter failed.
326 	 */
327 	public static GIConv iconvOpen(string toCodeset, string fromCodeset)
328 	{
329 		// GIConv g_iconv_open (const gchar *to_codeset,  const gchar *from_codeset);
330 		return g_iconv_open(Str.toStringz(toCodeset), Str.toStringz(fromCodeset));
331 	}
332 	
333 	/**
334 	 * Same as the standard UNIX routine iconv_close(), but
335 	 * may be implemented via libiconv on UNIX flavors that lack
336 	 * a native implementation. Should be called to clean up
337 	 * the conversion descriptor from g_iconv_open() when
338 	 * you are done converting things.
339 	 * GLib provides g_convert() and g_locale_to_utf8() which are likely
340 	 * more convenient than the raw iconv wrappers.
341 	 * Params:
342 	 * converter = a conversion descriptor from g_iconv_open()
343 	 * Returns: -1 on error, 0 on success
344 	 */
345 	public static int iconvClose(GIConv converter)
346 	{
347 		// gint g_iconv_close (GIConv converter);
348 		return g_iconv_close(converter);
349 	}
350 	
351 	/**
352 	 * Converts a string which is in the encoding used for strings by
353 	 * the C runtime (usually the same as that used by the operating
354 	 * system) in the current locale into a
355 	 * UTF-8 string.
356 	 * Params:
357 	 * opsysstring = a string in the encoding of the current locale. On Windows
358 	 * this means the system codepage.
359 	 * len = the length of the string, or -1 if the string is
360 	 * nul-terminated[2].
361 	 * bytesRead = location to store the number of bytes in the
362 	 * input string that were successfully converted, or NULL.
363 	 * Even if the conversion was successful, this may be
364 	 * less than len if there were partial characters
365 	 * at the end of the input. If the error
366 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
367 	 * stored will the byte offset after the last valid
368 	 * input sequence.
369 	 * bytesWritten = the number of bytes stored in the output buffer (not
370 	 * including the terminating nul).
371 	 * Returns: The converted string, or NULL on an error.
372 	 * Throws: GException on failure.
373 	 */
374 	public static string localeToUtf8(string opsysstring, gssize len, out gsize bytesRead, out gsize bytesWritten)
375 	{
376 		// gchar * g_locale_to_utf8 (const gchar *opsysstring,  gssize len,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
377 		GError* err = null;
378 		
379 		auto p = g_locale_to_utf8(Str.toStringz(opsysstring), len, &bytesRead, &bytesWritten, &err);
380 		
381 		if (err !is null)
382 		{
383 			throw new GException( new ErrorG(err) );
384 		}
385 		
386 		return Str.toString(p);
387 	}
388 	
389 	/**
390 	 * Converts a string which is in the encoding used by GLib for
391 	 * filenames into a UTF-8 string. Note that on Windows GLib uses UTF-8
392 	 * for filenames; on other platforms, this function indirectly depends on
393 	 * the current locale.
394 	 * Params:
395 	 * opsysstring = a string in the encoding for filenames
396 	 * len = the length of the string, or -1 if the string is
397 	 * nul-terminated[2].
398 	 * bytesRead = location to store the number of bytes in the
399 	 * input string that were successfully converted, or NULL.
400 	 * Even if the conversion was successful, this may be
401 	 * less than len if there were partial characters
402 	 * at the end of the input. If the error
403 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
404 	 * stored will the byte offset after the last valid
405 	 * input sequence.
406 	 * bytesWritten = the number of bytes stored in the output buffer (not
407 	 * including the terminating nul).
408 	 * Returns: The converted string, or NULL on an error.
409 	 * Throws: GException on failure.
410 	 */
411 	public static string filenameToUtf8(string opsysstring, out gsize bytesRead, out gsize bytesWritten)
412 	{
413 		// gchar * g_filename_to_utf8 (const gchar *opsysstring,  gssize len,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
414 		GError* err = null;
415 		
416 		auto p = g_filename_to_utf8(cast(char*)opsysstring.ptr, cast(int) opsysstring.length, &bytesRead, &bytesWritten, &err);
417 		
418 		if (err !is null)
419 		{
420 			throw new GException( new ErrorG(err) );
421 		}
422 		
423 		return Str.toString(p);
424 	}
425 	
426 	/**
427 	 * Converts a string from UTF-8 to the encoding GLib uses for
428 	 * filenames. Note that on Windows GLib uses UTF-8 for filenames;
429 	 * on other platforms, this function indirectly depends on the
430 	 * current locale.
431 	 * Params:
432 	 * utf8string = a UTF-8 encoded string.
433 	 * len = the length of the string, or -1 if the string is
434 	 * nul-terminated.
435 	 * bytesRead = location to store the number of bytes in
436 	 * the input string that were successfully converted, or NULL.
437 	 * Even if the conversion was successful, this may be
438 	 * less than len if there were partial characters
439 	 * at the end of the input. If the error
440 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
441 	 * stored will the byte offset after the last valid
442 	 * input sequence. [out][allow-none]
443 	 * bytesWritten = the number of bytes stored in the output buffer (not
444 	 * including the terminating nul). [out]
445 	 * Returns: The converted string, or NULL on an error. [array length=bytes_written][element-type guint8][transfer full]
446 	 * Throws: GException on failure.
447 	 */
448 	public static string filenameFromUtf8(string utf8string, out gsize bytesRead, out gsize bytesWritten)
449 	{
450 		// gchar * g_filename_from_utf8 (const gchar *utf8string,  gssize len,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
451 		GError* err = null;
452 		
453 		auto p = g_filename_from_utf8(cast(char*)utf8string.ptr, cast(int) utf8string.length, &bytesRead, &bytesWritten, &err);
454 		
455 		if (err !is null)
456 		{
457 			throw new GException( new ErrorG(err) );
458 		}
459 		
460 		return Str.toString(p);
461 	}
462 	
463 	/**
464 	 * Determines the preferred character sets used for filenames.
465 	 * The first character set from the charsets is the filename encoding, the
466 	 * subsequent character sets are used when trying to generate a displayable
467 	 * representation of a filename, see g_filename_display_name().
468 	 * On Unix, the character sets are determined by consulting the
469 	 * environment variables G_FILENAME_ENCODING and
470 	 * G_BROKEN_FILENAMES. On Windows, the character set
471 	 * used in the GLib API is always UTF-8 and said environment variables
472 	 * have no effect.
473 	 * G_FILENAME_ENCODING may be set to a comma-separated list
474 	 * of character set names. The special token "@locale" is taken to
475 	 * mean the character set for the current
476 	 * locale. If G_FILENAME_ENCODING is not set, but
477 	 * G_BROKEN_FILENAMES is, the character set of the current
478 	 * locale is taken as the filename encoding. If neither environment variable
479 	 * is set, UTF-8 is taken as the filename encoding, but the character
480 	 * set of the current locale is also put in the list of encodings.
481 	 * The returned charsets belong to GLib and must not be freed.
482 	 * Note that on Unix, regardless of the locale character set or
483 	 * G_FILENAME_ENCODING value, the actual file names present
484 	 * on a system might be in any random encoding or just gibberish.
485 	 * Since 2.6
486 	 * Params:
487 	 * charsets = return location for the NULL-terminated list of encoding names
488 	 * Returns: TRUE if the filename encoding is UTF-8.
489 	 */
490 	public static int getFilenameCharsets(out string[] charsets)
491 	{
492 		// gboolean g_get_filename_charsets (const gchar ***charsets);
493 		char** outcharsets = null;
494 		
495 		auto p = g_get_filename_charsets(&outcharsets);
496 		
497 		charsets = Str.toStringArray(outcharsets);
498 		return p;
499 	}
500 	
501 	/**
502 	 * Converts a filename into a valid UTF-8 string. The conversion is
503 	 * not necessarily reversible, so you should keep the original around
504 	 * and use the return value of this function only for display purposes.
505 	 * Unlike g_filename_to_utf8(), the result is guaranteed to be non-NULL
506 	 * even if the filename actually isn't in the GLib file name encoding.
507 	 * If GLib cannot make sense of the encoding of filename, as a last resort it
508 	 * replaces unknown characters with U+FFFD, the Unicode replacement character.
509 	 * You can search the result for the UTF-8 encoding of this character (which is
510 	 * "\357\277\275" in octal notation) to find out if filename was in an invalid
511 	 * encoding.
512 	 * If you know the whole pathname of the file you should use
513 	 * g_filename_display_basename(), since that allows location-based
514 	 * translation of filenames.
515 	 * Since 2.6
516 	 * Params:
517 	 * filename = a pathname hopefully in the GLib file name encoding
518 	 * Returns: a newly allocated string containing a rendition of the filename in valid UTF-8
519 	 */
520 	public static string filenameDisplayName(string filename)
521 	{
522 		// gchar * g_filename_display_name (const gchar *filename);
523 		return Str.toString(g_filename_display_name(Str.toStringz(filename)));
524 	}
525 	
526 	/**
527 	 * Returns the display basename for the particular filename, guaranteed
528 	 * to be valid UTF-8. The display name might not be identical to the filename,
529 	 * for instance there might be problems converting it to UTF-8, and some files
530 	 * can be translated in the display.
531 	 * If GLib cannot make sense of the encoding of filename, as a last resort it
532 	 * replaces unknown characters with U+FFFD, the Unicode replacement character.
533 	 * You can search the result for the UTF-8 encoding of this character (which is
534 	 * "\357\277\275" in octal notation) to find out if filename was in an invalid
535 	 * encoding.
536 	 * You must pass the whole absolute pathname to this functions so that
537 	 * translation of well known locations can be done.
538 	 * This function is preferred over g_filename_display_name() if you know the
539 	 * whole path, as it allows translation.
540 	 * Since 2.6
541 	 * Params:
542 	 * filename = an absolute pathname in the GLib file name encoding
543 	 * Returns: a newly allocated string containing a rendition of the basename of the filename in valid UTF-8
544 	 */
545 	public static string filenameDisplayBasename(string filename)
546 	{
547 		// gchar * g_filename_display_basename (const gchar *filename);
548 		return Str.toString(g_filename_display_basename(Str.toStringz(filename)));
549 	}
550 	
551 	/**
552 	 * Converts a string from UTF-8 to the encoding used for strings by
553 	 * the C runtime (usually the same as that used by the operating
554 	 * system) in the current locale. On
555 	 * Windows this means the system codepage.
556 	 * Params:
557 	 * utf8string = a UTF-8 encoded string
558 	 * len = the length of the string, or -1 if the string is
559 	 * nul-terminated[2].
560 	 * bytesRead = location to store the number of bytes in the
561 	 * input string that were successfully converted, or NULL.
562 	 * Even if the conversion was successful, this may be
563 	 * less than len if there were partial characters
564 	 * at the end of the input. If the error
565 	 * G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value
566 	 * stored will the byte offset after the last valid
567 	 * input sequence.
568 	 * bytesWritten = the number of bytes stored in the output buffer (not
569 	 * including the terminating nul).
570 	 * Returns: The converted string, or NULL on an error.
571 	 * Throws: GException on failure.
572 	 */
573 	public static string localeFromUtf8(string utf8string, gssize len, out gsize bytesRead, out gsize bytesWritten)
574 	{
575 		// gchar * g_locale_from_utf8 (const gchar *utf8string,  gssize len,  gsize *bytes_read,  gsize *bytes_written,  GError **error);
576 		GError* err = null;
577 		
578 		auto p = g_locale_from_utf8(Str.toStringz(utf8string), len, &bytesRead, &bytesWritten, &err);
579 		
580 		if (err !is null)
581 		{
582 			throw new GException( new ErrorG(err) );
583 		}
584 		
585 		return Str.toString(p);
586 	}
587 	
588 	/**
589 	 * Obtains the character set for the current
590 	 * locale; you might use this character set as an argument to
591 	 * g_convert(), to convert from the current locale's encoding to some
592 	 * other encoding. (Frequently g_locale_to_utf8() and g_locale_from_utf8()
593 	 * are nice shortcuts, though.)
594 	 * On Windows the character set returned by this function is the
595 	 * so-called system default ANSI code-page. That is the character set
596 	 * used by the "narrow" versions of C library and Win32 functions that
597 	 * handle file names. It might be different from the character set
598 	 * used by the C library's current locale.
599 	 * The return value is TRUE if the locale's encoding is UTF-8, in that
600 	 * case you can perhaps avoid calling g_convert().
601 	 * The string returned in charset is not allocated, and should not be
602 	 * freed.
603 	 * Params:
604 	 * charset = return location for character set name
605 	 * Returns: TRUE if the returned charset is UTF-8
606 	 */
607 	public static int getCharset(out string charset)
608 	{
609 		// gboolean g_get_charset (const char **charset);
610 		char* outcharset = null;
611 		
612 		auto p = g_get_charset(&outcharset);
613 		
614 		charset = Str.toString(outcharset);
615 		return p;
616 	}
617 	
618 	/**
619 	 * Gets the character set for the current locale.
620 	 * Returns: a newly allocated string containing the name of the character set. This string must be freed with g_free(). [2] Note that some encodings may allow nul bytes to occur inside strings. In that case, using -1 for the len parameter is unsafe. [3] Despite the fact that byes_read can return information about partial characters, the g_convert_... functions are not generally suitable for streaming. If the underlying converter being used maintains internal state, then this won't be preserved across successive calls to g_convert(), g_convert_with_iconv() or g_convert_with_fallback(). (An example of this is the GNU C converter for CP1255 which does not emit a base character until it knows that the next character is not a mark that could combine with the base character.)
621 	 */
622 	public static string getCodeset()
623 	{
624 		// gchar * g_get_codeset (void);
625 		return Str.toString(g_get_codeset());
626 	}
627 }