From a2f5403367f3666287698f171979f9905f9f2438 Mon Sep 17 00:00:00 2001 From: Timothy Sample Date: Wed, 18 Jul 2018 02:33:08 -0400 Subject: [PATCH] Fix field splitting on outside spaces * geesh/word.scm (split-fields): Make outside spaces in word-parts count for field splitting. * tests/word.scm: Test this. --- geesh/word.scm | 7 ++++--- tests/word.scm | 8 ++++++++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/geesh/word.scm b/geesh/word.scm index e935a7d..c6b02d2 100644 --- a/geesh/word.scm +++ b/geesh/word.scm @@ -75,12 +75,13 @@ set @var{ifs}." (str (let ((str-parts (string-split str ifs))) (if (every string-null? str-parts) '(wedge) - (infix 'wedge (filter (compose not string-null?) - str-parts))))))) + (filter (lambda (x) + (or (eq? x 'wedge) (not (string-null? x)))) + (infix 'wedge str-parts))))))) (let ((wedged (append-map (cut wedge-apart <> ifs) (normalize-word qword)))) - (list-split wedged 'wedge))) + (filter pair? (list-split wedged 'wedge)))) (define (remove-quotes qword) "Remove quote forms from @var{qword} and concatenate the result into a diff --git a/tests/word.scm b/tests/word.scm index bdc4185..4f24535 100644 --- a/tests/word.scm +++ b/tests/word.scm @@ -60,6 +60,14 @@ the `set' built-in for details on these options.)" '("foo" "bar") (expand-word #f '("foo bar"))) +(test-equal "Splits a word on leading space" + '("foo" "bar") + (expand-word #f '("foo" " bar"))) + +(test-equal "Splits a word on trailing space" + '("foo" "bar") + (expand-word #f '("foo " "bar"))) + (test-equal "Ignores leading spaces" '("foo") (expand-word #f '(" foo")))