Skip to content

Commit

Permalink
fix(plc4j/spi): fixed asciibox breaking on CR/LF
Browse files Browse the repository at this point in the history
  • Loading branch information
sruehl committed Jan 27, 2022
1 parent cf8ebfe commit 6fe7535
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class AsciiBox {
private final String data;

protected AsciiBox(String data) {
Objects.requireNonNull(data);
asciiBoxWriter = AsciiBoxWriter.DEFAULT;
this.data = data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collection;
import java.util.LinkedList;
import java.util.List;
import java.util.*;
import java.util.regex.Pattern;

public class AsciiBoxWriter {
Expand Down Expand Up @@ -99,6 +96,9 @@ public AsciiBox boxBox(String name, AsciiBox box, int charWidth) {
* @return boxed data
*/
public AsciiBox boxString(String name, String data, int charWidth) {
Objects.requireNonNull(data);
// Convert dos2unix as that messes with box rendering
data = data.replaceAll("\r\n", "\n");
AsciiBox rawBox = new AsciiBox(data);
int longestLine = rawBox.width();
if (charWidth < longestLine) {
Expand Down

0 comments on commit 6fe7535

Please sign in to comment.