From 472e4c430343671a6cb4e5ed392beae04ef09da6 Mon Sep 17 00:00:00 2001 From: Ludovic Courtès Date: Thu, 5 Mar 2015 10:06:28 +0100 Subject: serialization: Factorize 'read-byte-string'. * guix/serialization.scm (read-byte-string): New procedure. (read-string, read-latin1-string): Use it. --- guix/serialization.scm | 26 ++++++++++++-------------- 1 file changed, 12 insertions(+), 14 deletions(-) diff --git a/guix/serialization.scm b/guix/serialization.scm index 4f82c06862..da01ff39f5 100644 --- a/guix/serialization.scm +++ b/guix/serialization.scm @@ -109,28 +109,26 @@ (bytevector-copy! s 0 b 8 l) (put-bytevector p b))) -(define (read-string p) +(define (read-byte-string p) (let* ((len (read-int p)) (m (modulo len 8)) - (bv (get-bytevector-n* p len)) - (str (utf8->string bv))) + (bv (get-bytevector-n* p len))) (or (zero? m) (get-bytevector-n* p (- 8 m))) - str)) + bv)) -(define (read-latin1-string p) - (let* ((len (read-int p)) - (m (modulo len 8)) - ;; Note: do not use 'get-string-n' to work around Guile bug - ;; . See for - ;; a discussion. - (str (get-bytevector-n* p len))) - (or (zero? m) - (get-bytevector-n* p (- 8 m))) +(define (read-string p) + (utf8->string (read-byte-string p))) +(define (read-latin1-string p) + "Read an ISO-8859-1 string from P." + ;; Note: do not use 'get-string-n' to work around Guile bug + ;; . See for + ;; a discussion. + (let ((bv (read-byte-string p))) ;; XXX: Rewrite using (ice-9 iconv) when the minimum requirement is ;; upgraded to Guile >= 2.0.9. - (list->string (map integer->char (bytevector->u8-list str))))) + (list->string (map integer->char (bytevector->u8-list bv))))) (define (write-string-list l p) (write-int (length l) p) -- cgit 1.4.1