SF.net SVN: geany:[4014] trunk
ntrel at users.sourceforge.net
ntrel at xxxxx
Thu Jul 23 16:01:46 UTC 2009
Revision: 4014
http://geany.svn.sourceforge.net/geany/?rev=4014&view=rev
Author: ntrel
Date: 2009-07-23 16:01:45 +0000 (Thu, 23 Jul 2009)
Log Message:
-----------
Rename utils_str_replace() utils_str_replace_all(), setting a
'gchar **haystack' argument instead of returning a new string.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/build.c
trunk/src/callbacks.c
trunk/src/printing.c
trunk/src/templates.c
trunk/src/utils.c
trunk/src/utils.h
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/ChangeLog 2009-07-23 16:01:45 UTC (rev 4014)
@@ -4,6 +4,10 @@
plugins/splitwindow.c:
Change utils_str_remove_chars() to work in place; fix allocating on
the stack (the string length could exhaust the stack size).
+ * src/templates.c, src/build.c, src/utils.c, src/utils.h,
+ src/printing.c, src/callbacks.c:
+ Rename utils_str_replace() utils_str_replace_all(), setting a
+ 'gchar **haystack' argument instead of returning a new string.
2009-07-21 Enrico Tröger <enrico(dot)troeger(at)uvena(dot)de>
Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/build.c 2009-07-23 16:01:45 UTC (rev 4014)
@@ -195,8 +195,8 @@
cmd_string = g_strdup((mode == LATEX_CMD_VIEW_DVI) ?
g_strdup(doc->file_type->programs->run_cmd) :
g_strdup(doc->file_type->programs->run_cmd2));
- cmd_string = utils_str_replace(cmd_string, "%f", view_file);
- cmd_string = utils_str_replace(cmd_string, "%e", executable);
+ utils_str_replace_all(&cmd_string, "%f", view_file);
+ utils_str_replace_all(&cmd_string, "%e", executable);
/* try convert in locale */
locale_cmd_string = utils_get_locale_from_utf8(cmd_string);
@@ -481,10 +481,10 @@
cmd_string = g_strdup(cmd);
/* replace %f and %e in the command string */
tmp = g_path_get_basename(locale_filename);
- cmd_string = utils_str_replace(cmd_string, "%f", tmp);
+ utils_str_replace_all(&cmd_string, "%f", tmp);
g_free(tmp);
tmp = g_path_get_basename(executable);
- cmd_string = utils_str_replace(cmd_string, "%e", tmp);
+ utils_str_replace_all(&cmd_string, "%e", tmp);
g_free(tmp);
g_free(executable);
@@ -618,9 +618,9 @@
/* replace %f and %e in the run_cmd string */
cmd = g_strdup(cmd);
tmp = g_path_get_basename(locale_filename);
- cmd = utils_str_replace(cmd, "%f", tmp);
+ utils_str_replace_all(&cmd, "%f", tmp);
g_free(tmp);
- cmd = utils_str_replace(cmd, "%e", executable);
+ utils_str_replace_all(&cmd, "%e", executable);
#ifdef HAVE_VTE
if (vte_info.load_vte && vc != NULL && vc->run_in_vte)
Modified: trunk/src/callbacks.c
===================================================================
--- trunk/src/callbacks.c 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/callbacks.c 2009-07-23 16:01:45 UTC (rev 4014)
@@ -1952,7 +1952,7 @@
/* substitute the wildcard %s and run the command if it is non empty */
if (NZV(command))
{
- command = utils_str_replace(command, "%s", word);
+ utils_str_replace_all(&command, "%s", word);
if (! g_spawn_command_line_async(command, &error))
{
Modified: trunk/src/printing.c
===================================================================
--- trunk/src/printing.c 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/printing.c 2009-07-23 16:01:45 UTC (rev 4014)
@@ -869,7 +869,7 @@
}
cmdline = g_strdup(printing_prefs.external_print_cmd);
- cmdline = utils_str_replace(cmdline, "%f", doc->file_name);
+ utils_str_replace_all(&cmdline, "%f", doc->file_name);
if (dialogs_show_question(
_("The file \"%s\" will be printed with the following command:\n\n%s"),
Modified: trunk/src/templates.c
===================================================================
--- trunk/src/templates.c 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/templates.c 2009-07-23 16:01:45 UTC (rev 4014)
@@ -692,10 +692,10 @@
else
shortname = g_path_get_basename(fname);
- template = utils_str_replace(template, "{filename}", shortname);
- template = utils_str_replace(template, "{gpl}", templates[GEANY_TEMPLATE_GPL]);
- template = utils_str_replace(template, "{bsd}", templates[GEANY_TEMPLATE_BSD]);
- template = utils_str_replace(template, "{datetime}", date);
+ utils_str_replace_all(&template, "{filename}", shortname);
+ utils_str_replace_all(&template, "{gpl}", templates[GEANY_TEMPLATE_GPL]);
+ utils_str_replace_all(&template, "{bsd}", templates[GEANY_TEMPLATE_BSD]);
+ utils_str_replace_all(&template, "{datetime}", date);
result = make_comment_block(template, ft_id, 8);
@@ -724,7 +724,7 @@
file_header = templates_get_template_fileheader(ft->id, NULL); /* file template only used for new files */
ft_template = get_file_template(ft);
- ft_template = utils_str_replace(ft_template, "{fileheader}", file_header);
+ utils_str_replace_all(&ft_template, "{fileheader}", file_header);
g_free(file_header);
return ft_template;
}
@@ -743,9 +743,9 @@
gchar *datetime = utils_get_date_time(template_prefs.datetime_format, NULL);
gchar *result;
- template = utils_str_replace(template, "{date}", date);
- template = utils_str_replace(template, "{datetime}", datetime);
- template = utils_str_replace(template, "{functionname}", (func_name) ? func_name : "");
+ utils_str_replace_all(&template, "{date}", date);
+ utils_str_replace_all(&template, "{datetime}", datetime);
+ utils_str_replace_all(&template, "{functionname}", (func_name) ? func_name : "");
result = make_comment_block(template, filetype_idx, 3);
@@ -760,8 +760,9 @@
{
gchar *date = utils_get_date_time(template_prefs.datetime_format, NULL);
gchar *result = g_strdup(templates[GEANY_TEMPLATE_CHANGELOG]);
- result = utils_str_replace(result, "{date}", date);
+ utils_str_replace_all(&result, "{date}", date);
+
g_free(date);
return result;
}
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/utils.c 2009-07-23 16:01:45 UTC (rev 4014)
@@ -601,23 +601,23 @@
/* Replaces all occurrences of needle in haystack with replacement.
- * Warning: haystack will be freed.
- * New code should use utils_string_replace_all() instead (freeing arguments
- * is unusual behaviour).
+ * Warning: *haystack must be a heap address; it may be freed and reassigned.
+ * Note: utils_string_replace_all() will always be faster when @a replacement is longer
+ * than @a needle.
* All strings have to be NULL-terminated.
* See utils_string_replace_all() for details. */
-gchar *utils_str_replace(gchar *haystack, const gchar *needle, const gchar *replacement)
+void utils_str_replace_all(gchar **haystack, const gchar *needle, const gchar *replacement)
{
GString *str;
- g_return_val_if_fail(haystack != NULL, NULL);
+ g_return_if_fail(*haystack != NULL);
- str = g_string_new(haystack);
+ str = g_string_new(*haystack);
- g_free(haystack);
+ g_free(*haystack);
utils_string_replace_all(str, needle, replacement);
- return g_string_free(str, FALSE);
+ *haystack = g_string_free(str, FALSE);
}
Modified: trunk/src/utils.h
===================================================================
--- trunk/src/utils.h 2009-07-23 14:39:03 UTC (rev 4013)
+++ trunk/src/utils.h 2009-07-23 16:01:45 UTC (rev 4014)
@@ -121,7 +121,7 @@
guint utils_string_replace_first(GString *haystack, const gchar *needle, const gchar *replace);
-gchar *utils_str_replace(gchar *haystack, const gchar *needle, const gchar *replacement);
+void utils_str_replace_all(gchar **haystack, const gchar *needle, const gchar *replacement);
gint utils_strpos(const gchar* haystack, const gchar *needle);
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