Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #6537: Improved name search for diacritics #6538

Merged
merged 2 commits into from
Feb 15, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.awt.event.KeyEvent;
import java.awt.event.KeyListener;
import java.awt.event.WindowEvent;
import java.text.Normalizer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
Expand Down Expand Up @@ -673,9 +674,9 @@ public boolean include(Entry<? extends MekTableModel, ? extends Integer> entry)

protected boolean matchesTextFilter(MekSummary unit) {
if (!textFilter.getText().isBlank()) {
String text = textFilter.getText().toLowerCase();
String text = stripAccents(textFilter.getText().toLowerCase());
String[] tokens = text.split(" ");
String searchText = unit.getName().toLowerCase() + "###" + unit.getModel().toLowerCase();
String searchText = stripAccents(unit.getName().toLowerCase() + "###" + unit.getModel().toLowerCase());
for (String token : tokens) {
if (!searchText.contains(token)) {
return false;
Expand All @@ -685,6 +686,14 @@ protected boolean matchesTextFilter(MekSummary unit) {
return true;
}

public static String stripAccents(String input) {
if (input == null) {
return null;
}
String normalized = Normalizer.normalize(input, Normalizer.Form.NFD);
return normalized.replaceAll("\\p{M}", "");
}

/**
* @return the selected entity (required for MekHQ/MegaMek overrides)
*/
Expand Down