@@ -29,16 +29,10 @@ pub fn generate_merge_list<'a>(
2929
3030 last_offset_set. insert ( first_path. clone ( ) , 0 ) ;
3131
32- let line_ending_offset = if is_crlf ( sources. get ( & first_path) . unwrap ( ) ) {
33- 2
34- } else {
35- 1
36- } ;
37-
3832 // stack to keep track of the depth first traversal
3933 let mut stack = VecDeque :: < NodeIndex > :: new ( ) ;
4034
41- create_merge_views ( & mut nodes_iter, & mut merge_list, & mut last_offset_set, graph, sources, & mut line_directives, & mut stack, line_ending_offset ) ;
35+ create_merge_views ( & mut nodes_iter, & mut merge_list, & mut last_offset_set, graph, sources, & mut line_directives, & mut stack) ;
4236
4337 // now we add a view of the remainder of the root file
4438 let offset = * last_offset_set. get ( & first_path) . unwrap ( ) ;
@@ -58,10 +52,6 @@ pub fn generate_merge_list<'a>(
5852 merged
5953}
6054
61- fn is_crlf ( source : & String ) -> bool {
62- source. contains ( "\r \n " )
63- }
64-
6555fn create_merge_views < ' a > (
6656 nodes : & mut Peekable < Iter < ( NodeIndex , Option < NodeIndex > ) > > ,
6757 merge_list : & mut LinkedList < & ' a str > ,
@@ -70,7 +60,6 @@ fn create_merge_views<'a>(
7060 sources : & ' a HashMap < PathBuf , String > ,
7161 line_directives : & mut Vec < String > ,
7262 stack : & mut VecDeque < NodeIndex > ,
73- line_ending_offset : usize ,
7463) {
7564
7665 loop {
@@ -86,7 +75,7 @@ fn create_merge_views<'a>(
8675 let child_path = graph. get_node ( child) . clone ( ) ;
8776
8877 let parent_source = sources. get ( & parent_path) . unwrap ( ) ;
89- let ( char_for_line, char_following_line) = char_offset_for_line ( edge. line , parent_source, line_ending_offset ) ;
78+ let ( char_for_line, char_following_line) = char_offset_for_line ( edge. line , parent_source) ;
9079
9180 let offset = * last_offset_set. insert ( parent_path. clone ( ) , char_following_line) . get_or_insert ( 0 ) ;
9281 merge_list. push_back ( & parent_source[ offset..char_for_line] ) ;
@@ -101,7 +90,7 @@ fn create_merge_views<'a>(
10190 // if ends in \n\n, we want to exclude the last \n for some reason. Ask optilad
10291 let offset = {
10392 match child_source. ends_with ( "\n " ) {
104- true => child_source. len ( ) -line_ending_offset ,
93+ true => child_source. len ( ) -1 ,
10594 false => child_source. len ( ) ,
10695 }
10796 } ;
@@ -117,15 +106,15 @@ fn create_merge_views<'a>(
117106 }
118107
119108 stack. push_back ( parent) ;
120- create_merge_views ( nodes, merge_list, last_offset_set, graph, sources, line_directives, stack, line_ending_offset ) ;
109+ create_merge_views ( nodes, merge_list, last_offset_set, graph, sources, line_directives, stack) ;
121110 stack. pop_back ( ) ;
122111
123112 let offset = * last_offset_set. get ( & child_path) . unwrap ( ) ;
124113 let child_source = sources. get ( & child_path) . unwrap ( ) ;
125114 // this evaluates to false once the file contents have been exhausted aka offset = child_source.len() + 1
126115 let end_offset = {
127116 match child_source. ends_with ( "\n " ) {
128- true => line_ending_offset /* child_source.len()-1 */ ,
117+ true => 1 /* child_source.len()-1 */ ,
129118 false => 0 /* child_source.len() */ ,
130119 }
131120 } ;
@@ -148,7 +137,7 @@ fn create_merge_views<'a>(
148137 // if ends in \n\n, we want to exclude the last \n for some reason. Ask optilad
149138 let offset = {
150139 match child_source. ends_with ( "\n " ) {
151- true => child_source. len ( ) -line_ending_offset ,
140+ true => child_source. len ( ) -1 ,
152141 false => child_source. len ( ) ,
153142 }
154143 } ;
@@ -163,15 +152,15 @@ fn create_merge_views<'a>(
163152
164153// returns the character offset + 1 of the end of line number `line` and the character
165154// offset + 1 for the end of the line after the previous one
166- fn char_offset_for_line ( line_num : usize , source : & str , line_ending_offset : usize ) -> ( usize , usize ) {
155+ fn char_offset_for_line ( line_num : usize , source : & str ) -> ( usize , usize ) {
167156 let mut char_for_line: usize = 0 ;
168157 let mut char_following_line: usize = 0 ;
169158 for ( n, line) in source. lines ( ) . enumerate ( ) {
170159 if n == line_num {
171- char_following_line += line. len ( ) +line_ending_offset ;
160+ char_following_line += line. len ( ) +1 ;
172161 break ;
173162 }
174- char_for_line += line. len ( ) +line_ending_offset ;
163+ char_for_line += line. len ( ) +1 ;
175164 char_following_line = char_for_line;
176165 }
177166 ( char_for_line, char_following_line)
0 commit comments