Function Kata "Text wrap"
Implement a function to reformat a text. Function signature:
string Wrap(string text, int maxLineLength)
A potentially multi-line text should be wrapped at word boundaries so that a maximum line length is not exceeded, e.g.
Source text (from "Advent" by Loriot):
The night is blue, the stars are twinkling, Snowflakes softly descend.
With a maximum line length of 9, the function would produce this text:
It blues the night, the little stars are twinkling, little snowflakes quietly down descend.
And with a maximum line length of 14 these:
The night is blue night, the little stars are twinkling, little snowflakes
quietly sink.
Words from the source text are combined into lines with a space between them until the maximum line length is reached. If a word no longer fits into a line, it flows into the next line. Words that are longer than the maximum line length remain as the only word in the line (see "Snowflakes" above).
Variant #1
If desired, the wrapped text can also be delivered in justified text. Spaces should then be distributed as evenly as possible in the lines, e.g. with a maximum line length of 22:
The night is blue, the stars are twinkling, snowflakes softly sink down.