Patching file extensions to include upper/lower case in filters.

This commit is contained in:
Rob Greene 2018-06-12 21:42:35 -05:00
parent 6915ada616
commit b14b72476e

View File

@ -160,7 +160,7 @@ public class SwtAppleCommander implements Listener {
String[] extensions = new String[fileFilters.length];
for (int i=0; i<fileFilters.length; i++) {
names[i] = fileFilters[i].getNames();
extensions[i] = fileFilters[i].getExtensions();
extensions[i] = makeExtensionCaseInsensitive(fileFilters[i].getExtensions());
}
fileDialog.setFilterNames(names);
fileDialog.setFilterExtensions(extensions);
@ -182,6 +182,25 @@ public class SwtAppleCommander implements Listener {
}
}
}
/**
* A quick change to any letter in the glob to be a regex of both the lower-case
* and upper-case letters. For example, {@code *.dsk} converts to
* {@code *.[dD][sS][kK]}.
*/
protected String makeExtensionCaseInsensitive(String extension) {
StringBuilder sb = new StringBuilder();
for (char ch : extension.toCharArray()) {
if (Character.isLetter(ch)) {
sb.append("[");
sb.append(Character.toLowerCase(ch));
sb.append(Character.toUpperCase(ch));
sb.append("]");
} else {
sb.append(ch);
}
}
return sb.toString();
}
/**
* Displays the unrecognized disk format message.