-
Notifications
You must be signed in to change notification settings - Fork 267
feat: add regex and case sensitive to FindReplaceMenu
#480
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
Changes from 19 commits
c2fa26a
6b91334
601b961
4bedca4
bba13d2
6e67ced
40845a0
666f63d
e9121b9
2fcbcad
44db679
20bd13a
58e7565
2d0d693
a342d98
9b2b2b0
d7e84a2
77b3f5f
708eac3
4b9bd28
e324d5c
2caa385
e110509
ff06b7d
ab9f7b5
4181f00
addea23
7cab003
7fd4d49
476888a
90368cd
d507155
d1ea4ab
16af1c3
97f067d
21f83fa
ee39de2
4701db3
d35c4e8
0a53503
8c69ea6
ac34ee2
e0f3921
484fd67
4a206b1
44033f2
cf9a2d4
4574659
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 |
|---|---|---|
|
|
@@ -5,20 +5,61 @@ import 'dart:math' as math; | |
| /// `searchMethod(String pattern, String text)`, here `pattern` is the sequence of | ||
| /// characters that are to be searched within the `text`. | ||
| abstract class SearchAlgorithm { | ||
| List<int> searchMethod(String pattern, String text); | ||
| Iterable<Match> searchMethod(Pattern pattern, String text); | ||
| } | ||
|
|
||
| final class BoyerMooreMatch implements Match { | ||
| const BoyerMooreMatch( | ||
| this.pattern, | ||
| this.input, | ||
| this.start, | ||
| ) : end = start + pattern.length; | ||
|
|
||
| @override | ||
| final int start; | ||
| @override | ||
| final String input; | ||
| @override | ||
| final String pattern; | ||
| @override | ||
| final int end; | ||
| @override | ||
| final int groupCount = 0; | ||
|
|
||
| @override | ||
| String operator [](int g) => group(g); | ||
|
|
||
| @override | ||
| String group(int group) { | ||
| if (group != 0) { | ||
| throw RangeError.value(group); | ||
| } | ||
| return pattern; | ||
| } | ||
|
|
||
| @override | ||
| List<String> groups(List<int> groups) => groups.map((e) => group(e)).toList(); | ||
| } | ||
|
|
||
| class BoyerMoore extends SearchAlgorithm { | ||
| //This is a standard algorithm used for searching patterns in long text samples | ||
| //It is more efficient than brute force searching because it is able to skip | ||
| //characters that will never possibly match with required pattern. | ||
| @override | ||
| List<int> searchMethod(String pattern, String text) { | ||
| List<Match> searchMethod(Pattern pattern, String text) { | ||
| if (pattern is String) { | ||
| return _searchMethod(pattern, text); | ||
| } else { | ||
| throw UnimplementedError(); | ||
| } | ||
sun-jiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
|
|
||
| List<Match> _searchMethod(String pattern, String text) { | ||
| int m = pattern.length; | ||
| int n = text.length; | ||
|
|
||
| Map<String, int> badchar = {}; | ||
| List<int> matches = []; | ||
| List<Match> matches = []; | ||
|
|
||
| _badCharHeuristic(pattern, m, badchar); | ||
|
|
||
|
|
@@ -33,7 +74,7 @@ class BoyerMoore extends SearchAlgorithm { | |
|
|
||
| //if pattern is present at current shift, the index will become -1 | ||
| if (j < 0) { | ||
| matches.add(s); | ||
| matches.add(BoyerMooreMatch(pattern, text, s)); | ||
| s += (s + m < n) ? m - (badchar[text[s + m]] ?? -1) : 1; | ||
| } else { | ||
| s += math.max(1, j - (badchar[text[s + j]] ?? -1)); | ||
|
|
@@ -54,3 +95,24 @@ class BoyerMoore extends SearchAlgorithm { | |
| } | ||
| } | ||
| } | ||
|
|
||
| class DartBuiltin extends SearchAlgorithm { | ||
sun-jiao marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| @override | ||
| Iterable<Match> searchMethod(Pattern pattern, String text) { | ||
| return pattern.allMatches(text); | ||
| } | ||
| } | ||
|
|
||
| class Mixture extends SearchAlgorithm { | ||
| SearchAlgorithm boyerMoore = BoyerMoore(); | ||
| SearchAlgorithm builtin = DartBuiltin(); | ||
|
|
||
| @override | ||
| Iterable<Match> searchMethod(Pattern pattern, String text) { | ||
| if (pattern is String) { | ||
|
||
| return boyerMoore.searchMethod(pattern, text); | ||
| } else { | ||
| return builtin.searchMethod(pattern, text); | ||
| } | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.