1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-06-16 16:50:21 +02:00

Add get-string-n' and get-string-n!' for R6RS ports

* libguile/r6rs-ports.c (scm_get_string_n_x): Implement `get-string-n!'
  in C for efficiency.
* libguile/r6rs-ports.h: Add prototype for this function.
* module/ice-9/binary-ports.scm: Export `get-string-n!'.

* module/rnrs/io/ports.scm (get-string-n): Implement based on
  `get-string-n!'.
  Export both `get-string-n!' and `get-string-n'.
* module/rnrs.scm: Also export these.

* test-suite/tests/r6rs-ports.test (8.2.9 Textual input): Add a few
  tests for `get-string-n' and `get-string-n!'.

Signed-off-by: Ludovic Courtès <ludo@gnu.org>
This commit is contained in:
Andreas Rottmann 2011-03-13 22:39:14 +01:00 committed by Ludovic Courtès
parent ca33b501a9
commit a6c377f7d8
6 changed files with 78 additions and 5 deletions

View file

@ -567,6 +567,24 @@
(put-string tp "The letter λ cannot be represented in Latin-1.")
#f)))))
(with-test-prefix "8.2.9 Textual input"
(pass-if "get-string-n [short]"
(let ((port (open-input-string "GNU Guile")))
(string=? "GNU " (get-string-n port 4))))
(pass-if "get-string-n [long]"
(let ((port (open-input-string "GNU Guile")))
(string=? "GNU Guile" (get-string-n port 256))))
(pass-if "get-string-n [eof]"
(let ((port (open-input-string "")))
(eof-object? (get-string-n port 4))))
(pass-if "get-string-n! [short]"
(let ((port (open-input-string "GNU Guile"))
(s (string-copy "Isn't XXX great?")))
(and (= 3 (get-string-n! port s 6 3))
(string=? s "Isn't GNU great?")))))
;;; Local Variables:
;;; mode: scheme
;;; eval: (put 'guard 'scheme-indent-function 1)