geany  1.38
About: Geany is a text editor (using GTK2) with basic features of an integrated development environment (syntax highlighting, code folding, symbol name auto-completion, ...). F: office T: editor programming GTK+ IDE
  Fossies Dox: geany-1.38.tar.bz2  ("unofficial" and yet experimental doxygen-generated source code documentation)  

encodings.c File Reference
#include "encodings.h"
#include "encodingsprivate.h"
#include "app.h"
#include "callbacks.h"
#include "documentprivate.h"
#include "support.h"
#include "ui_utils.h"
#include "utils.h"
#include <string.h>
Include dependency graph for encodings.c:

Go to the source code of this file.

Classes

struct  BufferData
 

Macros

#define PATTERN_HTMLMETA   "<meta\\s+http-equiv\\s*=\\s*\"?content-type\"?\\s+content\\s*=\\s*\"text/x?html;\\s*charset=([a-z0-9_-]+)\"\\s*/?>"
 
#define PATTERN_CODING   "coding[\t ]*[:=][\t ]*\"?([a-z0-9-]+)\"?[\t ]*"
 
#define fill(Order, Group, Idx, Charset, Name)
 

Functions

static void init_encodings (void)
 
static gboolean encodings_charset_equals (const gchar *a, const gchar *b)
 
GeanyEncodingIndex encodings_get_idx_from_charset (const gchar *charset)
 
const GeanyEncodingencodings_get_from_charset (const gchar *charset)
 
static const gchar * encodings_normalize_charset (const gchar *charset)
 
const GeanyEncodingencodings_get_from_index (gint idx)
 
const gchar * encodings_get_charset_from_index (gint idx)
 Gets the character set name of the specified index e.g. More...
 
gchar * encodings_to_string (const GeanyEncoding *enc)
 
const gchar * encodings_get_charset (const GeanyEncoding *enc)
 
void encodings_select_radio_item (const gchar *charset)
 
static GRegex * regex_compile (const gchar *pattern)
 
static gchar * regex_match (GRegex *preg, const gchar *buffer, gsize size)
 
static void encodings_radio_item_change_cb (GtkCheckMenuItem *menuitem, gpointer user_data)
 
static void encodings_reload_radio_item_change_cb (GtkMenuItem *menuitem, gpointer user_data)
 
void encodings_finalize (void)
 
void encodings_init (void)
 
static gint encoding_combo_store_sort_func (GtkTreeModel *model, GtkTreeIter *a, GtkTreeIter *b, gpointer data)
 
GtkTreeStore * encodings_encoding_store_new (gboolean has_detect)
 
gint encodings_encoding_store_get_encoding (GtkTreeStore *store, GtkTreeIter *iter)
 
gboolean encodings_encoding_store_get_iter (GtkTreeStore *store, GtkTreeIter *iter, gint enc)
 
void encodings_encoding_store_cell_data_func (GtkCellLayout *cell_layout, GtkCellRenderer *cell, GtkTreeModel *tree_model, GtkTreeIter *iter, gpointer data)
 
gchar * encodings_convert_to_utf8_from_charset (const gchar *buffer, gssize size, const gchar *charset, gboolean fast)
 Tries to convert buffer into UTF-8 encoding from the encoding specified with charset. More...
 
static gchar * encodings_check_regexes (const gchar *buffer, gsize size)
 
static gchar * encodings_convert_to_utf8_with_suggestion (const gchar *buffer, gssize size, const gchar *suggested_charset, gchar **used_encoding)
 
gchar * encodings_convert_to_utf8 (const gchar *buffer, gssize size, gchar **used_encoding)
 Tries to convert buffer into UTF-8 encoding and store the detected original encoding in used_encoding. More...
 
GeanyEncodingIndex encodings_scan_unicode_bom (const gchar *string, gsize len, guint *bom_len)
 
gboolean encodings_is_unicode_charset (const gchar *string)
 
static gboolean handle_forced_encoding (BufferData *buffer, const gchar *forced_enc)
 
static gboolean handle_encoding (BufferData *buffer, GeanyEncodingIndex enc_idx)
 
static void handle_bom (BufferData *buffer)
 
static gboolean handle_buffer (BufferData *buffer, const gchar *forced_enc)
 
