src/Tables/GridTable.cs
/// <summary>
/// Splits a given content object as needed based on the max width of the cell.
/// </summary>
/// <param name="text">Text to split</param>
/// <param name="width">Width to cap to</param>
/// <returns></returns>
Splits a given content object as needed based on the max width of the cell.
Splits a given content object as needed based on the max width of the cell .
private static string[] SplitIntoWrappedText(string text, int width)
        {
            if (text.Length < width)
            {
                text += new string(' ', width - text.Length);
                return new [] { text };
            }
            if (text.Length == width)
                return new [] { text };
            var lines = new List<string>();
            while (text.Length > width)
            {
                int lp = 0;
                int pos = text.IndexOf(' ');
                while (pos < width)
                {
                    lp = pos;
                    pos = text.IndexOf(' ', pos + 1);
                    if (pos == -1)
                    {
                        lp = width;
                        break;
                    }
                }
                if (lp == 0) lp = width;
                lines.Add(text[..lp]);
                text = text[lp..];
            }
            if (text.Length < width)
            {
                text += new string(' ', width - text.Length);
            }
            lines.Add(text);
            return lines.ToArray();
        }
private static string [ ] SplitIntoWrappedText ( string text , int width ) { if ( text . Length < width ) { text += new string ( ' ' , width - text . Length ) ; return new [ ] { text } ; } if ( text . Length == width ) return new [ ] { text } ; var lines = new List < string > ( ) ; while ( text . Length > width ) { int lp = 0 ; int pos = text . IndexOf ( ' ' ) ; while ( pos < width ) { lp = pos ; pos = text . IndexOf ( ' ' , pos + 1 ) ; if ( pos == - 1 ) { lp = width ; break ; } } if ( lp == 0 ) lp = width ; lines . Add ( text [ .. lp ] ) ; text = text [ lp .. ] ; } if ( text . Length < width ) { text += new string ( ' ' , width - text . Length ) ; } lines . Add ( text ) ; return lines . ToArray ( ) ; }
Splits a given content object as needed based on the max width of the cell.
Splits a given content object as needed based on the max width of the cell .
None
text
string
Text to split
Text to split
width
int
Width to cap to
Width to cap to