10
10
11
11
use std:: cell:: RefCell ;
12
12
use std:: collections:: HashMap ;
13
- use std:: cmp;
14
13
use std:: sync:: Arc ;
15
14
16
15
use thread_local:: CachedThreadLocal ;
@@ -557,7 +556,7 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
557
556
match self . ro . match_type {
558
557
MatchType :: Literal ( ty) => {
559
558
self . find_literals ( ty, text, start) . and_then ( |( s, e) | {
560
- self . captures_nfa_with_match ( slots, text, s, e)
559
+ self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, s, e)
561
560
} )
562
561
}
563
562
MatchType :: Dfa => {
@@ -566,7 +565,7 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
566
565
} else {
567
566
match self . find_dfa_forward ( text, start) {
568
567
dfa:: Result :: Match ( ( s, e) ) => {
569
- self . captures_nfa_with_match ( slots, text, s, e)
568
+ self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, s, e)
570
569
}
571
570
dfa:: Result :: NoMatch ( _) => None ,
572
571
dfa:: Result :: Quit => self . captures_nfa ( slots, text, start) ,
@@ -576,7 +575,7 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
576
575
MatchType :: DfaAnchoredReverse => {
577
576
match self . find_dfa_anchored_reverse ( text, start) {
578
577
dfa:: Result :: Match ( ( s, e) ) => {
579
- self . captures_nfa_with_match ( slots, text, s, e)
578
+ self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, s, e)
580
579
}
581
580
dfa:: Result :: NoMatch ( _) => None ,
582
581
dfa:: Result :: Quit => self . captures_nfa ( slots, text, start) ,
@@ -585,14 +584,14 @@ impl<'c> RegularExpression for ExecNoSync<'c> {
585
584
MatchType :: DfaSuffix => {
586
585
match self . find_dfa_reverse_suffix ( text, start) {
587
586
dfa:: Result :: Match ( ( s, e) ) => {
588
- self . captures_nfa_with_match ( slots, text, s, e)
587
+ self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, s, e)
589
588
}
590
589
dfa:: Result :: NoMatch ( _) => None ,
591
590
dfa:: Result :: Quit => self . captures_nfa ( slots, text, start) ,
592
591
}
593
592
}
594
593
MatchType :: Nfa ( ty) => {
595
- self . captures_nfa_type ( ty, slots, text, start)
594
+ self . captures_nfa_type ( ty, slots, text, start, text . len ( ) )
596
595
}
597
596
MatchType :: Nothing => None ,
598
597
MatchType :: DfaMany => {
@@ -830,7 +829,7 @@ impl<'c> ExecNoSync<'c> {
830
829
text : & [ u8 ] ,
831
830
start : usize ,
832
831
) -> bool {
833
- self . exec_nfa ( ty, & mut [ false ] , & mut [ ] , true , text, start)
832
+ self . exec_nfa ( ty, & mut [ false ] , & mut [ ] , true , text, start, text . len ( ) )
834
833
}
835
834
836
835
/// Finds the shortest match using an NFA.
@@ -846,7 +845,7 @@ impl<'c> ExecNoSync<'c> {
846
845
start : usize ,
847
846
) -> Option < usize > {
848
847
let mut slots = [ None , None ] ;
849
- if self . exec_nfa ( ty, & mut [ false ] , & mut slots, true , text, start) {
848
+ if self . exec_nfa ( ty, & mut [ false ] , & mut slots, true , text, start, text . len ( ) ) {
850
849
slots[ 1 ]
851
850
} else {
852
851
None
@@ -861,7 +860,7 @@ impl<'c> ExecNoSync<'c> {
861
860
start : usize ,
862
861
) -> Option < ( usize , usize ) > {
863
862
let mut slots = [ None , None ] ;
864
- if self . exec_nfa ( ty, & mut [ false ] , & mut slots, false , text, start) {
863
+ if self . exec_nfa ( ty, & mut [ false ] , & mut slots, false , text, start, text . len ( ) ) {
865
864
match ( slots[ 0 ] , slots[ 1 ] ) {
866
865
( Some ( s) , Some ( e) ) => Some ( ( s, e) ) ,
867
866
_ => None ,
@@ -871,26 +870,6 @@ impl<'c> ExecNoSync<'c> {
871
870
}
872
871
}
873
872
874
- /// Like find_nfa, but fills in captures and restricts the search space
875
- /// using previously found match information.
876
- ///
877
- /// `slots` should have length equal to `2 * nfa.captures.len()`.
878
- fn captures_nfa_with_match (
879
- & self ,
880
- slots : & mut [ Slot ] ,
881
- text : & [ u8 ] ,
882
- match_start : usize ,
883
- match_end : usize ,
884
- ) -> Option < ( usize , usize ) > {
885
- // We can't use match_end directly, because we may need to examine one
886
- // "character" after the end of a match for lookahead operators. We
887
- // need to move two characters beyond the end, since some look-around
888
- // operations may falsely assume a premature end of text otherwise.
889
- let e = cmp:: min (
890
- next_utf8 ( text, next_utf8 ( text, match_end) ) , text. len ( ) ) ;
891
- self . captures_nfa ( slots, & text[ ..e] , match_start)
892
- }
893
-
894
873
/// Like find_nfa, but fills in captures.
895
874
///
896
875
/// `slots` should have length equal to `2 * nfa.captures.len()`.
@@ -900,7 +879,7 @@ impl<'c> ExecNoSync<'c> {
900
879
text : & [ u8 ] ,
901
880
start : usize ,
902
881
) -> Option < ( usize , usize ) > {
903
- self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, start)
882
+ self . captures_nfa_type ( MatchNfaType :: Auto , slots, text, start, text . len ( ) )
904
883
}
905
884
906
885
/// Like captures_nfa, but allows specification of type of NFA engine.
@@ -910,8 +889,9 @@ impl<'c> ExecNoSync<'c> {
910
889
slots : & mut [ Slot ] ,
911
890
text : & [ u8 ] ,
912
891
start : usize ,
892
+ end : usize ,
913
893
) -> Option < ( usize , usize ) > {
914
- if self . exec_nfa ( ty, & mut [ false ] , slots, false , text, start) {
894
+ if self . exec_nfa ( ty, & mut [ false ] , slots, false , text, start, end ) {
915
895
match ( slots[ 0 ] , slots[ 1 ] ) {
916
896
( Some ( s) , Some ( e) ) => Some ( ( s, e) ) ,
917
897
_ => None ,
@@ -929,6 +909,7 @@ impl<'c> ExecNoSync<'c> {
929
909
quit_after_match : bool ,
930
910
text : & [ u8 ] ,
931
911
start : usize ,
912
+ end : usize ,
932
913
) -> bool {
933
914
use self :: MatchNfaType :: * ;
934
915
if let Auto = ty {
@@ -940,10 +921,10 @@ impl<'c> ExecNoSync<'c> {
940
921
}
941
922
match ty {
942
923
Auto => unreachable ! ( ) ,
943
- Backtrack => self . exec_backtrack ( matches, slots, text, start) ,
924
+ Backtrack => self . exec_backtrack ( matches, slots, text, start, end ) ,
944
925
PikeVM => {
945
926
self . exec_pikevm (
946
- matches, slots, quit_after_match, text, start)
927
+ matches, slots, quit_after_match, text, start, end )
947
928
}
948
929
}
949
930
}
@@ -956,6 +937,7 @@ impl<'c> ExecNoSync<'c> {
956
937
quit_after_match : bool ,
957
938
text : & [ u8 ] ,
958
939
start : usize ,
940
+ end : usize ,
959
941
) -> bool {
960
942
if self . ro . nfa . uses_bytes ( ) {
961
943
pikevm:: Fsm :: exec (
@@ -965,7 +947,8 @@ impl<'c> ExecNoSync<'c> {
965
947
slots,
966
948
quit_after_match,
967
949
ByteInput :: new ( text, self . ro . nfa . only_utf8 ) ,
968
- start)
950
+ start,
951
+ end)
969
952
} else {
970
953
pikevm:: Fsm :: exec (
971
954
& self . ro . nfa ,
@@ -974,7 +957,8 @@ impl<'c> ExecNoSync<'c> {
974
957
slots,
975
958
quit_after_match,
976
959
CharInput :: new ( text) ,
977
- start)
960
+ start,
961
+ end)
978
962
}
979
963
}
980
964
@@ -985,6 +969,7 @@ impl<'c> ExecNoSync<'c> {
985
969
slots : & mut [ Slot ] ,
986
970
text : & [ u8 ] ,
987
971
start : usize ,
972
+ end : usize ,
988
973
) -> bool {
989
974
if self . ro . nfa . uses_bytes ( ) {
990
975
backtrack:: Bounded :: exec (
@@ -993,15 +978,17 @@ impl<'c> ExecNoSync<'c> {
993
978
matches,
994
979
slots,
995
980
ByteInput :: new ( text, self . ro . nfa . only_utf8 ) ,
996
- start)
981
+ start,
982
+ end)
997
983
} else {
998
984
backtrack:: Bounded :: exec (
999
985
& self . ro . nfa ,
1000
986
self . cache ,
1001
987
matches,
1002
988
slots,
1003
989
CharInput :: new ( text) ,
1004
- start)
990
+ start,
991
+ end)
1005
992
}
1006
993
}
1007
994
@@ -1045,11 +1032,12 @@ impl<'c> ExecNoSync<'c> {
1045
1032
& mut [ ] ,
1046
1033
false ,
1047
1034
text,
1048
- start)
1035
+ start,
1036
+ text. len ( ) )
1049
1037
}
1050
1038
}
1051
1039
}
1052
- Nfa ( ty) => self . exec_nfa ( ty, matches, & mut [ ] , false , text, start) ,
1040
+ Nfa ( ty) => self . exec_nfa ( ty, matches, & mut [ ] , false , text, start, text . len ( ) ) ,
1053
1041
Nothing => false ,
1054
1042
}
1055
1043
}
0 commit comments