@@ -561,10 +561,32 @@ Controller.prototype = {
561
561
}
562
562
} ,
563
563
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
+
564
586
// merge two scripts with sorted line numbers, lines from script2 overwrite lines from script1
565
587
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 ( ) ) ,
568
590
aResult = [ ] ,
569
591
iLine1 , sLine2 , iLine2 , sResult ;
570
592
@@ -599,7 +621,7 @@ Controller.prototype = {
599
621
600
622
// get line range from a script with sorted line numbers
601
623
fnGetLinesInRange : function ( sScript , iFirstLine , iLastLine ) {
602
- var aLines = sScript ? sScript . split ( "\n" ) : [ ] ;
624
+ var aLines = sScript ? this . splitLines ( sScript ) : [ ] ;
603
625
604
626
while ( aLines . length && parseInt ( aLines [ 0 ] , 10 ) < iFirstLine ) {
605
627
aLines . shift ( ) ;
0 commit comments