Character Set Conversion

Name

Character Set Conversion -- 

Synopsis


#include <glib.h>


gchar*      g_convert                       (const gchar *str,
                                             gint len,
                                             const gchar *to_codeset,
                                             const gchar *from_codeset,
                                             gint *bytes_read,
                                             gint *bytes_written,
                                             GError **error);
gchar*      g_convert_with_fallback         (const gchar *str,
                                             gint len,
                                             const gchar *to_codeset,
                                             const gchar *from_codeset,
                                             gchar *fallback,
                                             gint *bytes_read,
                                             gint *bytes_written,
                                             GError **error);
#define     G_CONVERT_ERROR
GIConv      g_iconv_open                    (const gchar *to_codeset,
                                             const gchar *from_codeset);
size_t      g_iconv                         (GIConv converter,
                                             gchar **inbuf,
                                             size_t *inbytes_left,
                                             gchar **outbuf,
                                             size_t *outbytes_left);
gint        g_iconv_close                   (GIConv converter);
gchar*      g_locale_to_utf8                (const gchar *opsysstring,
                                             GError **error);
gchar*      g_filename_to_utf8              (const gchar *opsysstring,
                                             GError **error);
gchar*      g_filename_from_utf8            (const gchar *utf8string,
                                             GError **error);
gchar*      g_locale_from_utf8              (const gchar *utf8string,
                                             GError **error);
enum        GConvertError;

Description

Details

g_convert ()

gchar*      g_convert                       (const gchar *str,
                                             gint len,
                                             const gchar *to_codeset,
                                             const gchar *from_codeset,
                                             gint *bytes_read,
                                             gint *bytes_written,
                                             GError **error);

Convert a string from one character set to another.

str : the string to convert
len : the length of the string
to_codeset : name of character set into which to convert str
from_codeset : character set of str.
bytes_read : location to store the number of bytes in the input string that were successfully converted, or NULL. Even if the conversion was succesful, this may be less than len if there were partial characters at the end of the input. If the error G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value stored will the byte fofset after the last valid input sequence.
bytes_written : the stored in the output buffer (not including the terminating nul.
error : location to store the error occuring, or NULL to ignore errors. Any of the errors in GConvertError may occur.
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.


g_convert_with_fallback ()

gchar*      g_convert_with_fallback         (const gchar *str,
                                             gint len,
                                             const gchar *to_codeset,
                                             const gchar *from_codeset,
                                             gchar *fallback,
                                             gint *bytes_read,
                                             gint *bytes_written,
                                             GError **error);

Convert a string from one character set to another, possibly including fallback sequences for characters not representable in the output. Note that it is not guaranteed that the specification for the fallback sequences in fallback will be honored. Some systems may do a approximate conversion from from_codeset to to_codeset in their iconv() functions, in which case GLib will simply return that approximate conversion.

str : the string to convert
len : the length of the string
to_codeset : name of character set into which to convert str
from_codeset : character set of str.
fallback : UTF-8 string to use in place of character not present in the target encoding. (This must be in the target encoding), if NULL, characters not in the target encoding will be represented as Unicode escapes \x{XXXX} or \x{XXXXXX}.
bytes_read : location to store the number of bytes in the input string that were successfully converted, or NULL. Even if the conversion was succesful, this may be less than len if there were partial characters at the end of the input. If the error G_CONVERT_ERROR_ILLEGAL_SEQUENCE occurs, the value stored will the byte fofset after the last valid input sequence.
bytes_written : the stored in the output buffer (not including the terminating nul.
error : location to store the error occuring, or NULL to ignore errors. Any of the errors in GConvertError may occur.
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.


G_CONVERT_ERROR

#define G_CONVERT_ERROR g_convert_error_quark()


g_iconv_open ()

GIConv      g_iconv_open                    (const gchar *to_codeset,
                                             const gchar *from_codeset);

to_codeset : 
from_codeset : 
Returns : 


g_iconv ()

size_t      g_iconv                         (GIConv converter,
                                             gchar **inbuf,
                                             size_t *inbytes_left,
                                             gchar **outbuf,
                                             size_t *outbytes_left);

converter : 
inbuf : 
inbytes_left : 
outbuf : 
outbytes_left : 
Returns : 


g_iconv_close ()

gint        g_iconv_close                   (GIConv converter);

converter : 
Returns : 


g_locale_to_utf8 ()

gchar*      g_locale_to_utf8                (const gchar *opsysstring,
                                             GError **error);

opsysstring : 
error : 
Returns : 


g_filename_to_utf8 ()

gchar*      g_filename_to_utf8              (const gchar *opsysstring,
                                             GError **error);

opsysstring : 
error : 
Returns : 


g_filename_from_utf8 ()

gchar*      g_filename_from_utf8            (const gchar *utf8string,
                                             GError **error);

utf8string : 
error : 
Returns : 


g_locale_from_utf8 ()

gchar*      g_locale_from_utf8              (const gchar *utf8string,
                                             GError **error);

utf8string : 
error : 
Returns : 


enum GConvertError

typedef enum 
{
  G_CONVERT_ERROR_NO_CONVERSION,
  G_CONVERT_ERROR_ILLEGAL_SEQUENCE,
  G_CONVERT_ERROR_FAILED,
  G_CONVERT_ERROR_PARTIAL_INPUT
} GConvertError;