From 624460132b38ed111c75aa72ca1a32ed68fd140f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Pant=C5=AF=C4=8Dek?= Date: Tue, 28 Mar 2023 22:53:40 +0200 Subject: [PATCH] Handle empty strings in paragraph formatting. --- ansi.scm | 4 ++-- table.scm | 8 ++++++-- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/ansi.scm b/ansi.scm index a72f4b9..6c28ac3 100644 --- a/ansi.scm +++ b/ansi.scm @@ -155,8 +155,8 @@ ;; accordingly. (define (ansi-paragraph-format str width) (let* ((strl (string->list str)) - (first-char (car strl)) - (last-char (car (reverse strl))) + (first-char (if (null? strl) #f (car strl))) + (last-char (if (null? strl) #f (car (reverse strl)))) (first-tab (eq? first-char #\tab)) (last-tab (eq? last-char #\tab))) (let loop ((words (string-split diff --git a/table.scm b/table.scm index 83c6684..6ea52e2 100644 --- a/table.scm +++ b/table.scm @@ -138,8 +138,12 @@ ;; Normalizes cell line to required width and handles leading and ;; trailing tabs to allow for right and center alignment. - (define (table-normalize-cell-line cs w) - (let ((csl (ansi-string-length cs))) + (define (table-normalize-cell-line line w) + (let ((lst (string->list line)) + (first-char (if (null? lst) #f (car lst))) + (last-char (if (null? lst) #f (car (reverse lst)))) + ;; Line without tabs + (len (ansi-string-length line))) (if (< csl w) (string-append cs (string-repeat " " (- w csl))) cs)))