SF.net SVN: geany:[4003] trunk

eht16 at users.sourceforge.net eht16 at xxxxx
Mon Jul 20 23:10:46 UTC 2009


Revision: 4003
          http://geany.svn.sourceforge.net/geany/?rev=4003&view=rev
Author:   eht16
Date:     2009-07-20 23:10:46 +0000 (Mon, 20 Jul 2009)

Log Message:
-----------
Move utils_str_remove_chars() from the plugins/splitwindow.c to src/utils.c and add it to the plugin API.
Make utils_str_remove_chars() work on a new copy of the input string instead of modifying it in place.

Modified Paths:
--------------
    trunk/ChangeLog
    trunk/plugins/geanyfunctions.h
    trunk/plugins/splitwindow.c
    trunk/src/plugindata.h
    trunk/src/plugins.c
    trunk/src/utils.c
    trunk/src/utils.h

Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/ChangeLog	2009-07-20 23:10:46 UTC (rev 4003)
@@ -5,6 +5,12 @@
    is empty.
  * src/win32.c:
    Fix some harmless compiler warnings.
+ * plugins/geanyfunctions.h, plugins/splitwindow.c, src/plugindata.h,
+   src/plugins.c, src/utils.c, src/utils.h:
+   Move utils_str_remove_chars() from the plugins/splitwindow.c to
+   src/utils.c and add it to the plugin API.
+   Make utils_str_remove_chars() work on a new copy of the input string
+   instead of modifying it in place.
 
 
 2009-07-20  Nick Treleaven  <nick(dot)treleaven(at)btinternet(dot)com>

Modified: trunk/plugins/geanyfunctions.h
===================================================================
--- trunk/plugins/geanyfunctions.h	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/plugins/geanyfunctions.h	2009-07-20 23:10:46 UTC (rev 4003)
@@ -188,6 +188,8 @@
 	geany_functions->p_utils->string_replace_first
 #define utils_str_middle_truncate \
 	geany_functions->p_utils->str_middle_truncate
+#define utils_str_remove_chars \
+	geany_functions->p_utils->str_remove_chars
 #define ui_dialog_vbox_new \
 	geany_functions->p_ui->dialog_vbox_new
 #define ui_frame_new_with_alignment \

Modified: trunk/plugins/splitwindow.c
===================================================================
--- trunk/plugins/splitwindow.c	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/plugins/splitwindow.c	2009-07-20 23:10:46 UTC (rev 4003)
@@ -211,50 +211,6 @@
 }
 
 
-/* Avoid adding new string translations which are the same but without an underscore.
- * @warning Heavy use may cause stack exhaustion. */
-#define no_underscore(str)\
-	utils_str_remove_chars(utils_strdupa(str), "_")
-
-/* Like strcpy, but can handle overlapping src and dest. */
-static gchar *utils_str_copy(gchar *dest, const gchar *src)
-{
-	gchar *cpy;
-
-	/* strcpy might not handle overlaps, so make a copy */
-	cpy = utils_strdupa(src);
-	return strcpy(dest, cpy);
-}
-
-
-/* Remove characters from a string, in place.
- * @param chars Characters to remove.
- * @return @a str */
-/* Note: Could be more efficient by writing non-chars into new string then using only one strcpy. */
-static gchar *utils_str_remove_chars(gchar *str, const gchar *chars)
-{
-	gchar *ptr;
-	gsize len;
-
-	g_return_val_if_fail(str, NULL);
-
-	len = strlen(str);
-	ptr = str;
-
-	while (ptr < str + len)
-	{
-		if (strchr(chars, *ptr))
-		{
-			utils_str_copy(ptr, ptr + 1);
-			len--;
-		}
-		else
-			ptr++;
-	}
-	return str;
-}
-
-
 static const gchar *ui_get_stock_label(const gchar *stock_id)
 {
 	GtkStockItem item;
@@ -278,8 +234,8 @@
 	if (stock_id && !label)
 	{
 		label = ui_get_stock_label(stock_id);
-		dup = g_strdup(label);
-		label = utils_str_remove_chars(dup, "_");
+		dup = utils_str_remove_chars(label, "_");
+		label = dup;
 	}
 	item = gtk_tool_button_new(NULL, label);
 	if (stock_id)
@@ -310,6 +266,7 @@
 {
 	GtkWidget *toolbar, *item;
 	GtkToolItem *tool_item;
+	gchar *label;
 
 	toolbar = gtk_toolbar_new();
 	gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), GTK_ICON_SIZE_MENU);
