@@ -16,7 +16,7 @@ mod error {
1616}
1717
1818use crate :: Entry ;
19- use bstr:: ByteSlice ;
19+ use bstr:: { BStr , ByteSlice } ;
2020pub use error:: Error ;
2121
2222pub struct Lines < ' a > {
@@ -40,11 +40,44 @@ impl<'a> Iterator for Lines<'a> {
4040 for line in self . lines . by_ref ( ) {
4141 self . line_no += 1 ;
4242 match line. first ( ) {
43- None => continue ,
44- Some ( b) if * b == b'#' => continue ,
43+ None => return None ,
44+ Some ( b) if * b == b'#' => return None ,
4545 Some ( _) => { }
4646 }
47+
48+ return parse_line ( line. into ( ) , self . line_no ) . into ( ) ;
4749 }
4850 None
4951 }
5052}
53+
54+ fn parse_line ( line : & BStr , line_number : usize ) -> Result < Entry < ' _ > , Error > {
55+ let ( name1, email1, rest) = parse_name_and_email ( line, line_number) ?;
56+ let ( name2, email2, rest) = parse_name_and_email ( rest, line_number) ?;
57+ if !rest. trim ( ) . is_empty ( ) {
58+ return Err ( Error :: UnconsumedInput {
59+ line_number,
60+ line : line. into ( ) ,
61+ } ) ;
62+ }
63+ Ok ( match ( name1, email1, name2, email2) {
64+ ( Some ( proper_name) , Some ( commit_email) , None , None ) => Entry :: change_name_by_email ( proper_name, commit_email) ,
65+ ( None , Some ( proper_email) , None , Some ( commit_email) ) => {
66+ Entry :: change_email_by_email ( proper_email, commit_email)
67+ }
68+ ( Some ( proper_name) , Some ( proper_email) , None , Some ( commit_email) ) => {
69+ Entry :: change_name_and_email_by_email ( proper_name, proper_email, commit_email)
70+ }
71+ ( Some ( proper_name) , Some ( proper_email) , Some ( commit_name) , Some ( commit_email) ) => {
72+ Entry :: change_name_and_email_by_name_and_email ( proper_name, proper_email, commit_name, commit_email)
73+ }
74+ _ => todo ! ( ) ,
75+ } )
76+ }
77+
78+ fn parse_name_and_email (
79+ line : & BStr ,
80+ line_number : usize ,
81+ ) -> Result < ( Option < & ' _ BStr > , Option < & ' _ BStr > , & ' _ BStr ) , Error > {
82+ todo ! ( )
83+ }
0 commit comments