source: project/release/5/list-utils/tags/2.3.4/comma-list-utils.scm @ 39571

Last change on this file since 39571 was 39571, checked in by Kon Lovett, 4 months ago

rel 2.3.4

File size: 1.6 KB
Line 
1;;;; comma-list-utils.scm  -*- scheme -*-
2;;;; Kon Lovett, Jan '21
3
4(module comma-list-utils
5
6(;export
7  list->comma-string
8  comma-string->list
9  list-comma-join
10  make-comma-string)
11
12(import scheme
13  utf8
14  (chicken base)
15  (chicken type)
16  (only (chicken string) string-split)
17  (srfi 1)
18  (only utf8-srfi-13 string-null? string-concatenate string-trim-both)
19  (only utf8-srfi-14 char-set:whitespace)
20  (only list-utils list-flatten))
21
22;string-utils
23
24(: string-trim-whitespace-both (string -> string))
25
26(define (string-trim-whitespace-both str)
27  (string-trim-both str char-set:whitespace) )
28
29;;;
30
31(: list->comma-string (list #!optional boolean string -> string))
32(: comma-string->list (string -> list))
33(: list-comma-join (#!rest -> string))
34(: make-comma-string (fixnum #!optional string -> string))
35
36;;
37
38(define not-string-null? (o not string-null?))
39
40;the input list is flattened, so nulls are removed
41;comma : ", " so "a, b"
42;allow-empty? : do not remove string-nulls
43;
44(define (list->comma-string ls #!optional allow-empty? (comma ", "))
45  ;flatten possibly mixed list of string | list
46  (let* (
47    (ls (map ->string (list-flatten ls)))
48    (ls (if allow-empty? ls (filter not-string-null? ls))) )
49    (if (null? ls) ""
50      (string-concatenate (intersperse ls comma)) ) ) )
51
52(define (comma-string->list str #!optional (proc string-trim-whitespace-both))
53  (map! proc (string-split str ",")) )
54
55(define (list-comma-join . rest)
56  (list->comma-string rest) )
57
58(define (make-comma-string len #!optional (str "?"))
59  (list->comma-string (make-list len str)) )
60
61) ;module comma-list-utils
Note: See TracBrowser for help on using the repository browser.