@@ -329,9 +286,11 @@
 	gtk_container_add(GTK_CONTAINER(tool_item), item);
 	edit_window.name_label = item;
 
-	item = ui_tool_button_new(GTK_STOCK_CLOSE, no_underscore(_("_Unsplit")), NULL);
+	label = utils_str_remove_chars(_("_Unsplit"), "_");
+	item = ui_tool_button_new(GTK_STOCK_CLOSE, label, NULL);
 	gtk_container_add(GTK_CONTAINER(toolbar), item);
 	g_signal_connect(item, "clicked", G_CALLBACK(on_unsplit), NULL);
+	g_free(label);
 
 	return toolbar;
 }

Modified: trunk/src/plugindata.h
===================================================================
--- trunk/src/plugindata.h	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/src/plugindata.h	2009-07-20 23:10:46 UTC (rev 4003)
@@ -50,7 +50,7 @@
 enum {
 	/** The Application Programming Interface (API) version, incremented
 	 * whenever any plugin data types are modified or appended to. */
-	GEANY_API_VERSION = 147,
+	GEANY_API_VERSION = 148,
 
 	/** The Application Binary Interface (ABI) version, incremented whenever
 	 * existing fields in the plugin data types have to be changed or reordered. */
@@ -369,6 +369,7 @@
 	guint		(*string_replace_first) (GString *haystack, const gchar *needle,
 				 const gchar *replace);
 	gchar*		(*str_middle_truncate) (const gchar *string, guint truncate_length);
+	gchar*		(*str_remove_chars) (const gchar *string, const gchar *chars);
 }
 UtilsFuncs;
 

Modified: trunk/src/plugins.c
===================================================================
--- trunk/src/plugins.c	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/src/plugins.c	2009-07-20 23:10:46 UTC (rev 4003)
@@ -221,7 +221,8 @@
 	&utils_get_date_time,
 	&utils_open_browser,
 	&utils_string_replace_first,
-	&utils_str_middle_truncate
+	&utils_str_middle_truncate,
+	&utils_str_remove_chars
 };
 
 static UIUtilsFuncs uiutils_funcs = {

Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/src/utils.c	2009-07-20 23:10:46 UTC (rev 4003)
@@ -1756,3 +1756,49 @@
 }
 
 
+/* Like strcpy, but can handle overlapping src and dest. */
+static gchar *utils_str_copy(gchar *dest, const gchar *src)
+{
+	gchar *cpy;
+
+	/* strcpy might not handle overlaps, so make a copy */
+	cpy = utils_strdupa(src);
+	return strcpy(dest, cpy);
+}
+
+
+/**
+ *  Remove characters from a string.
+ *
+ *  @param str The original string
+ *  @param chars Characters to remove.
+ *
+ *  @return A newly-allocated copy of @c str without the characters in @c chars,
+ *          should be freed when no longer needed.
+ **/
+gchar *utils_str_remove_chars(const gchar *string, const gchar *chars)
+{
+	gchar *ptr;
+	gchar *result;
+	gsize len;
+
+	g_return_val_if_fail(string, NULL);
+
+	result = g_strdup(string);
+	len = strlen(result);
+	ptr = result;
+
+	while (ptr < result + len)
+	{
+		if (strchr(chars, *ptr))
+		{
+			utils_str_copy(ptr, ptr + 1);
+			len--;
+		}
+		else
+			ptr++;
+	}
+	return result;
+}
+
+

Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h	2009-07-20 23:09:29 UTC (rev 4002)
+++ trunk/src/utils.h	2009-07-20 23:10:46 UTC (rev 4003)
@@ -198,4 +198,6 @@
 
 gchar *utils_str_middle_truncate(const gchar *string, guint truncate_length);
 
+gchar *utils_str_remove_chars(const gchar *string, const gchar *chars);
+
 #endif


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