## GtkSourceEncoding GtkSourceEncoding — Character encoding |

## Functions

GtkSourceEncoding * | gtk_source_encoding_new ()
GtkSourceEncoding * | gtk_source_encoding_new_utf8 ()
GtkSourceEncoding * | gtk_source_encoding_new_from_locale ()
GtkSourceEncoding * | gtk_source_encoding_copy ()
gpointer | gtk_source_encoding_copy_func ()
void | gtk_source_encoding_free ()
const gchar * | gtk_source_encoding_get_charset ()
gboolean | gtk_source_encoding_has_known_charset ()
const gchar * | gtk_source_encoding_get_name ()
gchar * | gtk_source_encoding_to_string ()
gboolean | gtk_source_encoding_is_utf8 ()
gboolean | gtk_source_encoding_is_locale ()
gboolean | gtk_source_encoding_equals ()
gint | gtk_source_encoding_compare_func ()
GSList * | gtk_source_encoding_get_all ()
GSList * | gtk_source_encoding_get_default_candidates ()
GSList * | gtk_source_encoding_remove_duplicates ()

## Types and Values

| GtkSourceEncoding
enum | GtkSourceEncodingDuplicates

## Object Hierarchy

        GBoxed
        ╰── GtkSourceEncoding
        GEnum
        ╰── GtkSourceEncodingDuplicates

## Includes

    #include <gtksourceview/gtksource.h>

## Description

The GtkSourceEncoding boxed type represents a character encoding. It is used for example by GtkSourceFile. Note that the text in GTK widgets is always encoded in UTF-8.

## Functions

### gtk_source_encoding_new ()

    GtkSourceEncoding *
    gtk_source_encoding_new (const gchar *charset);

Creates a new GtkSourceEncoding from a character set such as "UTF-8" or "ISO-8859-1".

The `gtk_source_encoding_get_charset()` function will return exactly the same string as the `charset` passed in to this constructor.

#### Parameters

charset | a character set. |

#### Returns

the new GtkSourceEncoding. Free with `gtk_source_encoding_free()`.

[transfer full]

Since: 299.6

### gtk_source_encoding_new_utf8 ()

    GtkSourceEncoding *
    gtk_source_encoding_new_utf8 (void);

Creates a new GtkSourceEncoding with the "UTF-8" character set.

#### Returns

the new GtkSourceEncoding. Free with `gtk_source_encoding_free()`.

[transfer full]

Since: 299.6

### gtk_source_encoding_new_from_locale ()

    GtkSourceEncoding *
    gtk_source_encoding_new_from_locale (void);

Creates a new GtkSourceEncoding from the current locale, as returned by `g_get_charset()`.

#### Returns

the new GtkSourceEncoding. Free with `gtk_source_encoding_free()`.

[transfer full]

Since: 299.6

### gtk_source_encoding_copy ()

    GtkSourceEncoding *
    gtk_source_encoding_copy (const GtkSourceEncoding *enc);

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

a copy of `enc` .

[transfer full]

Since: 299.6

### gtk_source_encoding_copy_func ()

    gpointer
    gtk_source_encoding_copy_func (gconstpointer src,
                                   gpointer data);

A GCopyFunc provided for convenience. It does the same as `gtk_source_encoding_copy()`. It is useful for example for `g_slist_copy_deep()`.

#### Parameters

src | a GtkSourceEncoding. |
data | Additional data (ignored). |

#### Returns

a copy of `src` .

Since: 299.6

### gtk_source_encoding_free ()

    void
    gtk_source_encoding_free (GtkSourceEncoding *enc);

#### Parameters

enc | a GtkSourceEncoding, or `NULL`. | [nullable]

Since: 299.6

### gtk_source_encoding_get_charset ()

    const gchar *
    gtk_source_encoding_get_charset (const GtkSourceEncoding *enc);

Gets the character set of the GtkSourceEncoding, such as "UTF-8" or "ISO-8859-1".

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

the character set of the GtkSourceEncoding.

Since: 299.6

### gtk_source_encoding_has_known_charset ()

    gboolean
    gtk_source_encoding_has_known_charset (const GtkSourceEncoding *enc);

Returns `TRUE` if `enc` has a charset known by GtkSourceEncoding. In other words: if `enc` is equal to an encoding returned by `gtk_source_encoding_get_all()`.

When the charset string comes from an untrusted source, it can be desirable to check it.

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

whether `enc` has a charset known by GtkSourceEncoding.

Since: 299.6

### gtk_source_encoding_get_name ()

    const gchar *
    gtk_source_encoding_get_name (const GtkSourceEncoding *enc);

Gets the name of the GtkSourceEncoding such as "Unicode" or "Western". If the charset is unknown by GtkSourceEncoding, "Unknown" is returned. The return value is already translated by gettext.

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

