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.
This commit is contained in:
Timothy Sample 2018-07-18 02:33:08 -04:00
parent da1d561f22
commit a2f5403367
2 changed files with 12 additions and 3 deletions

View File

@ -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

View File

@ -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")))