@@ -21,36 +21,31 @@ pub struct RegExp {
21
21
}
22
22
23
23
impl RegExp {
24
- pub fn new ( pattern : & str , flag_options : Option < & str > ) -> Result < Self , String > {
25
- let source = if let Some ( flag_options) = flag_options {
26
- format ! ( "/{pattern}/{flag_options}" )
27
- } else {
28
- format ! ( "/{pattern}/" )
29
- } ;
30
-
24
+ pub fn new ( pattern : & str , flag_options : & str ) -> Result < Self , String > {
25
+ let source = format ! ( "/{pattern}/{flag_options}" ) ;
31
26
let mut flags = Flags :: default ( ) ;
32
27
let mut flags_unsupported = false ;
33
28
34
- if let Some ( flag_options) = flag_options {
35
- for flag in flag_options. chars ( ) {
36
- #[ allow( clippy:: match_same_arms) ]
37
- match flag {
38
- 'd' => flags_unsupported = true , // indices for substring matches are not supported
39
- 'g' => flags_unsupported = true , // stateful regex is not supported
40
- 'i' => flags. icase = true ,
41
- 'm' => flags. multiline = true ,
42
- 's' => flags. dot_all = true ,
43
- 'u' => flags. unicode = true ,
44
- 'v' => flags. unicode_sets = true ,
45
- 'y' => flags_unsupported = true , // sticky search is not supported
46
- _ => panic ! ( "Unknown flag: {flag:?}" ) ,
47
- }
29
+ for flag in flag_options. chars ( ) {
30
+ #[ allow( clippy:: match_same_arms) ]
31
+ match flag {
32
+ 'd' => flags_unsupported = true , // indices for substring matches are not supported
33
+ 'g' => flags_unsupported = true , // stateful regex is not supported
34
+ 'i' => flags. icase = true ,
35
+ 'm' => flags. multiline = true ,
36
+ 's' => flags. dot_all = true ,
37
+ 'u' => flags. unicode = true ,
38
+ 'v' => flags. unicode_sets = true ,
39
+ 'y' => flags_unsupported = true , // sticky search is not supported
40
+ // Should be caught by parser errors
41
+ _ => panic ! ( "Unknown flag: {flag:?}" ) ,
48
42
}
49
43
}
50
44
51
45
let compiled_regex = {
52
46
let mut ire = backends:: try_parse ( pattern. chars ( ) . map ( u32:: from) , flags)
53
47
. map_err ( |err| err. text ) ?;
48
+
54
49
if !flags. no_opt {
55
50
backends:: optimize ( & mut ire) ;
56
51
}
@@ -314,10 +309,7 @@ impl BinarySerializable for RegExp {
314
309
315
310
fn deserialize < I : Iterator < Item = u8 > > ( iter : & mut I , source_id : SourceId ) -> Self {
316
311
let source = String :: deserialize ( iter, source_id) ;
317
-
318
312
let ( pattern, flags) = source[ 1 ..] . rsplit_once ( '/' ) . unwrap ( ) ;
319
- let flags = if flags. is_empty ( ) { None } else { Some ( flags) } ;
320
-
321
313
Self :: new ( pattern, flags) . unwrap ( )
322
314
}
323
315
}
0 commit comments