Whitespace behavior

Excessive white spaces in the paragraph text are removed. Those white spaces are additional blanks (two or more), tabulators, and any new line.

The following example shows text being added to a paragraph with excessive white spaces. The first lines add strings with extra blanks (c2, c3, and c4). The next four lines add strings with tabulators (t1, t2, t3, and t4), using the normal tabulator character and the escaped tabulator \t.

Finally, a string with additional line breaks is added. The line breaks for carriage return, line feed, and escaped newline \n are recognized.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
AsciiParagraph ap = new AsciiParagraph();

ap.addText("c2  c2");
ap.addText("c3   c3");
ap.addText("c4    c4");

ap.addText("t1        t1");
ap.addText("t2                t2");
ap.addText("t3                        t3");
ap.addText("t4\t\t\t\tt4");

ap.addText("word followed by " + StringUtils.CR + " followed by" + StringUtils.LF + " followed by \n");

ap.getContext().setWidth(60).setAlignment(TextAlignment.LEFT);
System.out.println(ap.render());

The resulting output has all excessive white spaces removed:

c2 c2 c3 c3 c4 c4 t1 t1 t2 t2 t3 t3 t4 t4 word followed by
followed by followed by

It does not matter how many excessive white spaces are added. The code below uses more excessive white spaces for blanks and tabulators.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
AsciiParagraph ap = new AsciiParagraph();

ap.addText("c2  c2");
ap.addText("c3   c3");
ap.addText("c4    c4");
ap.addText("c5     c5");
ap.addText("c6      c6");
ap.addText("c7       c7");

ap.addText("t2                t2");
ap.addText("t3                        t3");
ap.addText("t4                                t4");
ap.addText("t5                                        t5");
ap.addText("t6                                                t6");
ap.addText("t7                                                        t7");

ap.addText("word followed by " + StringUtils.CR + " followed by" + StringUtils.LF + " followed by \n");

ap.getContext().setWidth(60);
ap.getContext().setAlignment(TextAlignment.LEFT);
System.out.println(ap.render());

All of which will be removed accordingly:

c2 c2 c3 c3 c4 c4 c5 c5 c6 c6 c7 c7 t2 t2 t3 t3 t4 t4 t5 t5
t6 t6 t7 t7 word followed by followed by followed by