the name of the GtkSourceEncoding.

Since: 299.6

### gtk_source_encoding_to_string ()

    gchar *
    gtk_source_encoding_to_string (const GtkSourceEncoding *enc);

Returns the encoding name with the charset in parenthesis, for example "Unicode (UTF-8)". If the name is unknown, just the charset is returned. The name is translated by gettext.

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

a string representation. Free with `g_free()` when no longer needed.

Since: 299.6

### gtk_source_encoding_is_utf8 ()

    gboolean
    gtk_source_encoding_is_utf8 (const GtkSourceEncoding *enc);

Returns whether `enc` is a UTF-8 encoding.

If `enc` was created with `gtk_source_encoding_new_utf8()`, the charset is "UTF-8". But iconv supports other variants: "UTF8", "utf-8" and "utf8". This function returns `TRUE` for all UTF-8 variants supported by iconv.

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

whether `enc` is a UTF-8 encoding.

Since: 299.6

### gtk_source_encoding_is_locale ()

    gboolean
    gtk_source_encoding_is_locale (const GtkSourceEncoding *enc);

#### Parameters

enc | a GtkSourceEncoding. |

#### Returns

whether `enc` is the locale encoding (see `gtk_source_encoding_new_from_locale()`).

Since: 299.6

### gtk_source_encoding_equals ()

    gboolean
    gtk_source_encoding_equals (const GtkSourceEncoding *enc1,
                                const GtkSourceEncoding *enc2);

Returns whether `enc1` and `enc2` are equal. It returns `TRUE` if and only if:

- Both `enc1` and `enc2` are `NULL`;

- Or both `enc1` and `enc2` have a UTF-8 charset (see `gtk_source_encoding_is_utf8()`);

- Or the charsets are equal according to `g_ascii_strcasecmp()` (because iconv-compatible charsets are case insensitive).

#### Parameters

enc1 | a GtkSourceEncoding, or `NULL`. | [nullable]
enc2 | a GtkSourceEncoding, or `NULL`. | [nullable]

#### Returns

whether `enc1` and `enc2` are equal.

Since: 299.6

### gtk_source_encoding_compare_func ()

    gint
    gtk_source_encoding_compare_func (gconstpointer a,
                                      gconstpointer b);

A GCompareFunc provided for convenience. When 0 is returned it means that the two encodings are equal according to `gtk_source_encoding_equals()`.

It is useful for example for `g_slist_find_custom()`.

#### Parameters

a | a GtkSourceEncoding. | [nullable]
b | a GtkSourceEncoding. | [nullable]

#### Returns

an integer according to GCompareFunc.

Since: 299.6

### gtk_source_encoding_get_all ()

    GSList *
    gtk_source_encoding_get_all (void);

Gets a list of all encodings known by GtkSourceEncoding.

#### Returns

a list of GtkSourceEncoding's.

[transfer full][element-type GtkSourceEncoding]

Since: 299.6

### gtk_source_encoding_get_default_candidates ()

    GSList *
    gtk_source_encoding_get_default_candidates
                                   (void);

Gets the list of default candidate encodings to try when loading a file. See `gtk_source_file_loader_set_candidate_encodings()`.

This function returns a different list depending on the current locale (i.e., language, country and default encoding). The UTF-8 encoding and the current locale encoding are guaranteed to be present in the returned list.

Note that the returned list doesn't contain all encodings known by GtkSourceEncoding, it is a limited list that contains only the encodings that have the most likelihood to fit for the current locale.

#### Returns

the list of default candidate encodings.

[transfer full][element-type GtkSourceEncoding]

Since: 299.6

### gtk_source_encoding_remove_duplicates ()

    GSList *
    gtk_source_encoding_remove_duplicates (GSList *list,
                                           GtkSourceEncodingDuplicates removal_type);

A convenience function to remove duplicated encodings in a list.

#### Parameters

list | a list of GtkSourceEncoding's. | [transfer full][element-type GtkSourceEncoding]
removal_type | the GtkSourceEncodingDuplicates. |

#### Returns

the new start of the GSList.

[transfer full][element-type GtkSourceEncoding]

Since: 299.6

## Types and Values

### GtkSourceEncoding

    typedef struct _GtkSourceEncoding GtkSourceEncoding;

### enum GtkSourceEncodingDuplicates

Specifies which GtkSourceEncoding occurrence to keep when removing duplicated encodings in a list with `gtk_source_encoding_remove_duplicates()`.

#### Members

GTK_SOURCE_ENCODING_DUPLICATES_KEEP_FIRST | Keep the first occurrence. |
GTK_SOURCE_ENCODING_DUPLICATES_KEEP_LAST | Keep the last occurrence. |

Since: 299.6

## See Also

GtkSourceFile, GtkSourceFileLoader, GtkSourceFileSaver