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 ;
@@ -877,13 +876,7 @@ impl<'c> ExecNoSync<'c> {
877
876
match_start : usize ,
878
877
match_end : usize ,
879
878
) -> Option < ( usize , usize ) > {
880
- // We can't use match_end directly, because we may need to examine one
881
- // "character" after the end of a match for lookahead operators. We
882
- // need to move two characters beyond the end, since some look-around
883
- // operations may falsely assume a premature end of text otherwise.
884
- let e = cmp:: min (
885
- next_utf8 ( text, next_utf8 ( text, match_end) ) , text. len ( ) ) ;
886
- self . captures_nfa ( slots, & text[ ..e] , match_start)
879
+ self . captures_nfa_type_with_end ( MatchNfaType :: Auto , slots, text, match_start, match_end)
887
880
}
888
881
889
882
/// Like find_nfa, but fills in captures.
@@ -905,8 +898,19 @@ impl<'c> ExecNoSync<'c> {
905
898
slots : & mut [ Slot ] ,
906
899
text : & [ u8 ] ,
907
900
start : usize ,
901
+ ) -> Option < ( usize , usize ) > {
902
+ self . captures_nfa_type_with_end ( ty, slots, text, start, text. len ( ) )
903
+ }
904
+
905
+ fn captures_nfa_type_with_end (
906
+ & self ,
907
+ ty : MatchNfaType ,
908
+ slots : & mut [ Slot ] ,
909
+ text : & [ u8 ] ,
910
+ start : usize ,
911
+ end : usize ,
908
912
) -> Option < ( usize , usize ) > {
909
- if self . exec_nfa ( ty, & mut [ false ] , slots, false , text, start) {
913
+ if self . exec_nfa_with_end ( ty, & mut [ false ] , slots, false , text, start, end ) {
910
914
match ( slots[ 0 ] , slots[ 1 ] ) {
911
915
( Some ( s) , Some ( e) ) => Some ( ( s, e) ) ,
912
916
_ => None ,
@@ -917,13 +921,26 @@ impl<'c> ExecNoSync<'c> {
917
921
}
918
922
919
923
fn exec_nfa (
924
+ & self ,
925
+ ty : MatchNfaType ,
926
+ matches : & mut [ bool ] ,
927
+ slots : & mut [ Slot ] ,
928
+ quit_after_match : bool ,
929
+ text : & [ u8 ] ,
930
+ start : usize ,
931
+ ) -> bool {
932
+ self . exec_nfa_with_end ( ty, matches, slots, quit_after_match, text, start, text. len ( ) )
933
+ }
934
+
935
+ fn exec_nfa_with_end (
920
936
& self ,
921
937
mut ty : MatchNfaType ,
922
938
matches : & mut [ bool ] ,
923
939
slots : & mut [ Slot ] ,
924
940
quit_after_match : bool ,
925
941
text : & [ u8 ] ,
926
942
start : usize ,
943
+ end : usize ,
927
944
) -> bool {
928
945
use self :: MatchNfaType :: * ;
929
946
if let Auto = ty {
@@ -935,10 +952,10 @@ impl<'c> ExecNoSync<'c> {
935
952
}
936
953
match ty {
937
954
Auto => unreachable ! ( ) ,
938
- Backtrack => self . exec_backtrack ( matches, slots, text, start) ,
955
+ Backtrack => self . exec_backtrack ( matches, slots, text, start, end ) ,
939
956
PikeVM => {
940
957
self . exec_pikevm (
941
- matches, slots, quit_after_match, text, start)
958
+ matches, slots, quit_after_match, text, start, end )
942
959
}
943
960
}
944
961
}
@@ -951,6 +968,7 @@ impl<'c> ExecNoSync<'c> {
951
968
quit_after_match : bool ,
952
969
text : & [ u8 ] ,
953
970
start : usize ,
971
+ end : usize ,
954
972
) -> bool {
955
973
if self . ro . nfa . uses_bytes ( ) {
956
974
pikevm:: Fsm :: exec (
@@ -960,7 +978,8 @@ impl<'c> ExecNoSync<'c> {
960
978
slots,
961
979
quit_after_match,
962
980
ByteInput :: new ( text, self . ro . nfa . only_utf8 ) ,
963
- start)
981
+ start,
982
+ end)
964
983
} else {
965
984
pikevm:: Fsm :: exec (
966
985
& self . ro . nfa ,
@@ -969,7 +988,8 @@ impl<'c> ExecNoSync<'c> {
969
988
slots,
970
989
quit_after_match,
971
990
CharInput :: new ( text) ,
972
- start)
991
+ start,
992
+ end)
973
993
}
974
994
}
975
995
@@ -980,6 +1000,7 @@ impl<'c> ExecNoSync<'c> {
980
1000
slots : & mut [ Slot ] ,
981
1001
text : & [ u8 ] ,
982
1002
start : usize ,
1003
+ end : usize
983
1004
) -> bool {
984
1005
if self . ro . nfa . uses_bytes ( ) {
985
1006
backtrack:: Bounded :: exec (
@@ -988,15 +1009,15 @@ impl<'c> ExecNoSync<'c> {
988
1009
matches,
989
1010
slots,
990
1011
ByteInput :: new ( text, self . ro . nfa . only_utf8 ) ,
991
- start)
1012
+ start, end )
992
1013
} else {
993
1014
backtrack:: Bounded :: exec (
994
1015
& self . ro . nfa ,
995
1016
self . cache ,
996
1017
matches,
997
1018
slots,
998
1019
CharInput :: new ( text) ,
999
- start)
1020
+ start, end )
1000
1021
}
1001
1022
}
1002
1023
0 commit comments