Rename utils_str_replace() utils_str_replace_all(), setting a
'gchar **haystack' argument instead of returning a new string. git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@4014 ea778897-0a13-0410-b9d1-a72fbfd435f5
This commit is contained in:
parent
1581d275e0
commit
d563da620c
@ -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>
|
||||
|
||||
12
src/build.c
12
src/build.c
@ -195,8 +195,8 @@ static GPid build_view_tex_file(GeanyDocument *doc, gint mode)
|
||||
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 @@ static GPid build_spawn_cmd(GeanyDocument *doc, const gchar *cmd, const gchar *d
|
||||
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 @@ static gchar *prepare_run_script(GeanyDocument *doc, gchar **vte_cmd_nonscript)
|
||||
/* 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)
|
||||
|
||||
@ -1952,7 +1952,7 @@ on_context_action1_activate (GtkMenuItem *menuitem,
|
||||
/* 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))
|
||||
{
|
||||
|
||||
@ -869,7 +869,7 @@ static void print_external(GeanyDocument *doc)
|
||||
}
|
||||
|
||||
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"),
|
||||
|
||||
@ -692,10 +692,10 @@ gchar *templates_get_template_fileheader(gint filetype_idx, const gchar *fname)
|
||||
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 @@ gchar *templates_get_template_new_file(GeanyFiletype *ft)
|
||||
|
||||
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 *templates_get_template_function(gint filetype_idx, const gchar *func_name
|
||||
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,7 +760,8 @@ gchar *templates_get_template_changelog(void)
|
||||
{
|
||||
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;
|
||||
|
||||
16
src/utils.c
16
src/utils.c
@ -601,23 +601,23 @@ gint utils_is_file_writeable(const gchar *locale_filename)
|
||||
|
||||
|
||||
/* 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -121,7 +121,7 @@ guint utils_string_replace_all(GString *haystack, const gchar *needle, const gch
|
||||
|
||||
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);
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user