@@ -11,6 +11,7 @@ use regex::Regex;
1111use skim:: prelude:: * ;
1212use structopt:: StructOpt ;
1313
14+ const LINE_SPLITTER : char = '=' ;
1415const URL_REGEX : & str = r"(http(s)?://[a-zA-Z0-9_/?+&.=@%#;~:-]+)" ;
1516
1617#[ derive( Debug , StructOpt ) ]
@@ -31,24 +32,49 @@ pub fn main() {
3132 io:: stdin ( ) . read_to_string ( & mut buffer) . unwrap ( ) ;
3233 let lines = buffer. split ( "\n " ) ;
3334
34- let mut matches : HashMap < & str , u8 > = HashMap :: new ( ) ;
35- let mut match_index = 1 ;
36-
35+ let mut split_lines = false ;
36+ let mut split_line_buffer : Vec < & str > = Vec :: new ( ) ;
37+ let mut merged_lines : Vec < String > = Vec :: new ( ) ;
3738 for line in lines {
38- for capture in re. captures_iter ( line) {
39+ if line. len ( ) == 0 {
40+ continue
41+ }
42+
43+ if line. ends_with ( LINE_SPLITTER ) {
44+ let mergable = line. get ( 0 ..line. len ( ) - 1 ) . unwrap_or ( "" ) ;
45+ split_line_buffer. push ( mergable) ;
46+ split_lines = true ;
47+ continue ;
48+ }
49+
50+ if split_lines {
51+ split_lines = false ;
52+ split_line_buffer. push ( line) ;
53+ let merged_line = & split_line_buffer. join ( "" ) ;
54+ merged_lines. push ( merged_line. to_string ( ) ) ;
55+ split_line_buffer = Vec :: new ( ) ;
56+ } else {
57+ merged_lines. push ( line. to_string ( ) ) ;
58+ }
59+ }
60+
61+ let mut matches: HashMap < String , u8 > = HashMap :: new ( ) ;
62+ let mut match_index = 1 ;
63+ for line in merged_lines {
64+ for capture in re. captures_iter ( & line) {
3965 let url_match = capture. get ( 1 ) . unwrap ( ) . as_str ( ) ;
4066 if matches. contains_key ( url_match) {
4167 continue ;
4268 }
43- matches. insert ( url_match, match_index) ;
69+ matches. insert ( url_match. to_string ( ) , match_index) ;
4470 match_index += 1 ;
4571 }
4672 }
4773
4874 let mut ordered_items: Vec < _ > = matches. into_iter ( ) . collect ( ) ;
4975 ordered_items. sort_by ( |a, b| a. 1 . cmp ( & b. 1 ) ) ;
5076
51- let item_list: Vec < _ > = ordered_items. iter ( ) . map ( |item| item. 0 ) . collect ( ) ;
77+ let item_list: Vec < _ > = ordered_items. iter ( ) . map ( |item| item. 0 . as_str ( ) ) . collect ( ) ;
5278 let items = item_list. join ( "\n " ) ;
5379
5480 let item_reader = SkimItemReader :: default ( ) ;
0 commit comments