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