File tree 2 files changed +40
-10
lines changed
2 files changed +40
-10
lines changed Original file line number Diff line number Diff line change @@ -15,8 +15,6 @@ categories = ["development-tools"]
15
15
[dependencies ]
16
16
nom = " 7.0.0"
17
17
unicode_categories = " 0.1.1"
18
- once_cell = " 1"
19
- regex = " 1.6"
20
18
21
19
[dev-dependencies ]
22
20
criterion = " 0.4"
Original file line number Diff line number Diff line change 1
- use regex:: Regex ;
2
1
use std:: borrow:: Cow ;
3
2
4
3
use crate :: indentation:: Indentation ;
@@ -7,14 +6,47 @@ use crate::params::Params;
7
6
use crate :: tokenizer:: { Token , TokenKind } ;
8
7
use crate :: { FormatOptions , QueryParams } ;
9
8
10
- use once_cell:: sync:: Lazy ;
11
-
12
- static RE : Lazy < Regex > = Lazy :: new ( || Regex :: new ( r"(?i)^(--|/\*)\s*fmt\s*:\s*(off|on)" ) . unwrap ( ) ) ;
13
-
9
+ // -- fmt: off
10
+ // -- fmt: on
14
11
pub ( crate ) fn check_fmt_off ( s : & str ) -> Option < bool > {
15
- RE . captures ( s) ?
16
- . get ( 2 )
17
- . map ( |matched| matched. as_str ( ) . eq_ignore_ascii_case ( "off" ) )
12
+ let mut state = 0 ;
13
+
14
+ const ON : bool = false ;
15
+ const OFF : bool = true ;
16
+
17
+ const NEXT : u8 = 1 ;
18
+ const STAY : u8 = 0 ;
19
+
20
+ // SPACE SPACE SPACE n
21
+ // ┌┐ ┌┐ ┌┐ ┌───────────► ON
22
+ // - - ▼ f m t ▼ : ▼ o │ N
23
+ // 0 ───► 1 ───► 2 ───► 3 ───► 4 ───► 5 ───► 6 ───► 7
24
+ // F M T O │ f f
25
+ // └────► 8 ───► OFF
26
+ // F F
27
+ for c in s. bytes ( ) {
28
+ state += match ( state, c) {
29
+ ( 0 | 1 , b'-' ) => NEXT ,
30
+ ( 2 , b' ' ) => STAY ,
31
+ ( 2 , b'f' | b'F' ) => NEXT ,
32
+ ( 3 , b'm' | b'M' ) => NEXT ,
33
+ ( 4 , b't' | b'T' ) => NEXT ,
34
+ ( 5 , b' ' ) => STAY ,
35
+ ( 5 , b':' ) => NEXT ,
36
+ ( 6 , b' ' ) => STAY ,
37
+ ( 6 , b'o' | b'O' ) => NEXT ,
38
+ ( 7 , b'n' | b'N' ) => {
39
+ return Some ( ON ) ;
40
+ }
41
+ ( 7 , b'f' | b'F' ) => NEXT ,
42
+ ( 8 , b'f' | b'F' ) => {
43
+ return Some ( OFF ) ;
44
+ }
45
+ _ => return None ,
46
+ } ;
47
+ }
48
+
49
+ None
18
50
}
19
51
20
52
pub ( crate ) fn format (
You can’t perform that action at this time.
0 commit comments