implement some string functions in c

This commit is contained in:
Yuichi Nishiwaki
2014-02-09 03:10:58 +09:00
parent ca965d088a
commit 668ace7901
2 changed files with 74 additions and 32 deletions
+1 -32
View File
@@ -457,38 +457,7 @@
(define (list->string list)
(apply string list))
(define (string-copy! to at from . opts)
(let ((start (if (pair? opts) (car opts) 0))
(end (if (>= (length opts) 2)
(cadr opts)
(string-length from))))
(do ((i at (+ i 1))
(j start (+ j 1)))
((= j end))
(string-set! to i (string-ref from j)))))
(define (string-copy v . opts)
(let ((start (if (pair? opts) (car opts) 0))
(end (if (>= (length opts) 2)
(cadr opts)
(string-length v))))
(let ((res (make-string (string-length v))))
(string-copy! res 0 v start end)
res)))
(define (string-fill! v fill . opts)
(let ((start (if (pair? opts) (car opts) 0))
(end (if (>= (length opts) 2)
(cadr opts)
(string-length v))))
(do ((i start (+ i 1)))
((= i end)
#f)
(string-set! v i fill))))
(export string string->list list->string
string-copy! string-copy
string-append string-fill!)
(export string string->list list->string)
;;; 6.8. Vector