From 67a9018fe5ce73abe881c33e5fe0b77287649342 Mon Sep 17 00:00:00 2001 From: Michael Ventnor Date: Thu, 27 Nov 2008 20:09:50 -0800 Subject: [PATCH] Bug 136941 - Filters from filepicker.properties should should have case insensitive test r+sr=roc a1.9.1=beltzner --- widget/src/gtk2/nsFilePicker.cpp | 29 ++++++++++++++++++++++++++++- 1 file changed, 28 insertions(+), 1 deletion(-) diff --git a/widget/src/gtk2/nsFilePicker.cpp b/widget/src/gtk2/nsFilePicker.cpp index 1118ecb96cb..1ef0dc8ac81 100644 --- a/widget/src/gtk2/nsFilePicker.cpp +++ b/widget/src/gtk2/nsFilePicker.cpp @@ -320,6 +320,32 @@ UpdateFilePreviewWidget(GtkFileChooser *file_chooser, _gtk_file_chooser_set_preview_widget_active(file_chooser, TRUE); } +static nsCAutoString +MakeCaseInsensitiveShellGlob(const char* aPattern) { + // aPattern is UTF8 + nsCAutoString result; + unsigned int len = strlen(aPattern); + + for (unsigned int i = 0; i < len; i++) { + if (!g_ascii_isalpha(aPattern[i])) { + // non-ASCII characters will also trigger this path, so unicode + // is safely handled albeit case-sensitively + result.Append(aPattern[i]); + continue; + } + + // add the lowercase and uppercase version of a character to a bracket + // match, so it matches either the lowercase or uppercase char. + result.Append('['); + result.Append(g_ascii_tolower(aPattern[i])); + result.Append(g_ascii_toupper(aPattern[i])); + result.Append(']'); + + } + + return result; +} + NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker) nsFilePicker::nsFilePicker() @@ -628,7 +654,8 @@ nsFilePicker::Show(PRInt16 *aReturn) GtkFileFilter *filter = _gtk_file_filter_new (); for (int j = 0; patterns[j] != NULL; ++j) { - _gtk_file_filter_add_pattern (filter, g_strstrip (patterns[j])); + nsCAutoString caseInsensitiveFilter = MakeCaseInsensitiveShellGlob(g_strstrip(patterns[j])); + _gtk_file_filter_add_pattern (filter, caseInsensitiveFilter.get()); } g_strfreev(patterns);