@@ -38,7 +38,7 @@ when executed when assertions are disabled.
38
38
Use llvm::report_fatal_error for increased robustness." ;
39
39
40
40
/// Parser states for `line_is_url`.
41
- #[ derive( PartialEq ) ]
41
+ #[ derive( Clone , Copy , PartialEq ) ]
42
42
#[ allow( non_camel_case_types) ]
43
43
enum LIUState {
44
44
EXP_COMMENT_START ,
@@ -56,26 +56,31 @@ enum LIUState {
56
56
fn line_is_url ( line : & str ) -> bool {
57
57
use self :: LIUState :: * ;
58
58
let mut state: LIUState = EXP_COMMENT_START ;
59
+ let is_url = |w : & str | w. starts_with ( "http://" ) || w. starts_with ( "https://" ) ;
59
60
60
61
for tok in line. split_whitespace ( ) {
61
62
match ( state, tok) {
62
- ( EXP_COMMENT_START , "//" ) => state = EXP_LINK_LABEL_OR_URL ,
63
- ( EXP_COMMENT_START , "///" ) => state = EXP_LINK_LABEL_OR_URL ,
63
+ ( EXP_COMMENT_START , "//" ) |
64
+ ( EXP_COMMENT_START , "///" ) |
64
65
( EXP_COMMENT_START , "//!" ) => state = EXP_LINK_LABEL_OR_URL ,
65
66
66
67
( EXP_LINK_LABEL_OR_URL , w)
67
68
if w. len ( ) >= 4 && w. starts_with ( '[' ) && w. ends_with ( "]:" )
68
69
=> state = EXP_URL ,
69
70
70
71
( EXP_LINK_LABEL_OR_URL , w)
71
- if w . starts_with ( "http://" ) || w . starts_with ( "https://" )
72
+ if is_url ( w )
72
73
=> state = EXP_END ,
73
74
74
75
( EXP_URL , w)
75
- if w . starts_with ( "http://" ) || w . starts_with ( "https://" ) || w. starts_with ( "../" )
76
+ if is_url ( w ) || w. starts_with ( "../" )
76
77
=> state = EXP_END ,
77
78
78
- ( _, _) => return false ,
79
+ ( _, w)
80
+ if w. len ( ) > COLS && is_url ( w)
81
+ => state = EXP_END ,
82
+
83
+ ( _, _) => { }
79
84
}
80
85
}
81
86
0 commit comments