-
Notifications
You must be signed in to change notification settings - Fork 5.3k
feat(gui):improve search and usage dialog #2383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package jadx.gui.search; | ||
|
|
||
| public class MatchingPositions { | ||
| private final String line; | ||
| private int startMath; | ||
| private int endMath; | ||
|
|
||
| private int lineNumber; | ||
|
|
||
| public MatchingPositions(String line) { | ||
| this.line = line; | ||
| } | ||
|
|
||
| public MatchingPositions(String line, int lineNumber, int startMath, int endMath) { | ||
| this.line = line; | ||
| this.lineNumber = lineNumber; | ||
| this.startMath = startMath; | ||
| this.endMath = endMath; | ||
| } | ||
|
|
||
| public MatchingPositions(String line, int startMath, int endMath) { | ||
| this.line = line; | ||
| this.lineNumber = -1; | ||
| this.startMath = startMath; | ||
| this.endMath = endMath; | ||
| } | ||
|
|
||
| public MatchingPositions(int startMath, int endMath) { | ||
| this.line = null; | ||
| this.lineNumber = -1; | ||
| this.startMath = startMath; | ||
| this.endMath = endMath; | ||
| } | ||
|
|
||
| public int getLineNumber() { | ||
| return lineNumber; | ||
| } | ||
|
|
||
| public String getLine() { | ||
| return line; | ||
| } | ||
|
|
||
| public int getEndMath() { | ||
| return endMath; | ||
| } | ||
|
|
||
| public int getStartMath() { | ||
| return startMath; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package jadx.gui.search; | ||
|
|
||
| import java.util.regex.Pattern; | ||
|
|
||
| public class SearchManager { | ||
| /** | ||
| * Generate the good pattern according to the different boolean | ||
| * | ||
| * @param exp the searched expression | ||
| * @param caseSensitive boolean | ||
| * @param wholeWord boolean | ||
| * @param useRegexp boolean | ||
| * @return the pattern | ||
| */ | ||
| public static Pattern generatePattern(String exp, boolean caseSensitive, boolean wholeWord, boolean useRegexp) { | ||
| String word = exp; | ||
| if (word != null && !word.isEmpty()) { | ||
| if (!useRegexp) { | ||
| word = word.replace("\\E", "\\E\\\\E\\Q"); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you please add a comment explaining why this is necessary? |
||
| word = "\\Q" + word + "\\E"; | ||
| if (wholeWord && exp.matches("\\b.*\\b")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is the second condition needed here? |
||
| word = "\\b" + word + "\\b"; | ||
| } | ||
| } | ||
|
|
||
| if (!caseSensitive) { | ||
| word = "(?i)" + word; | ||
| } | ||
|
|
||
| if (useRegexp) { | ||
| word = "(?m)" + word; | ||
| } | ||
|
|
||
| return Pattern.compile(word); | ||
| } else { | ||
| return Pattern.compile(""); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's probably better to use StringBuilder here until you're done processing the string