source: project/release/5/list-utils/trunk/comma-list-utils.scm @ 39553

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

remove finger-slip

File size: 1.5 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; "a, b", not "a,b"
41;string-nulls & nulls are removed
42;
43(define (list->comma-string ls #!optional allow-empty? (comma ", "))
44  ;flatten possibly mixed list of string | list
45  (let* (
46    (ls (map ->string (list-flatten ls)))
47    (ls (if allow-empty? ls (filter not-string-null? ls))) )
48    (if (null? ls)
49      ""
50      (string-concatenate (intersperse ls comma)) ) ) )
51
52(define (comma-string->list str)
53  (map! string-trim-whitespace-both (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.