mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-06 03:50:02 +02:00
GT-3440 fixed bug where finding words in strings wasn't handling tabs
correctly
This commit is contained in:
parent
b487ce7eba
commit
3c2c23d8ce
3 changed files with 22 additions and 2 deletions
|
@ -58,7 +58,9 @@ public class CommentFieldMouseHandler implements FieldMouseHandlerExtension {
|
||||||
}
|
}
|
||||||
|
|
||||||
String clickedWord =
|
String clickedWord =
|
||||||
StringUtilities.findWord(comments[commentRow], column, GoToService.VALID_GOTO_CHARS);
|
StringUtilities.findWord(StringUtilities.convertTabsToSpaces(comments[commentRow]),
|
||||||
|
column, GoToService.VALID_GOTO_CHARS);
|
||||||
|
|
||||||
return checkWord(clickedWord, serviceProvider, sourceNavigatable);
|
return checkWord(clickedWord, serviceProvider, sourceNavigatable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -152,7 +152,7 @@ public class CommentUtils {
|
||||||
AttributedString prototype, int row) {
|
AttributedString prototype, int row) {
|
||||||
|
|
||||||
// tabs are converted here instead of the GUI dialogs now
|
// tabs are converted here instead of the GUI dialogs now
|
||||||
text = StringUtilities.convertTabsToSpaces(text, 8);
|
text = StringUtilities.convertTabsToSpaces(text);
|
||||||
|
|
||||||
int column = 0;
|
int column = 0;
|
||||||
List<Object> parts =
|
List<Object> parts =
|
||||||
|
|
|
@ -83,6 +83,9 @@ public class StringUtilities {
|
||||||
public static final int UNICODE_LE16_BYTE_ORDER_MARK = 0x0____FFFE;
|
public static final int UNICODE_LE16_BYTE_ORDER_MARK = 0x0____FFFE;
|
||||||
public static final int UNICODE_LE32_BYTE_ORDER_MARK = 0xFFFE_0000;
|
public static final int UNICODE_LE32_BYTE_ORDER_MARK = 0xFFFE_0000;
|
||||||
|
|
||||||
|
// This is Java's default rendered size of a tab (in spaces)
|
||||||
|
public static final int DEFAULT_TAB_SIZE = 8;
|
||||||
|
|
||||||
private StringUtilities() {
|
private StringUtilities() {
|
||||||
// utility class; can't create
|
// utility class; can't create
|
||||||
}
|
}
|
||||||
|
@ -439,6 +442,19 @@ public class StringUtilities {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Convert tabs in the given string to spaces using
|
||||||
|
* a default tab width of 8 spaces.
|
||||||
|
*
|
||||||
|
* @param str
|
||||||
|
* string containing tabs
|
||||||
|
* @return string that has spaces for tabs
|
||||||
|
*/
|
||||||
|
public static String convertTabsToSpaces(String str) {
|
||||||
|
return convertTabsToSpaces(str, DEFAULT_TAB_SIZE);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convert tabs in the given string to spaces.
|
* Convert tabs in the given string to spaces.
|
||||||
*
|
*
|
||||||
|
@ -631,7 +647,9 @@ public class StringUtilities {
|
||||||
return location.getWord();
|
return location.getWord();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static WordLocation findWordLocation(String s, int index, char[] charsToAllow) {
|
public static WordLocation findWordLocation(String s, int index, char[] charsToAllow) {
|
||||||
|
|
||||||
int len = s.length();
|
int len = s.length();
|
||||||
if (index < 0 || index >= len) {
|
if (index < 0 || index >= len) {
|
||||||
return WordLocation.empty(s);
|
return WordLocation.empty(s);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue