mirror of
https://github.com/libsdl-org/SDL.git
synced 2026-06-01 23:07:45 +08:00
dialog: Use case-insensitive filter matching on portal dialogs
On most implementations, filter pattern matching is case-sensitive. For case-insensitive matching of a pattern such as '*.png', the pattern *.[pP][nN][gG]' must be used.
This commit is contained in:
@@ -86,10 +86,25 @@ static void DBus_AppendFilter(SDL_DBusContext *dbus, DBusMessageIter *parent, co
|
|||||||
dbus->message_iter_append_basic(&filter_entry, DBUS_TYPE_STRING, &filter.name);
|
dbus->message_iter_append_basic(&filter_entry, DBUS_TYPE_STRING, &filter.name);
|
||||||
dbus->message_iter_open_container(&filter_entry, DBUS_TYPE_ARRAY, "(us)", &filter_array);
|
dbus->message_iter_open_container(&filter_entry, DBUS_TYPE_ARRAY, "(us)", &filter_array);
|
||||||
|
|
||||||
patterns = SDL_strdup(filter.pattern);
|
/* Copy the filter string, converting to a case-insensitive version.
|
||||||
|
* For example, for case-insensitive matching of '*.png', the pattern '*.[pP][nN][gG]' is used.
|
||||||
|
*/
|
||||||
|
const size_t len = SDL_strlen(filter.pattern) + 1;
|
||||||
|
patterns = SDL_malloc(len * 4); // Single characters may be expanded to 4 characters.
|
||||||
if (!patterns) {
|
if (!patterns) {
|
||||||
goto cleanup;
|
goto cleanup;
|
||||||
}
|
}
|
||||||
|
for (size_t i = 0, p = 0; i < len; ++i) {
|
||||||
|
if ((filter.pattern[i] >= 'a' && filter.pattern[i] <= 'z') ||
|
||||||
|
(filter.pattern[i] >= 'A' && filter.pattern[i] <= 'Z')) {
|
||||||
|
patterns[p++] = '[';
|
||||||
|
patterns[p++] = SDL_tolower(filter.pattern[i]);
|
||||||
|
patterns[p++] = SDL_toupper(filter.pattern[i]);
|
||||||
|
patterns[p++] = ']';
|
||||||
|
} else {
|
||||||
|
patterns[p++] = filter.pattern[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pattern = SDL_strtok_r(patterns, ";", &state);
|
pattern = SDL_strtok_r(patterns, ";", &state);
|
||||||
while (pattern) {
|
while (pattern) {
|
||||||
|
|||||||
Reference in New Issue
Block a user