[geany/geany-plugins] ac7208: Addons: Trying to clean up some variable mess on xmltagging
Frank Lanitz
git-noreply at xxxxx
Wed Nov 6 15:36:43 UTC 2013
Branch: refs/heads/master
Author: Frank Lanitz <frank at frank.uvena.de>
Committer: Frank Lanitz <frank at frank.uvena.de>
Date: Wed, 06 Nov 2013 15:36:43 UTC
Commit: ac7208c3a977ad57dcc24a3cecbe1ff999ed0fe4
https://github.com/geany/geany-plugins/commit/ac7208c3a977ad57dcc24a3cecbe1ff999ed0fe4
Log Message:
-----------
Addons: Trying to clean up some variable mess on xmltagging
Modified Paths:
--------------
addons/src/ao_xmltagging.c
Modified: addons/src/ao_xmltagging.c
28 files changed, 14 insertions(+), 14 deletions(-)
===================================================================
@@ -44,8 +44,6 @@ void ao_xmltagging(void)
if (sci_has_selection(doc->editor->sci) == TRUE)
{
- gchar *selection = NULL;
- gchar *replacement = NULL;
GtkWidget *dialog = NULL;
GtkWidget *vbox = NULL;
GtkWidget *hbox = NULL;
@@ -84,38 +82,40 @@ void ao_xmltagging(void)
if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_ACCEPT)
{
- gchar *tag = NULL;
+ GString *tag = NULL;
+ gchar *selection = NULL;
+ gchar *replacement = NULL;
+ /* Getting the selection and setting the undo flag */
selection = sci_get_selection_contents(doc->editor->sci);
sci_start_undo_action(doc->editor->sci);
- tag = g_strdup(gtk_entry_get_text(GTK_ENTRY(textbox)));
- if (NZV(tag))
+ /* Getting the tag */
+ tag = g_string_new(gtk_entry_get_text(GTK_ENTRY(textbox)));
+
+ if (tag->len > 0)
{
gsize end = 0;
- GString *tmp = NULL;
gchar *end_tag;
/* First we check for %s and replace it with selection*/
- tmp = g_string_new(tag);
- utils_string_replace_all(tmp, "%s", selection);
- tag = g_string_free(tmp, FALSE);
+ utils_string_replace_all(tag, "%s", selection);
/* We try to find a space inside the inserted tag as we
* only need to close the tag with part until first space.
* */
- while (!g_ascii_isspace(tag[end]) && tag[end] != '\0')
+ while (!g_ascii_isspace(tag->str[end]) && end < tag->len)
end++;
if (end > 0)
{
- end_tag = g_strndup(tag, end);
+ end_tag = g_strndup(tag->str, end);
}
else
{
- end_tag = tag;
+ end_tag = tag->str;
}
- replacement = g_strconcat("<", tag, ">",
+ replacement = g_strconcat("<", tag->str, ">",
selection, "</", end_tag, ">", NULL);
g_free(end_tag);
}
@@ -124,7 +124,7 @@ void ao_xmltagging(void)
sci_end_undo_action(doc->editor->sci);
g_free(selection);
g_free(replacement);
- g_free(tag);
+ g_string_free(tag, TRUE);
}
gtk_widget_destroy(dialog);
}
--------------
This E-Mail was brought to you by github_commit_mail.py (Source: https://github.com/geany/infrastructure).
More information about the Plugins-Commits
mailing list