Skip to content

Commit

Permalink
Don't insert a line break when nothing is processed (#543)
Browse files Browse the repository at this point in the history
Complements a6a7fa8.
  • Loading branch information
dr0i committed Sep 27, 2024
1 parent a6a7fa8 commit 16b9349
Showing 1 changed file with 13 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,18 +90,21 @@ public void setCompression(final String compression) {
@Override
public void process(final T obj) {
assert !closed;
try {
if (firstObject) {
getWriter().write(getHeader());
firstObject = false;
final String objStr = obj.toString();
if (!objStr.isEmpty()) {
try {
if (firstObject) {
getWriter().write(getHeader());
firstObject = false;
}
else {
getWriter().write(getSeparator());
}
getWriter().write(objStr);
}
else {
getWriter().write(getSeparator());
catch (final IOException e) {
throw new MetafactureException(e);
}
getWriter().write(obj.toString());
}
catch (final IOException e) {
throw new MetafactureException(e);
}
}

Expand Down

2 comments on commit 16b9349

@TobiasNx
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

May this also be a problem with print?

@dr0i
Copy link
Member Author

@dr0i dr0i commented on 16b9349 Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is disputable. Many implementations of "print" act like "print and add enter a line breaking" resp. "enter a line breaking and print", compare e.g. bash:

$ echo


$ printf ""

If you find this an issue we should discuss this in an issuer of itself, though.

Please sign in to comment.