mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 10:49:34 +02:00
Merge remote-tracking branch 'origin/GP-3847_dev747368_translated_string_labels'
This commit is contained in:
commit
c63be6d2c3
1 changed files with 18 additions and 3 deletions
|
@ -20,6 +20,7 @@ import static ghidra.program.model.data.RenderUnicodeSettingsDefinition.*;
|
||||||
import static ghidra.program.model.data.StringLayoutEnum.*;
|
import static ghidra.program.model.data.StringLayoutEnum.*;
|
||||||
import static ghidra.program.model.data.TranslationSettingsDefinition.*;
|
import static ghidra.program.model.data.TranslationSettingsDefinition.*;
|
||||||
|
|
||||||
|
import java.lang.Character.UnicodeScript;
|
||||||
import java.nio.*;
|
import java.nio.*;
|
||||||
import java.nio.charset.*;
|
import java.nio.charset.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
@ -212,24 +213,37 @@ public class StringDataInstance {
|
||||||
public static String makeStringLabel(String prefixStr, String str,
|
public static String makeStringLabel(String prefixStr, String str,
|
||||||
DataTypeDisplayOptions options) {
|
DataTypeDisplayOptions options) {
|
||||||
boolean needsUnderscore = false;
|
boolean needsUnderscore = false;
|
||||||
|
Set<UnicodeScript> foundScripts = EnumSet.noneOf(UnicodeScript.class);
|
||||||
StringBuilder buffer = new StringBuilder();
|
StringBuilder buffer = new StringBuilder();
|
||||||
for (int i = 0, strLength = str.length(); i < strLength &&
|
for (int i = 0, strLength = str.length(); i < strLength &&
|
||||||
buffer.length() < options.getLabelStringLength();) {
|
buffer.length() < options.getLabelStringLength();) {
|
||||||
int codePoint = str.codePointAt(i);
|
int codePoint = str.codePointAt(i);
|
||||||
if (StringUtilities.isDisplayable(codePoint) && (codePoint != ' ')) {
|
if (StringUtilities.isDisplayable(codePoint) && (codePoint != ' ')) {
|
||||||
if (needsUnderscore) {
|
if (needsUnderscore) {
|
||||||
|
if (!buffer.isEmpty()) {
|
||||||
buffer.append('_');
|
buffer.append('_');
|
||||||
|
}
|
||||||
needsUnderscore = false;
|
needsUnderscore = false;
|
||||||
}
|
}
|
||||||
buffer.appendCodePoint(codePoint);
|
buffer.appendCodePoint(codePoint);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
foundScripts.add(UnicodeScript.of(codePoint));
|
||||||
needsUnderscore = true;
|
needsUnderscore = true;
|
||||||
// discard character
|
// discard character
|
||||||
}
|
}
|
||||||
i += Character.charCount(codePoint);
|
i += Character.charCount(codePoint);
|
||||||
}
|
}
|
||||||
return prefixStr + buffer.toString();
|
foundScripts.removeAll(Set.of(UnicodeScript.LATIN, UnicodeScript.COMMON));
|
||||||
|
String scriptSummary = "";
|
||||||
|
if (!foundScripts.isEmpty()) {
|
||||||
|
List<String> scriptNames = new ArrayList<>();
|
||||||
|
foundScripts.forEach(script -> scriptNames.add(script.name()));
|
||||||
|
Collections.sort(scriptNames);
|
||||||
|
scriptSummary = String.join("_", scriptNames) + "#";
|
||||||
|
}
|
||||||
|
|
||||||
|
return prefixStr + scriptSummary + buffer.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
@ -948,7 +962,8 @@ public class StringDataInstance {
|
||||||
return abbrevPrefixStr;
|
return abbrevPrefixStr;
|
||||||
}
|
}
|
||||||
|
|
||||||
String str = getStringValue();
|
String str =
|
||||||
|
showTranslation && translatedValue != null ? translatedValue : getStringValue();
|
||||||
if (str == null) {
|
if (str == null) {
|
||||||
return defaultStr;
|
return defaultStr;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue