mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +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.TranslationSettingsDefinition.*;
|
||||
|
||||
import java.lang.Character.UnicodeScript;
|
||||
import java.nio.*;
|
||||
import java.nio.charset.*;
|
||||
import java.util.*;
|
||||
|
@ -212,24 +213,37 @@ public class StringDataInstance {
|
|||
public static String makeStringLabel(String prefixStr, String str,
|
||||
DataTypeDisplayOptions options) {
|
||||
boolean needsUnderscore = false;
|
||||
Set<UnicodeScript> foundScripts = EnumSet.noneOf(UnicodeScript.class);
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
for (int i = 0, strLength = str.length(); i < strLength &&
|
||||
buffer.length() < options.getLabelStringLength();) {
|
||||
int codePoint = str.codePointAt(i);
|
||||
if (StringUtilities.isDisplayable(codePoint) && (codePoint != ' ')) {
|
||||
if (needsUnderscore) {
|
||||
buffer.append('_');
|
||||
if (!buffer.isEmpty()) {
|
||||
buffer.append('_');
|
||||
}
|
||||
needsUnderscore = false;
|
||||
}
|
||||
buffer.appendCodePoint(codePoint);
|
||||
}
|
||||
else {
|
||||
foundScripts.add(UnicodeScript.of(codePoint));
|
||||
needsUnderscore = true;
|
||||
// discard character
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
||||
String str = getStringValue();
|
||||
String str =
|
||||
showTranslation && translatedValue != null ? translatedValue : getStringValue();
|
||||
if (str == null) {
|
||||
return defaultStr;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue