Skip to content

Joining And Splitting

Scheme Procedure: bytestring-join bytevector-list delimiter

Joins the bytevectors in bytevector-list together using the delimiter, which can be anything suitable as an argument to bytestring. The grammar argument is a symbol that determines how the delimiter is used, and defaults to infix. It is an error for grammar to be any symbol other than these four:

infix

means an infix or separator grammar: inserts the delimiter between list elements. An empty list will produce an empty bytevector

strict-infix

means the same as infix if the list is non-empty, but will signal an error satisfying bytestring-error? if given an empty list.

suffix

means a suffix or terminator grammar: inserts the delimiter after every list element.

prefix

means a prefix grammar: inserts the delimiter before every list element.

For example:

emacs-lisp
(bytestring-join '(#u8"Heart" #u8"of" #u8"Gold") #x20)
#u8"Heart of Gold"
(bytestring-join '(#u8(#xef #xbb) #u8(#xbf)) 0 'prefix)
#u8(0 #xef #xbb 0 #xbf)
(bytestring-join '() 0 'strict-infix)
  ⇒ ⇒ raised &bytestring-error

Scheme Procedure: bytestring-split bytevector delimiter [grammar]

Divides the elements of bytevector and returns a list of newly allocated bytevectors using the delimiter (an ASCII character or exact integer in the range 0-255 inclusive). Delimiter bytes are not included in the result bytevectors.

The grammar argument is used to control how bytevector is divided. It has the same default and meaning as in bytestring-join, except that infix and strict-infix mean the same thing. That is, if grammar is prefix or suffix, then ignore any delimiter in the first or last position of bytevector respectively.

emacs-lisp
(bytestring-split #u8"Beeblebrox" #x62)
  ⇒ (#u8"Bee" #u8"le" #u8"rox")
(bytestring-split #u8(1 0 2 0) 0 'suffix)
  ⇒ (#u8(1) #u8(2))