@@ -279,7 +279,10 @@ Tuple<int, string[]> FormatColumn(int column, int height, int upper, int lower,
279279 {
280280 c [ index ++ ] = formatValue ( At ( row , column ) ) ;
281281 }
282- int w = c . Max ( x => x . Length ) ;
282+
283+ int w = height != 0
284+ ? c . Max ( x => x . Length )
285+ : 0 ;
283286 if ( withEllipsis )
284287 {
285288 c [ upper ] = ellipsis ;
@@ -289,6 +292,7 @@ Tuple<int, string[]> FormatColumn(int column, int height, int upper, int lower,
289292
290293 static string FormatStringArrayToString ( string [ , ] array , string columnSeparator , string rowSeparator )
291294 {
295+ const string emptyString = "[empty]" ;
292296 var rows = array . GetLength ( 0 ) ;
293297 var cols = array . GetLength ( 1 ) ;
294298
@@ -302,35 +306,89 @@ static string FormatStringArrayToString(string[,] array, string columnSeparator,
302306 }
303307
304308 var sb = new StringBuilder ( ) ;
305- for ( int i = 0 ; i < rows ; i ++ )
309+ if ( rows > 0 )
306310 {
307- sb . Append ( array [ i , 0 ] . PadLeft ( widths [ 0 ] ) ) ;
308- for ( int j = 1 ; j < cols ; j ++ )
311+ for ( int i = 0 ; i < rows ; i ++ )
309312 {
310- sb . Append ( columnSeparator ) ;
311- sb . Append ( array [ i , j ] . PadLeft ( widths [ j ] ) ) ;
313+ if ( cols > 0 )
314+ {
315+ sb . Append ( array [ i , 0 ] . PadLeft ( widths [ 0 ] ) ) ;
316+ for ( int j = 1 ; j < cols ; j ++ )
317+ {
318+ sb . Append ( columnSeparator ) ;
319+ sb . Append ( array [ i , j ] . PadLeft ( widths [ j ] ) ) ;
320+ }
321+ }
322+ else
323+ {
324+ sb . Append ( emptyString ) ;
325+ }
326+
327+ sb . Append ( rowSeparator ) ;
312328 }
313- sb . Append ( rowSeparator ) ;
314329 }
330+ else
331+ {
332+ if ( cols > 0 )
333+ {
334+ for ( int j = 0 ; j < cols ; j ++ )
335+ {
336+ sb . Append ( emptyString ) ;
337+ if ( j != cols - 1 )
338+ {
339+ sb . Append ( columnSeparator ) ;
340+ }
341+ }
342+ }
343+ else
344+ {
345+ sb . Append ( emptyString ) ;
346+ }
347+ }
348+
315349 return sb . ToString ( ) ;
316350 }
317351
318352 public string ToMatrixString ( int upperRows , int lowerRows , int leftColumns , int rightColumns ,
319353 string horizontalEllipsis , string verticalEllipsis , string diagonalEllipsis ,
320354 string columnSeparator , string rowSeparator , Func < T , string > formatValue )
321355 {
356+ var array = ToMatrixStringArray (
357+ upperRows ,
358+ lowerRows ,
359+ leftColumns ,
360+ rightColumns ,
361+ horizontalEllipsis ,
362+ verticalEllipsis ,
363+ diagonalEllipsis ,
364+ formatValue ) ;
365+
322366 return FormatStringArrayToString (
323- ToMatrixStringArray ( upperRows , lowerRows , leftColumns , rightColumns , horizontalEllipsis , verticalEllipsis , diagonalEllipsis , formatValue ) ,
324- columnSeparator , rowSeparator ) ;
367+ array ,
368+ columnSeparator ,
369+ rowSeparator ) ;
325370 }
326371
327372 public string ToMatrixString ( int upperRows , int lowerRows , int minLeftColumns , int rightColumns , int maxWidth ,
328373 string horizontalEllipsis , string verticalEllipsis , string diagonalEllipsis ,
329374 string columnSeparator , string rowSeparator , Func < T , string > formatValue )
330375 {
376+ var array = ToMatrixStringArray (
377+ upperRows ,
378+ lowerRows ,
379+ minLeftColumns ,
380+ rightColumns ,
381+ maxWidth ,
382+ columnSeparator . Length ,
383+ horizontalEllipsis ,
384+ verticalEllipsis ,
385+ diagonalEllipsis ,
386+ formatValue ) ;
387+
331388 return FormatStringArrayToString (
332- ToMatrixStringArray ( upperRows , lowerRows , minLeftColumns , rightColumns , maxWidth , columnSeparator . Length , horizontalEllipsis , verticalEllipsis , diagonalEllipsis , formatValue ) ,
333- columnSeparator , rowSeparator ) ;
389+ array ,
390+ columnSeparator ,
391+ rowSeparator ) ;
334392 }
335393
336394 /// <summary>
0 commit comments