summary refs log tree commit diff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2015-03-05 10:06:28 +0100
committerLudovic Courtès <ludo@gnu.org>2015-03-05 22:17:36 +0100
commit472e4c430343671a6cb4e5ed392beae04ef09da6 (patch)
treee0d944c06781a8f1e377dd751e2387ac3cd1b155
parent87d79282941de06a9b0c464df87c8d0456c145ce (diff)
downloadguix-472e4c430343671a6cb4e5ed392beae04ef09da6.tar.gz
serialization: Factorize 'read-byte-string'.
* guix/serialization.scm (read-byte-string): New procedure.
  (read-string, read-latin1-string): Use it.
-rw-r--r--guix/serialization.scm26
1 files 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
-         ;; <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)