@@ -561,10 +561,32 @@ Controller.prototype = {
561561 }
562562 } ,
563563
564+ splitLines : function ( input ) {
565+ var lines = [ ] ,
566+ lineParts = input . split ( / ^ ( \s * \d + ) / m) , // get numbers starting at the beginning of a line
567+ i , number , content ;
568+
569+ if ( lineParts [ 0 ] === "" ) {
570+ lineParts . shift ( ) ; // remove first empty item
571+ }
572+
573+ for ( i = 0 ; i < lineParts . length ; i += 2 ) {
574+ number = lineParts [ i ] ;
575+ content = lineParts [ i + 1 ] ;
576+
577+ if ( content . endsWith ( "\n" ) ) {
578+ content = content . substring ( 0 , content . length - 1 ) ;
579+ }
580+ lines . push ( number + content ) ;
581+ }
582+
583+ return lines ;
584+ } ,
585+
564586 // merge two scripts with sorted line numbers, lines from script2 overwrite lines from script1
565587 mergeScripts : function ( sScript1 , sScript2 ) {
566- var aLines1 = sScript1 . trimEnd ( ) . split ( "\n" ) ,
567- aLines2 = sScript2 . trimEnd ( ) . split ( "\n" ) ,
588+ var aLines1 = this . splitLines ( sScript1 . trimEnd ( ) ) ,
589+ aLines2 = this . splitLines ( sScript2 . trimEnd ( ) ) ,
568590 aResult = [ ] ,
569591 iLine1 , sLine2 , iLine2 , sResult ;
570592
@@ -599,7 +621,7 @@ Controller.prototype = {
599621
600622 // get line range from a script with sorted line numbers
601623 fnGetLinesInRange : function ( sScript , iFirstLine , iLastLine ) {
602- var aLines = sScript ? sScript . split ( "\n" ) : [ ] ;
624+ var aLines = sScript ? this . splitLines ( sScript ) : [ ] ;
603625
604626 while ( aLines . length && parseInt ( aLines [ 0 ] , 10 ) < iFirstLine ) {
605627 aLines . shift ( ) ;
0 commit comments