gboolean encodings_convert_to_utf8_auto (gchar **buf, gsize *size, const gchar *forced_enc, gchar **used_encoding, gboolean *has_bom, gboolean *partial)
 

Variables

static GRegex * pregs [2]
 
static gboolean pregs_loaded = FALSE
 
GeanyEncoding encodings [GEANY_ENCODINGS_MAX]
 
static GtkWidget * radio_items [GEANY_ENCODINGS_MAX]
 

Macro Definition Documentation

◆ fill

#define fill (   Order,
  Group,
  Idx,
  Charset,
  Name 
)
Value:
encodings[Idx].idx = Idx; \
encodings[Idx].order = Order; \
encodings[Idx].group = Group; \
encodings[Idx].charset = Charset; \
encodings[Idx].name = Name;
GeanyEncoding encodings[GEANY_ENCODINGS_MAX]
Definition: encodings.c:59
static vString * Name
Definition: geany_vhdl.c:59
GeanyEncodingIndex idx

Definition at line 62 of file encodings.c.

◆ PATTERN_CODING

#define PATTERN_CODING   "coding[\t ]*[:=][\t ]*\"?([a-z0-9-]+)\"?[\t ]*"

Definition at line 52 of file encodings.c.

◆ PATTERN_HTMLMETA

#define PATTERN_HTMLMETA   "<meta\\s+http-equiv\\s*=\\s*\"?content-type\"?\\s+content\\s*=\\s*\"text/x?html;\\s*charset=([a-z0-9_-]+)\"\\s*/?>"

Definition at line 50 of file encodings.c.

Function Documentation

◆ encoding_combo_store_sort_func()

static gint encoding_combo_store_sort_func ( GtkTreeModel *  model,
GtkTreeIter *  a,
GtkTreeIter *  b,
gpointer  data 
)
static

Definition at line 494 of file encodings.c.

Referenced by encodings_encoding_store_new().

◆ encodings_charset_equals()

static gboolean encodings_charset_equals ( const gchar *  a,
const gchar *  b 
)
static

Definition at line 148 of file encodings.c.

Referenced by encodings_get_from_charset(), and encodings_get_idx_from_charset().

◆ encodings_check_regexes()

static gchar * encodings_check_regexes ( const gchar *  buffer,
gsize  size 
)
static

Definition at line 668 of file encodings.c.

References NULL, pregs, and regex_match().

Referenced by encodings_convert_to_utf8(), and handle_encoding().

◆ encodings_convert_to_utf8()

gchar * encodings_convert_to_utf8 ( const gchar *  buffer,
gssize  size,
gchar **  used_encoding 
)

Tries to convert buffer into UTF-8 encoding and store the detected original encoding in used_encoding.

Parameters
bufferthe input string to convert.
sizethe length of the string, or -1 if the string is nul-terminated.
used_encoding (out) return location of the detected encoding of the input string, or NULL.
Returns
If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL.

Definition at line 784 of file encodings.c.

References encodings_check_regexes(), and encodings_convert_to_utf8_with_suggestion().

◆ encodings_convert_to_utf8_auto()

gboolean encodings_convert_to_utf8_auto ( gchar **  buf,
gsize *  size,
const gchar *  forced_enc,
gchar **  used_encoding,
gboolean *  has_bom,
gboolean *  partial 
)

◆ encodings_convert_to_utf8_from_charset()

gchar * encodings_convert_to_utf8_from_charset ( const gchar *  buffer,
gssize  size,
const gchar *  charset,
gboolean  fast 
)

Tries to convert buffer into UTF-8 encoding from the encoding specified with charset.

If fast is not set, additional checks to validate the converted string are performed.

Parameters
bufferThe input string to convert.
sizeThe length of the string, or -1 if the string is nul-terminated.
charsetThe charset to be used for conversion.
fastTRUE to only convert the input and skip extended checks on the converted string.
Returns
If the conversion was successful, a newly allocated nul-terminated string, which must be freed with g_free(). Otherwise NULL.

Definition at line 625 of file encodings.c.

References geany_debug(), and NULL.

Referenced by encodings_convert_to_utf8_with_suggestion(), get_symbol_name(), get_symbol_tooltip(), handle_encoding(), and handle_forced_encoding().

◆ encodings_convert_to_utf8_with_suggestion()

