@@ -38,7 +38,7 @@ when executed when assertions are disabled.
3838Use llvm::report_fatal_error for increased robustness." ;
3939
4040/// Parser states for `line_is_url`.
41- #[ derive( PartialEq ) ]
41+ #[ derive( Clone , Copy , PartialEq ) ]
4242#[ allow( non_camel_case_types) ]
4343enum LIUState {
4444 EXP_COMMENT_START ,
@@ -56,26 +56,31 @@ enum LIUState {
5656fn line_is_url ( line : & str ) -> bool {
5757 use self :: LIUState :: * ;
5858 let mut state: LIUState = EXP_COMMENT_START ;
59+ let is_url = |w : & str | w. starts_with ( "http://" ) || w. starts_with ( "https://" ) ;
5960
6061 for tok in line. split_whitespace ( ) {
6162 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 , "///" ) |
6465 ( EXP_COMMENT_START , "//!" ) => state = EXP_LINK_LABEL_OR_URL ,
6566
6667 ( EXP_LINK_LABEL_OR_URL , w)
6768 if w. len ( ) >= 4 && w. starts_with ( '[' ) && w. ends_with ( "]:" )
6869 => state = EXP_URL ,
6970
7071 ( EXP_LINK_LABEL_OR_URL , w)
71- if w . starts_with ( "http://" ) || w . starts_with ( "https://" )
72+ if is_url ( w )
7273 => state = EXP_END ,
7374
7475 ( EXP_URL , w)
75- if w . starts_with ( "http://" ) || w . starts_with ( "https://" ) || w. starts_with ( "../" )
76+ if is_url ( w ) || w. starts_with ( "../" )
7677 => state = EXP_END ,
7778
78- ( _, _) => return false ,
79+ ( _, w)
80+ if w. len ( ) > COLS && is_url ( w)
81+ => state = EXP_END ,
82+
83+ ( _, _) => { }
7984 }
8085 }
8186
0 commit comments