Cannot set Unix linefeed as separator
Opened this issue · 0 comments
JanMosigItemis commented
I'd like my tables to always use Unix linefeeds as line separators independently from the platform the code is running.
Observed behavior
So I did:
table.getRenderer().setLineSeparator("\n")
- It does compile and run
- It does not set the separator to
\n
though - The reason seems to be that
de.vandermeer.asciitable.new AT_Renderer() {...}.setLineSeparator(String)
as well asde.vandermeer.asciitable.AT_Context.setLineSeparator(String)
are checking the provided separator. If it is considered blank, it is ignored. However, the used utility methodorg.apache.commons.lang3.StringUtils.isBlank(CharSequence)
internally usesjava.lang.Character.isWhitespace(char)
which considers a\n
to be a whitepsace. Long story short: A linefeed (along with other special chars, see JavaDoc ofjava.lang.Character.isWhitespace(char)
) cannot be set as separator.
Why is this "bad"?
Well I cannot configure my own kind of special separator chars. This means it will use \r\n
on Windows and \n
on Windows which makes unit testing the results brittle. Also: I'd like consistent output on every platform. Windows can also work with linefeeds, no need to force \r\n
Expected behavior
- Take any char as long as it is no space (or multiple spaces)
- OR: Why is there a constraint on the separator char anyway. Taking any char as long as it is not null is fine for me.
Workaround
As a workaround we are currently using our own AT_Renderer instance that does not use this kind of isBlank
check:
AT_Renderer r = new AT_Renderer() {
private String separator = "\n";
private AT_ColumnWidthCalculator cwc = new CWC_FixedWidth().add(40).add(10).add(60);
@Override
public String getLineSeparator() {
return this.separator;
}
@Override
public AT_Renderer setLineSeparator(String separator) {
this.separator = separator;
return this;
}
@Override
public AT_ColumnWidthCalculator getCWC() {
return this.cwc;
}
@Override
public AT_Renderer setCWC(AT_ColumnWidthCalculator cwc) {
this.cwc = cwc;
return this;
}
};
table.setRenderer(r);