Check-in [524150d095]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:improved string-split
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 524150d0958a4005111ef0010888abc193b1c9b0
User & Date: aldo 2016-12-08 00:37:32
Context
2016-12-08
00:38
improved error info form matchable check-in: 3efc59d401 user: aldo tags: trunk
00:37
improved string-split check-in: 524150d095 user: aldo tags: trunk
00:36
added c-eval check-in: 56b242ceac user: aldo tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to thunder-utils.sls.

14
15
16
17
18
19
20
21
22



23

24
25
26

27
28
29
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
;; limitations under the License.

(library (thunder-utils)
	 (export string-split string-replace)
	 (import (scheme) (srfi s14 char-sets))

	 ;; POSSIBLE THAT NOT EXISTS THIS FUNCTION???
					; s is a string , c is a character-set
					; null strings are discarded from result



	 (define (string-split s c)

	   (define res '())
	   (let loop ([l (string->list s)] [t '()])
	     (if (null? l) 

		 (if (null? t) res (append res (list(list->string t))))
		 (if (char-set-contains? c (car l))
		     (begin 
		       (unless (null? t) 

			       (set! res (append res (list (list->string t)))))
		       (loop (cdr l) '()))
		     (loop (cdr l) (append t (list (car l))))))))

	 ;; POSSIBLE THAT THIS NOT EXIST?
	 ;; if x is a character: (eq?  s[i] x) => s[i] = y
	 ;; if x is a list:      (memq s[i] x) => s[i] = y

	 (define (string-replace s x y)
	   (list->string  
	    (let ([cmp (if (list? x) memq eq?)])
	      (map (lambda (z) (if (cmp z x) y z)) (string->list s)))))



);library







|
|
>
>
>
|
>
|
|
|
>
|


<
>


|
|












14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
;; limitations under the License.

(library (thunder-utils)
	 (export string-split string-replace)
	 (import (scheme) (srfi s14 char-sets))

	 ;; POSSIBLE THAT NOT EXISTS THIS FUNCTION???
	 ;; s is a string , c is a character-set
	 ;; null strings are discarded from result by default unless #f is specified as third argument
	 (define string-split
	   (case-lambda
	    [(s c)
	     (string-split s c #t)]
	    [(s c discard-null?)
	     (define res '())
	     (let loop ([l (string->list s)] [t '()])
	       (if (null? l) 
		   (if (and (null? t) discard-null?)
		       res (append res (list (list->string t))))
		 (if (char-set-contains? c (car l))
		     (begin 

		       (unless (and (null? t) discard-null?)
			       (set! res (append res (list (list->string t)))))
		       (loop (cdr l) '()))
		     (loop (cdr l) (append t (list (car l)))))))]))
	    
	 ;; POSSIBLE THAT THIS NOT EXIST?
	 ;; if x is a character: (eq?  s[i] x) => s[i] = y
	 ;; if x is a list:      (memq s[i] x) => s[i] = y

	 (define (string-replace s x y)
	   (list->string  
	    (let ([cmp (if (list? x) memq eq?)])
	      (map (lambda (z) (if (cmp z x) y z)) (string->list s)))))



);library