Bug 136941 - Filters from filepicker.properties should should have case insensitive test

r+sr=roc a1.9.1=beltzner
This commit is contained in:
Michael Ventnor 2008-11-27 20:09:50 -08:00
Родитель 48275ea990
Коммит 67a9018fe5
1 изменённых файлов: 28 добавлений и 1 удалений

Просмотреть файл

@ -320,6 +320,32 @@ UpdateFilePreviewWidget(GtkFileChooser *file_chooser,
_gtk_file_chooser_set_preview_widget_active(file_chooser, TRUE); _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) NS_IMPL_ISUPPORTS1(nsFilePicker, nsIFilePicker)
nsFilePicker::nsFilePicker() nsFilePicker::nsFilePicker()
@ -628,7 +654,8 @@ nsFilePicker::Show(PRInt16 *aReturn)
GtkFileFilter *filter = _gtk_file_filter_new (); GtkFileFilter *filter = _gtk_file_filter_new ();
for (int j = 0; patterns[j] != NULL; ++j) { 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); g_strfreev(patterns);