static gchar * encodings_convert_to_utf8_with_suggestion ( const gchar *  buffer,
gssize  size,
const gchar *  suggested_charset,
gchar **  used_encoding 
)
static

◆ encodings_encoding_store_cell_data_func()

void encodings_encoding_store_cell_data_func ( GtkCellLayout *  cell_layout,
GtkCellRenderer *  cell,
GtkTreeModel *  tree_model,
GtkTreeIter *  iter,
gpointer  data 
)

Definition at line 597 of file encodings.c.

References NULL, and text.

Referenced by prefs_show_dialog(), and ui_create_encodings_combo_box().

◆ encodings_encoding_store_get_encoding()

gint encodings_encoding_store_get_encoding ( GtkTreeStore *  store,
GtkTreeIter *  iter 
)

◆ encodings_encoding_store_get_iter()

gboolean encodings_encoding_store_get_iter ( GtkTreeStore *  store,
GtkTreeIter *  iter,
gint  enc 
)

◆ encodings_encoding_store_new()

GtkTreeStore * encodings_encoding_store_new ( gboolean  has_detect)

◆ encodings_finalize()

void encodings_finalize ( void  )

Definition at line 391 of file encodings.c.

References pregs, and pregs_loaded.

Referenced by do_main_quit().

◆ encodings_get_charset()

const gchar * encodings_get_charset ( const GeanyEncoding enc)

Definition at line 285 of file encodings.c.

References GeanyEncoding::charset, and NULL.

◆ encodings_get_charset_from_index()

const gchar * encodings_get_charset_from_index ( gint  idx)

Gets the character set name of the specified index e.g.

for use with document_set_encoding().

Parameters
idxGeanyEncodingIndex to retrieve the corresponding character set.
Returns
The charset according to idx, or NULL if the index is invalid.
Since
0.13

Definition at line 267 of file encodings.c.

References GeanyEncoding::charset, encodings, GEANY_ENCODINGS_MAX, and NULL.

Referenced by on_find_in_files_dialog_response(), and open_session_file().

◆ encodings_get_from_charset()

const GeanyEncoding * encodings_get_from_charset ( const gchar *  charset)

◆ encodings_get_from_index()

const GeanyEncoding * encodings_get_from_index ( gint  idx)

Definition at line 247 of file encodings.c.

References encodings, GEANY_ENCODINGS_MAX, and NULL.

◆ encodings_get_idx_from_charset()

GeanyEncodingIndex encodings_get_idx_from_charset ( const gchar *  charset)

◆ encodings_init()

◆ encodings_is_unicode_charset()

gboolean encodings_is_unicode_charset ( const gchar *  string)

◆ encodings_normalize_charset()

static const gchar * encodings_normalize_charset ( const gchar *  charset)
static

◆ encodings_radio_item_change_cb()

static void encodings_radio_item_change_cb ( GtkCheckMenuItem *  menuitem,
gpointer  user_data 
)
static

◆ encodings_reload_radio_item_change_cb()

static void encodings_reload_radio_item_change_cb ( GtkMenuItem *  menuitem,
gpointer  user_data 
)
static

Definition at line 381 of file encodings.c.

References document_get_current(), document_reload_prompt(), and NULL.

Referenced by encodings_init().

◆ encodings_scan_unicode_bom()

GeanyEncodingIndex encodings_scan_unicode_bom ( const gchar *  string,
gsize  len,
guint *  bom_len 
)

◆ encodings_select_radio_item()

void encodings_select_radio_item ( const gchar *  charset)

◆ encodings_to_string()

gchar * encodings_to_string ( const GeanyEncoding enc)

Definition at line 275 of file encodings.c.

References GeanyEncoding::charset, GeanyEncoding::name, and NULL.

Referenced by encodings_encoding_store_new(), and encodings_init().

◆ handle_bom()

static void handle_bom ( BufferData buffer)
static

Definition at line 983 of file encodings.c.

References BufferData::data, encodings_scan_unicode_bom(), BufferData::len, and BufferData::size.

Referenced by handle_buffer().

◆ handle_buffer()

◆ handle_encoding()

◆ handle_forced_encoding()

static gboolean handle_forced_encoding ( BufferData buffer,
const gchar *  forced_enc 
)
static

◆ init_encodings()

static void init_encodings ( void  )
static

Definition at line 69 of file encodings.c.

