GT-3440 fixed bug where finding words in strings wasn't handling tabs

correctly
This commit is contained in:
ghidravore 2020-01-09 13:07:04 -05:00
parent b487ce7eba
commit 3c2c23d8ce
3 changed files with 22 additions and 2 deletions

View file

@ -58,7 +58,9 @@ public class CommentFieldMouseHandler implements FieldMouseHandlerExtension {
}
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);
}

View file

@ -152,7 +152,7 @@ public class CommentUtils {
AttributedString prototype, int row) {
// tabs are converted here instead of the GUI dialogs now
text = StringUtilities.convertTabsToSpaces(text, 8);
text = StringUtilities.convertTabsToSpaces(text);
int column = 0;
List<Object> parts =

View file

@ -83,6 +83,9 @@ public class StringUtilities {
public static final int UNICODE_LE16_BYTE_ORDER_MARK = 0x0____FFFE;
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() {
// utility class; can't create
}
@ -439,6 +442,19 @@ public class StringUtilities {
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.
*
@ -631,7 +647,9 @@ public class StringUtilities {
return location.getWord();
}
public static WordLocation findWordLocation(String s, int index, char[] charsToAllow) {
int len = s.length();
if (index < 0 || index >= len) {
return WordLocation.empty(s);