From 77020df0422ce45c4da9b9bacc32bad602b0b1bc Mon Sep 17 00:00:00 2001 From: Veit Heller Date: Fri, 23 Apr 2021 09:35:34 +0200 Subject: [PATCH] fix: fix String.words for multiple spaces (#1205) --- core/Pattern.carp | 2 +- test/string.carp | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/core/Pattern.carp b/core/Pattern.carp index c18e8b96..fe6d0cb4 100644 --- a/core/Pattern.carp +++ b/core/Pattern.carp @@ -144,7 +144,7 @@ list of those characters.") (doc words "splits a string into words.") (defn words [s] - (split-by s &[\tab \space \newline])) + (Array.endo-filter &(fn [s] (not (empty? s))) (split-by s &[\tab \space \newline]))) (doc lines "splits a string into lines.") (defn lines [s] diff --git a/test/string.carp b/test/string.carp index 1a5747e9..0ca339d0 100644 --- a/test/string.carp +++ b/test/string.carp @@ -184,7 +184,11 @@ (assert-equal test &[@"erik" @"sved" @"hej" @"foo"] &(words "erik sved\nhej\tfoo") - "words works correctly") + "words works correctly I") + (assert-equal test + &[@"erik" @"sved" @"hej" @"foo"] + &(words "erik sved\n\nhej\tfoo") + "words works correctly II") (assert-equal test &[@"erik" @"sved" @"hej" @"foo"] &(lines "erik\nsved\nhej\nfoo")