mes: string-drop: Error on negative droppings.
* module/srfi/srfi-13.mes (string-drop, string-take, string-drop-right): Error on negative droppings. * tests/srfi-13.test ("string-drop"): Test it.
This commit is contained in:
parent
41fe739463
commit
1f216444f6
|
@ -54,14 +54,20 @@
|
|||
(list (list->string (list-head lst (- (length lst) (length rest)))))))))))
|
||||
|
||||
(define (string-take s n)
|
||||
(list->string (list-head (string->list s) n)))
|
||||
(cond ((zero? n) s)
|
||||
((> n 0) (list->string (list-head (string->list s) n)))
|
||||
(else (error "string-take: not supported: n=" n))))
|
||||
|
||||
(define (string-drop s n)
|
||||
(list->string (list-tail (string->list s) n)))
|
||||
(cond ((zero? n) s)
|
||||
((> n 0) (list->string (list-tail (string->list s) n)))
|
||||
(else s (error "string-drop: not supported: (n s)=" (cons n s)))))
|
||||
|
||||
(define (string-drop-right s n)
|
||||
(let ((length (string-length s)))
|
||||
(list->string (list-head (string->list s) (- length n)))))
|
||||
(cond ((zero? n) s)
|
||||
((> n 0) (let ((length (string-length s)))
|
||||
(list->string (list-head (string->list s) (- length n)))))
|
||||
(else (error "string-drop-right: not supported: n=" n))))
|
||||
|
||||
(define (string-delete pred s)
|
||||
(let ((p (if (procedure? pred) pred
|
||||
|
|
|
@ -56,4 +56,10 @@ exit $?
|
|||
"f-o-o-:"
|
||||
(list->string (string-fold-right (lambda (e p) (cons e (cons #\- p))) '(#\:) "foo")))
|
||||
|
||||
(pass-if-equal "string-drop" "bar"
|
||||
(string-drop "foobar" 3))
|
||||
|
||||
(pass-if-equal "string-drop-right" "foo"
|
||||
(string-drop-right "foobar" 3))
|
||||
|
||||
(result 'report)
|
||||
|
|
Loading…
Reference in a new issue