Revision: 586 Author: eht16 Date: 2006-07-19 04:30:59 -0700 (Wed, 19 Jul 2006) ViewCVS: http://svn.sourceforge.net/geany/?rev=586&view=rev
Log Message: ----------- Improved replacing escape sequences in Find and Replace dialog (thanks to Stefan Oltmanns).
Modified Paths: -------------- trunk/ChangeLog trunk/THANKS trunk/src/callbacks.c trunk/src/dialogs.c trunk/src/utils.c trunk/src/utils.h Modified: trunk/ChangeLog =================================================================== --- trunk/ChangeLog 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/ChangeLog 2006-07-19 11:30:59 UTC (rev 586) @@ -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
Modified: trunk/THANKS =================================================================== --- trunk/THANKS 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/THANKS 2006-07-19 11:30:59 UTC (rev 586) @@ -7,8 +7,8 @@ -------------------------- 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,8 +17,8 @@ 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: ---------------------------------- These people have translated Geany to foreign languages.
Modified: trunk/src/callbacks.c =================================================================== --- trunk/src/callbacks.c 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/src/callbacks.c 2006-07-19 11:30:59 UTC (rev 586) @@ -1864,18 +1864,13 @@
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 @@ 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) |
Modified: trunk/src/dialogs.c =================================================================== --- trunk/src/dialogs.c 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/src/dialogs.c 2006-07-19 11:30:59 UTC (rev 586) @@ -865,7 +865,8 @@ 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 @@ 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",
Modified: trunk/src/utils.c =================================================================== --- trunk/src/utils.c 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/src/utils.c 2006-07-19 11:30:59 UTC (rev 586) @@ -2428,3 +2428,134 @@ 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; +} +
Modified: trunk/src/utils.h =================================================================== --- trunk/src/utils.h 2006-07-19 10:55:11 UTC (rev 585) +++ trunk/src/utils.h 2006-07-19 11:30:59 UTC (rev 586) @@ -218,4 +218,8 @@
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
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.