GP-4166 fix unicodescript issue in search for encoded strings dlg

Fix duplicate <any> elements showing up in script list.
This commit is contained in:
dev747368 2023-12-29 20:17:18 +00:00
parent 93adc70757
commit 2f8d273eff
3 changed files with 13 additions and 4 deletions

View File

@ -29,9 +29,9 @@ public class CharacterScriptUtils {
/**
* The {@link UnicodeScript} value that represents the "ANY" choice. This is a bit of a hack
* and re-uses the INHERITED enum value for this purpose.
* and re-uses the enum value for this purpose.
*/
public static final UnicodeScript ANY_SCRIPT_ALIAS = UnicodeScript.INHERITED;
public static final UnicodeScript ANY_SCRIPT_ALIAS = UnicodeScript.UNKNOWN;
/**
* Premade examples of characters from each specified script, using info from

View File

@ -1063,7 +1063,11 @@ public class EncodedStringsDialog extends DialogComponentProvider {
private ComboBoxModel<UnicodeScript> getScriptListModel(EncodedStringsFilterStats stats) {
List<UnicodeScript> scripts = new ArrayList<>(stats.foundScriptCounts.keySet());
Collections.sort(scripts, (us1, us2) -> us1.name().compareTo(us2.name()));
Collections.sort(scripts, (us1, us2) -> {
int us1Count = stats.foundScriptCounts.get(us1);
int us2Count = stats.foundScriptCounts.get(us2);
return Integer.compare(us2Count, us1Count); // descending
});
scripts.add(0, CharacterScriptUtils.ANY_SCRIPT_ALIAS);
return new DefaultComboBoxModel<>(new Vector<>(scripts));

View File

@ -48,7 +48,12 @@ public record StringInfo(
s.codePoints().forEach(codePoint -> {
try {
UnicodeScript script = Character.UnicodeScript.of(codePoint);
scripts.add(script);
if (script == UnicodeScript.UNKNOWN) {
features.add(StringInfoFeature.CODEC_ERROR); // TODO: are we mis-using this enum to signal bad character?
}
else {
scripts.add(script);
}
if (codePoint == StringUtilities.UNICODE_REPLACEMENT) {
features.add(StringInfoFeature.CODEC_ERROR);