Bindat (src, strz): Operate on vectors too

Copyright-paperwork-exempt: yes

* lisp/emacs-lisp/bindat.el (bindat--unpack-str, bindat--unpack-strz):
Fix the non-string case.
* test/lisp/emacs-lisp/bindat-tests.el (bindat-test--strz-array-unpack)
(bindat-test--str-simple-array-unpack,bindat-test--str-combined-array-unpack):
New tests.
This commit is contained in:
Nacho Barrientos 2022-10-20 14:16:43 +02:00 committed by Stefan Monnier
parent 693443bbf7
commit 40a361fbd6
2 changed files with 22 additions and 3 deletions

View file

@ -163,7 +163,9 @@
(let ((s (substring bindat-raw bindat-idx (+ bindat-idx len))))
(setq bindat-idx (+ bindat-idx len))
(if (stringp s) s
(apply #'unibyte-string s))))
;; FIXME: There should be a more efficient way to do this.
;; Should `apply' accept vectors in addition to lists?
(apply #'unibyte-string (append s nil)))))
(defun bindat--unpack-strz (&optional len)
(let ((i 0) s)
@ -172,7 +174,7 @@
(setq s (substring bindat-raw bindat-idx (+ bindat-idx i)))
(setq bindat-idx (+ bindat-idx (or len (1+ i))))
(if (stringp s) s
(apply #'unibyte-string s))))
(apply #'unibyte-string (append s nil)))))
(defun bindat--unpack-bits (len)
(let ((bits nil) (bnum (1- (* 8 len))) j m)