@@ -416,10 +416,12 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa
416416
417417 for ( int k = 0 ; k < lines . Length ; k ++ )
418418 {
419- if ( lines [ k ] == null || displayCells . Length ( lines [ k ] ) <= firstLineLen )
419+ var currentLine = lines [ k ] ;
420+
421+ if ( currentLine == null || displayCells . Length ( currentLine ) <= firstLineLen )
420422 {
421423 // we do not need to split further, just add
422- retVal . Add ( lines [ k ] ) ;
424+ retVal . Add ( currentLine ) ;
423425 continue ;
424426 }
425427
@@ -432,15 +434,15 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa
432434
433435 int offset = 0 ; // offset into the line we are splitting
434436
435- while ( true )
437+ while ( currentLine . Length > offset )
436438 {
437439 // acquire the current active display line length (it can very from call to call)
438440 int currentDisplayLen = accumulator . ActiveLen ;
439441
440442 // determine if the current tail would fit or not
441443
442444 // for the remaining part of the string, determine its display cell count
443- int currentCellsToFit = displayCells . Length ( lines [ k ] , offset ) ;
445+ int currentCellsToFit = displayCells . Length ( currentLine , offset ) ;
444446
445447 // determine if we fit into the line
446448 int excessCells = currentCellsToFit - currentDisplayLen ;
@@ -449,7 +451,7 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa
449451 {
450452 // we are not at the end of the string, select a sub string
451453 // that would fit in the remaining display length
452- int charactersToAdd = displayCells . GetHeadSplitLength ( lines [ k ] , offset , currentDisplayLen ) ;
454+ int charactersToAdd = displayCells . GetHeadSplitLength ( currentLine , offset , currentDisplayLen ) ;
453455
454456 if ( charactersToAdd <= 0 )
455457 {
@@ -463,7 +465,7 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa
463465 else
464466 {
465467 // of the given length, add it to the accumulator
466- accumulator . AddLine ( lines [ k ] . Substring ( offset , charactersToAdd ) ) ;
468+ accumulator . AddLine ( currentLine . Substring ( offset , charactersToAdd ) ) ;
467469 }
468470
469471 // increase the offset by the # of characters added
@@ -472,7 +474,7 @@ private static StringCollection GenerateLinesWithoutWordWrap(DisplayCells displa
472474 else
473475 {
474476 // we reached the last (partial) line, we add it all
475- accumulator . AddLine ( lines [ k ] . Substring ( offset ) ) ;
477+ accumulator . AddLine ( currentLine . Substring ( offset ) ) ;
476478 break ;
477479 }
478480 }
0 commit comments