References _, ASIAN, EASTASIAN, EASTEUROPEAN, fill, GEANY_ENCODING_ARMSCII_8, GEANY_ENCODING_BIG5, GEANY_ENCODING_BIG5_HKSCS, GEANY_ENCODING_CP_866, GEANY_ENCODING_CP_932, GEANY_ENCODING_EUC_JP, GEANY_ENCODING_EUC_KR, GEANY_ENCODING_EUC_TW, GEANY_ENCODING_GB18030, GEANY_ENCODING_GB2312, GEANY_ENCODING_GBK, GEANY_ENCODING_GEOSTD8, GEANY_ENCODING_HZ, GEANY_ENCODING_IBM_850, GEANY_ENCODING_IBM_852, GEANY_ENCODING_IBM_855, GEANY_ENCODING_IBM_857, GEANY_ENCODING_IBM_862, GEANY_ENCODING_IBM_864, GEANY_ENCODING_ISO_2022_JP, GEANY_ENCODING_ISO_2022_KR, GEANY_ENCODING_ISO_8859_1, GEANY_ENCODING_ISO_8859_10, GEANY_ENCODING_ISO_8859_13, GEANY_ENCODING_ISO_8859_14, GEANY_ENCODING_ISO_8859_15, GEANY_ENCODING_ISO_8859_16, GEANY_ENCODING_ISO_8859_2, GEANY_ENCODING_ISO_8859_3, GEANY_ENCODING_ISO_8859_4, GEANY_ENCODING_ISO_8859_5, GEANY_ENCODING_ISO_8859_6, GEANY_ENCODING_ISO_8859_7, GEANY_ENCODING_ISO_8859_8, GEANY_ENCODING_ISO_8859_8_I, GEANY_ENCODING_ISO_8859_9, GEANY_ENCODING_ISO_IR_111, GEANY_ENCODING_JOHAB, GEANY_ENCODING_KOI8_R, GEANY_ENCODING_KOI8_U, GEANY_ENCODING_NONE, GEANY_ENCODING_SHIFT_JIS, GEANY_ENCODING_TCVN, GEANY_ENCODING_TIS_620, GEANY_ENCODING_UCS_2BE, GEANY_ENCODING_UCS_2LE, GEANY_ENCODING_UHC, GEANY_ENCODING_UTF_16BE, GEANY_ENCODING_UTF_16LE, GEANY_ENCODING_UTF_32BE, GEANY_ENCODING_UTF_32LE, GEANY_ENCODING_UTF_7, GEANY_ENCODING_UTF_8, GEANY_ENCODING_VISCII, GEANY_ENCODING_WINDOWS_1250, GEANY_ENCODING_WINDOWS_1251, GEANY_ENCODING_WINDOWS_1252, GEANY_ENCODING_WINDOWS_1253, GEANY_ENCODING_WINDOWS_1254, GEANY_ENCODING_WINDOWS_1255, GEANY_ENCODING_WINDOWS_1256, GEANY_ENCODING_WINDOWS_1257, GEANY_ENCODING_WINDOWS_1258, MIDDLEEASTERN, NONE, UNICODE, and WESTEUROPEAN.

Referenced by encodings_init().

◆ regex_compile()

static GRegex * regex_compile ( const gchar *  pattern)
static

Definition at line 323 of file encodings.c.

References error(), geany_debug(), and NULL.

Referenced by encodings_init().

◆ regex_match()

static gchar * regex_match ( GRegex *  preg,
const gchar *  buffer,
gsize  size 
)
static

Definition at line 337 of file encodings.c.

References geany_debug(), NULL, pregs_loaded, and SETPTR.

Referenced by encodings_check_regexes().

Variable Documentation

◆ encodings

◆ pregs

GRegex* pregs[2]
static

Definition at line 55 of file encodings.c.

Referenced by encodings_check_regexes(), encodings_finalize(), and encodings_init().

◆ pregs_loaded

gboolean pregs_loaded = FALSE
static

Definition at line 56 of file encodings.c.

Referenced by encodings_finalize(), encodings_init(), and regex_match().

◆ radio_items

GtkWidget* radio_items[GEANY_ENCODINGS_MAX]
static

Definition at line 294 of file encodings.c.

Referenced by encodings_init(), and encodings_select_radio_item().