[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
01/05: serialization: Factorize 'read-byte-string'.
From: |
Ludovic Courtès |
Subject: |
01/05: serialization: Factorize 'read-byte-string'. |
Date: |
Thu, 05 Mar 2015 21:22:49 +0000 |
civodul pushed a commit to branch master
in repository guix.
commit 472e4c430343671a6cb4e5ed392beae04ef09da6
Author: Ludovic Courtès <address@hidden>
Date: Thu Mar 5 10:06:28 2015 +0100
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 files changed, 12 insertions(+), 14 deletions(-)
diff --git a/guix/serialization.scm b/guix/serialization.scm
index 4f82c06..da01ff3 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
- ;; <http://bugs.gnu.org/19621>. See <http://bugs.gnu.org/19610> 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
+ ;; <http://bugs.gnu.org/19621>. See <http://bugs.gnu.org/19610> 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)