mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-09-28 17:11:11 -09:00
GP-3847 change string labels to use translated value if present
If label contains non-latin characters that were elided, add a summary of the alphabets/scripts that the non-latin characters were from (eg. s_SCRIPT1_SCRIPT2#normal_latin_chars_0090210)
This commit is contained in:
@@ -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) {
|
||||||
buffer.append('_');
|
if (!buffer.isEmpty()) {
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user