GflsEncodingConverter

GflsEncodingConverter — Character encoding converter

Functions

Types and Values

Object Hierarchy

    GObject
    ╰── GflsEncodingConverter

Includes

#include <gfls/gfls.h>

Description

A utility class to convert from one character encoding to another.

A GflsEncodingConverter object can be used only for one conversion. Call the functions in this order:

  • gfls_encoding_converter_new()

  • gfls_encoding_converter_set_allow_invalid_bytes()

  • gfls_encoding_converter_set_callback() to get the output.

  • gfls_encoding_converter_open()

  • gfls_encoding_converter_feed(), several times if streaming is desired.

  • gfls_encoding_converter_finish_feeding()

  • Finally gfls_encoding_converter_get_lossy_conversion() can be called to know more about how the conversion was performed.

Functions

GflsEncodingConverterCallback ()

void
(*GflsEncodingConverterCallback) (GBytes *bytes,
                                  gboolean is_valid,
                                  gpointer user_data);

This callback function is called when there is an output chunk from the GflsEncodingConverter.

bytes is always nul-terminated, but this is not included in the GBytes length.

If is_valid is TRUE, the chunk has been successfully converted.

If is_valid is FALSE, the bytes is a copy of the input bytes for which the conversion failed. Note especially that the bytes have not been escaped; for that, you can call a function like gfls_utils_bytes_to_hex_representation().

GflsEncodingConverter makes no attempts to coalesce contiguous chunks of the same kind. In other words, this callback can be called many times in a row with the same value for is_valid .

You need to either use bytes directly during the call of this callback, or increase the reference count to store bytes for later use. (When the call of the callback finishes, GflsEncodingConverter decreases the reference count of bytes ).

Parameters

bytes

the chunk data.

 

is_valid

whether bytes is a valid chunk.

 

user_data

user data.

 

Since: 0.5


gfls_encoding_converter_new ()

GflsEncodingConverter *
gfls_encoding_converter_new (void);

Returns

a new GflsEncodingConverter.

[transfer full]

Since: 0.5


gfls_encoding_converter_get_allow_invalid_bytes ()

gboolean
gfls_encoding_converter_get_allow_invalid_bytes
                               (GflsEncodingConverter *converter);

Parameters

converter

a GflsEncodingConverter.

 

Returns

whether invalid bytes are allowed during the conversion.

Since: 0.5


gfls_encoding_converter_set_allow_invalid_bytes ()

void
gfls_encoding_converter_set_allow_invalid_bytes
                               (GflsEncodingConverter *converter,
                                gboolean allow_invalid_bytes);

Sets whether to allow invalid bytes during the conversion.

Parameters

converter

a GflsEncodingConverter.

 

allow_invalid_bytes

whether to allow invalid bytes.

 

Since: 0.5


gfls_encoding_converter_set_callback ()

void
gfls_encoding_converter_set_callback (GflsEncodingConverter *converter,
                                      GflsEncodingConverterCallback callback,
                                      gpointer user_data);

Sets the GflsEncodingConverterCallback.

[skip]

Parameters

converter

a GflsEncodingConverter.

 

callback

function to call back to provide the output.

 

user_data

user data to pass to callback .

 

Since: 0.5


gfls_encoding_converter_open ()

gboolean
gfls_encoding_converter_open (GflsEncodingConverter *converter,
                              const gchar *from_charset,
                              const gchar *to_charset,
                              GError **error);

Similar to gfls_iconv_open().

Parameters

converter

a GflsEncodingConverter.

 

from_charset

source charset.

 

to_charset

destination charset.

 

error

location to a GError, or NULL to ignore errors.

 

Returns

TRUE on success, FALSE on error.

Since: 0.5


gfls_encoding_converter_feed ()

gboolean
gfls_encoding_converter_feed (GflsEncodingConverter *converter,
                              const guint8 *data,
                              gsize n_bytes,
                              GError **error);

Feeds some input bytes to the converter .

Can be called several times (useful for streaming scenarios).

The output is sent with the GflsEncodingConverterCallback.

Parameters

converter

a GflsEncodingConverter.

 

data

input bytes.

 

n_bytes

the number of input bytes.

 

error

location to a GError, or NULL to ignore errors.

 

Returns

TRUE on success, FALSE on error.

Since: 0.5


gfls_encoding_converter_finish_feeding ()

gboolean
gfls_encoding_converter_finish_feeding
                               (GflsEncodingConverter *converter,
                                GError **error);

Finishes the input feeding.

Note that the GflsEncodingConverterCallback can be called by this function too.

Parameters

converter

a GflsEncodingConverter.

 

error

location to a GError, or NULL to ignore errors.

 

Returns

TRUE on success, FALSE on error.

Since: 0.5


gfls_encoding_converter_get_lossy_conversion ()

gboolean
gfls_encoding_converter_get_lossy_conversion
                               (GflsEncodingConverter *converter);

Parameters

converter

a GflsEncodingConverter.

 

Returns

whether GFLS_ICONV_RESULT_LOSSY_CONVERSION was encountered.

Since: 0.5

Types and Values

struct GflsEncodingConverter

struct GflsEncodingConverter;