Kaydet (Commit) 8b09a293 authored tarafından Enrico Tröger's avatar Enrico Tröger

Improved replacing escape sequences in Find and Replace dialog (thanks to Stefan Oltmanns).


git-svn-id: https://geany.svn.sourceforge.net/svnroot/geany/trunk@586 ea778897-0a13-0410-b9d1-a72fbfd435f5
üst c6c0cb81
......@@ -3,6 +3,9 @@
* src/highlighting.c, data/filetypes.common:
Highlighting of current line can be disabled.
* geany.glade, src/interface.c: Fixed typo.
* src/utils.c, src/callbacks.c, src/dialogs.c:
Improved replacing escape sequences in Find and Replace dialog
(thanks to Stefan Oltmanns).
2006-07-18 Nick Treleaven <nick.treleaven@btinternet.com>
......
......@@ -7,8 +7,8 @@ Testers and contributors:
--------------------------
These people have contributed to Geany by testing the software,
reporting problems, sending patches and making useful suggestions.
Frank Lanitz <frank@partysoke.de>
Christoph Berg <Christoph.Berg@kpm-sport.de>
Frank Lanitz <frank@partysoke.de> - heavy testing
Christoph Berg <Christoph.Berg@kpm-sport.de> - testing and patch for filetype D
Nick Treleaven <nick.treleaven@btinternet.com> - many patches
Saleem Abdulrasool <compnerd@gentoo.org> - vte autoconf patch
Marko Peric <cragwolf@gmail.com>
......@@ -17,7 +17,7 @@ Colossus <colossus73@gmail.com>
Kristoffer A. Tjernås <kt@nupi.no>
Tamim <amitamim@gmail.com>
Kevin Ellwood <kellwood@ameritech.net>
Stefan Oltmanns <stefan.oltmanns@abi2006.gymnasium-achim.de> - escape sequences patch
Translators:
----------------------------------
......
......@@ -1864,18 +1864,13 @@ on_find_dialog_response (GtkDialog *dialog,
g_free(app->search_text);
app->search_text = g_strdup(gtk_entry_get_text(GTK_ENTRY(gtk_bin_get_child(GTK_BIN(user_data)))));
if (strlen(app->search_text) == 0)
if (strlen(app->search_text) == 0 ||
(search_replace_escape && ! utils_str_replace_escape(app->search_text)))
{
utils_beep();
gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->find_dialog, "entry"))->child));
return;
}
else if (search_replace_escape)
{
app->search_text = utils_str_replace(app->search_text, "\\n", "\n");
app->search_text = utils_str_replace(app->search_text, "\\r", "\r");
app->search_text = utils_str_replace(app->search_text, "\\t", "\t");
}
gtk_widget_hide(app->find_dialog);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(user_data), app->search_text);
......@@ -1952,18 +1947,15 @@ on_replace_dialog_response (GtkDialog *dialog,
return;
}
gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_find), find);
gtk_combo_box_prepend_text(GTK_COMBO_BOX(entry_replace), replace);
if (search_replace_escape_re)
if (search_replace_escape_re &&
(! utils_str_replace_escape(find) || ! utils_str_replace_escape(replace)))
{
find = utils_str_replace(find, "\\n", "\n");
find = utils_str_replace(find, "\\r", "\r");
find = utils_str_replace(find, "\\t", "\t");
replace = utils_str_replace(replace, "\\n", "\n");
replace = utils_str_replace(replace, "\\r", "\r");
replace = utils_str_replace(replace, "\\t", "\t");
utils_beep();
gtk_widget_grab_focus(GTK_WIDGET(GTK_BIN(lookup_widget(app->replace_dialog, "entry_find"))->child));
return;
}
search_flags_re = (fl1 ? SCFIND_MATCHCASE : 0) |
......
......@@ -865,7 +865,8 @@ void dialogs_show_find(void)
gtk_widget_ref(checkbox6), (GDestroyNotify)gtk_widget_unref);
gtk_button_set_focus_on_click(GTK_BUTTON(checkbox6), FALSE);
gtk_tooltips_set_tip(tooltips, checkbox6,
_("Replace \\t, \\n and \\r with the corresponding control characters."), NULL);
_("Replace \\\\, \\t, \\n, \\r and \\uXXXX (Unicode chararacters) with the "
"corresponding control characters."), NULL);
checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards"));
g_object_set_data_full(G_OBJECT(app->find_dialog), "check_back",
......@@ -996,7 +997,8 @@ void dialogs_show_replace(void)
gtk_widget_ref(checkbox7), (GDestroyNotify)gtk_widget_unref);
gtk_button_set_focus_on_click(GTK_BUTTON(checkbox7), FALSE);
gtk_tooltips_set_tip(tooltips, checkbox7,
_("Replace \\t, \\n and \\r with the corresponding control characters."), NULL);
_("Replace \\\\, \\t, \\n, \\r and \\uXXXX (Unicode chararacters) with the "
"corresponding control characters."), NULL);
checkbox4 = gtk_check_button_new_with_mnemonic(_("_Search backwards"));
g_object_set_data_full(G_OBJECT(app->replace_dialog), "check_back",
......
......@@ -2428,3 +2428,134 @@ gchar **utils_read_file_in_array(const gchar *filename)
return result;
}
/* Contributed by Stefan Oltmanns, thanks.
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts */
gboolean utils_str_replace_escape(gchar *string)
{
gint i, j;
guint unicodechar;
j = 0;
for (i = 0; i < strlen(string); i++)
{
if (string[i]=='\\')
{
if (i++ >= strlen(string))
{
return FALSE;
}
switch (string[i])
{
case '\\':
string[j] = '\\';
break;
case 'n':
string[j] = '\n';
break;
case 'r':
string[j] = '\r';
break;
case 't':
string[j] = '\t';
break;
#if 0
case 'x': // Warning: May produce illegal utf-8 string!
i += 2;
if (i >= strlen(string))
{
return FALSE;
}
if (isdigit(string[i-1])) string[j] = string[i-1]-48;
else if (isxdigit(string[i-1])) string[j] = tolower(string[i-1])-87;
else return FALSE;
string[j] <<= 4;
if (isdigit(string[i])) string[j] |= string[i]-48;
else if (isxdigit(string[i])) string[j] |= tolower(string[i])-87;
else return FALSE;
break;
#endif
case 'u':
i += 2;
if (i >= strlen(string))
{
return FALSE;
}
if (isdigit(string[i-1])) unicodechar = string[i-1]-48;
else if (isxdigit(string[i-1])) unicodechar = tolower(string[i-1])-87;
else return FALSE;
unicodechar <<= 4;
if (isdigit(string[i])) unicodechar |= string[i]-48;
else if (isxdigit(string[i])) unicodechar |= tolower(string[i])-87;
else return FALSE;
if (((i+2) < strlen(string)) && (isdigit(string[i+1]) || isxdigit(string[i+1]))
&& (isdigit(string[i+2]) || isxdigit(string[i+2])))
{
i += 2;
unicodechar <<= 8;
if (isdigit(string[i-1])) unicodechar |= ((string[i-1]-48)<<4);
else unicodechar |= ((tolower(string[i-1])-87) << 4);
if (isdigit(string[i])) unicodechar |= string[i]-48;
else unicodechar |= tolower(string[i])-87;
}
if (((i+2) < strlen(string)) && (isdigit(string[i+1]) || isxdigit(string[i+1]))
&& (isdigit(string[i+2]) || isxdigit(string[i+2])))
{
i += 2;
unicodechar <<= 8;
if (isdigit(string[i-1])) unicodechar |= ((string[i-1]-48) << 4);
else unicodechar |= ((tolower(string[i-1])-87) << 4);
if (isdigit(string[i])) unicodechar |= string[i]-48;
else unicodechar |= tolower(string[i])-87;
}
if(unicodechar < 0x80)
{
string[j] = unicodechar;
}
else if (unicodechar < 0x800)
{
string[j] = (unsigned char) ((unicodechar >> 6)| 0xC0);
j++;
string[j] = (unsigned char) ((unicodechar & 0x3F)| 0x80);
}
else if (unicodechar < 0x10000)
{
string[j] = (unsigned char) ((unicodechar >> 12) | 0xE0);
j++;
string[j] = (unsigned char) (((unicodechar >> 6) & 0x3F) | 0x80);
j++;
string[j] = (unsigned char) ((unicodechar & 0x3F) | 0x80);
}
else if (unicodechar < 0x110000) // more chars are not allowed in unicode
{
string[j] = (unsigned char) ((unicodechar >> 18) | 0xF0);
j++;
string[j] = (unsigned char) (((unicodechar >> 12) & 0x3F) | 0x80);
j++;
string[j] = (unsigned char) (((unicodechar >> 6) & 0x3F) | 0x80);
j++;
string[j] = (unsigned char) ((unicodechar & 0x3F) | 0x80);
}
else
{
return FALSE;
}
break;
default:
return FALSE;
}
}
else
{
string[j] = string[i];
}
j++;
}
while (j < i)
{
string[j] = 0;
j++;
}
return TRUE;
}
......@@ -218,4 +218,8 @@ void utils_update_toolbar_items(void);
gchar **utils_read_file_in_array(const gchar *filename);
/* Contributed by Stefan Oltmanns, thanks.
* Replaces \\, \r, \n, \t and \uXXX by their real counterparts */
gboolean utils_str_replace_escape(gchar *string);
#endif
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment