SF.net SVN: geany: [2177] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Wed Jan 16 16:50:12 UTC 2008


Revision: 2177
          http://geany.svn.sourceforge.net/geany/?rev=2177&view=rev
Author:   eht16
Date:     2008-01-16 08:50:10 -0800 (Wed, 16 Jan 2008)

Log Message:
-----------
Add encodings_get_charset_from_index() and make it available through plugin API.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/src/encodings.c
    trunk/src/encodings.h
    trunk/src/plugindata.h
    trunk/src/plugins.c

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/ChangeLog	2008-01-16 16:50:10 UTC (rev 2177)
@@ -3,6 +3,9 @@
  * geany.glade, src/interface.c, src/keyfile.c, src/prefs.c,
    src/project.c, src/project.h:
    Add option for project session files support.
+ * src/encodings.c, src/encodings.h, src/plugindata.h, src/plugins.c:
+   Add encodings_get_charset_from_index() and make it available through
+   plugin API.
 
 
 2008-01-16  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/src/encodings.c
===================================================================
--- trunk/src/encodings.c	2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/encodings.c	2008-01-16 16:50:10 UTC (rev 2177)
@@ -172,13 +172,32 @@
 
 const GeanyEncoding *encodings_get_from_index(gint idx)
 {
-	g_return_val_if_fail(idx >= 0, NULL);
-	g_return_val_if_fail(idx < GEANY_ENCODINGS_MAX, NULL);
+	g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL);
 
 	return &encodings[idx];
 }
 
 
+/*
+ * gtk_status_icon_get_stock:
+ * @idx: #GeanyEncodingIndex to retrieve the corresponding character set
+ *
+ * Gets the character set name of the specified index e.g. for use with
+ * document_set_encoding.
+ *
+ * Return value: charset according to idx,
+ *   or %NULL if the index is invalid.
+ *
+ * Since: 0.13
+ */
+const gchar* encodings_get_charset_from_index(gint idx)
+{
+	g_return_val_if_fail(idx >= 0 && idx < GEANY_ENCODINGS_MAX, NULL);
+
+	return encodings[idx].charset;
+}
+
+
 gchar *encodings_to_string(const GeanyEncoding* enc)
 {
 	g_return_val_if_fail(enc != NULL, NULL);
@@ -387,10 +406,21 @@
 }
 
 
-/* Converts a string from the given charset to UTF-8.
- * If fast is set, no further checks are performed. */
+/*
+ * encodings_convert_to_utf8_from_charset:
+ * @buffer: the input string to convert
+ * @size: the length of the string, or -1 if the string is nul-terminated
+ * @charset: the charset to be used for conversion
+ * @fast: TRUE to only convert the input and skip extended checks on the converted string
+ *
+ * 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.
+ *
+ * Return value: If the conversion was successful, a newly allocated nul-terminated string,
+ *   which must be freed with g_free(). Otherwise %NULL.
+ */
 gchar *encodings_convert_to_utf8_from_charset(const gchar *buffer, gsize size,
-											const gchar *charset, gboolean fast)
+											  const gchar *charset, gboolean fast)
 {
 	gchar *utf8_content = NULL;
 	GError *conv_error = NULL;
@@ -432,6 +462,18 @@
 }
 
 
+/*
+ * encodings_convert_to_utf8:
+ * @buffer: the input string to convert
+ * @size: the length of the string, or -1 if the string is nul-terminated.
+ * @used_encoding: return location of the detected encoding of the input string, or %NULL
+ *
+ * Tries to convert @buffer into UTF-8 encoding and store the detected original encoding in
+ * @used_encoding.
+ *
+ * Return value: If the conversion was successful, a newly allocated nul-terminated string,
+ *   which must be freed with g_free(). Otherwise %NULL.
+ */
 gchar *encodings_convert_to_utf8(const gchar *buffer, gsize size, gchar **used_encoding)
 {
 	gchar *locale_charset = NULL;
@@ -442,6 +484,11 @@
 	gboolean check_locale = FALSE;
 	guint i;
 
+	if ((gint)size == -1)
+	{
+		size = strlen(buffer);
+	}
+
 #ifdef HAVE_REGCOMP
 	// first try to read the encoding from the file content
 	for (i = 0; i < G_N_ELEMENTS(pregs) && ! check_regex; i++)

Modified: trunk/src/encodings.h
===================================================================
--- trunk/src/encodings.h	2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/encodings.h	2008-01-16 16:50:10 UTC (rev 2177)
@@ -62,6 +62,7 @@
 
 gchar* encodings_to_string(const GeanyEncoding* enc);
 const gchar* encodings_get_charset(const GeanyEncoding* enc);
+const gchar* encodings_get_charset_from_index(gint idx);
 
 void encodings_select_radio_item(const gchar *charset);
 

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/plugindata.h	2008-01-16 16:50:10 UTC (rev 2177)
@@ -93,7 +93,7 @@
 
 /* The API version should be incremented whenever any plugin data types below are
  * modified or appended to. */
-static const gint api_version = 38;
+static const gint api_version = 39;
 
 /* The ABI version should be incremented whenever existing fields in the plugin
  * data types below have to be changed or reordered. It should stay the same if fields
@@ -330,9 +330,10 @@
 
 typedef struct EncodingFuncs
 {
-	gchar*	(*convert_to_utf8) (const gchar *buffer, gsize size, gchar **used_encoding);
-	gchar* 	(*convert_to_utf8_from_charset) (const gchar *buffer, gsize size,
-											const gchar *charset, gboolean fast);
+	gchar*			(*convert_to_utf8) (const gchar *buffer, gsize size, gchar **used_encoding);
+	gchar* 			(*convert_to_utf8_from_charset) (const gchar *buffer, gsize size,
+													 const gchar *charset, gboolean fast);
+	const gchar*	(*get_charset_from_index) (gint idx);
 }
 EncodingFuncs;
 

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2008-01-16 16:30:34 UTC (rev 2176)
+++ trunk/src/plugins.c	2008-01-16 16:50:10 UTC (rev 2177)
@@ -178,7 +178,8 @@
 
 static EncodingFuncs encoding_funcs = {
 	&encodings_convert_to_utf8,
-	&encodings_convert_to_utf8_from_charset
+	&encodings_convert_to_utf8_from_charset,
+	&encodings_get_charset_from_index
 };
 
 static KeybindingFuncs keybindings_funcs = {


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.



More information about the Commits mailing list