@defun dbus-string-to-byte-array string
Sometimes, D-Bus methods require as input parameter an array of bytes,
-instead of a string. If it is guaranteed, that @var{string} is a
-UTF-8 string, this function performs the conversion. Example:
+instead of a string. This function converts @var{string} into an array
+of bytes of the UTF-8 encoding of @var{string}. Example:
@lisp
(dbus-string-to-byte-array "/etc/hosts")
@defun dbus-byte-array-to-string byte-array
If a D-Bus method or signal returns an array of bytes, which are known
-to represent a UTF-8 string, this function converts @var{byte-array}
-to the corresponding UTF-8 string. Example:
+to represent a UTF-8 string, this function converts @var{byte-array} to
+the corresponding Lisp string. The contents of @var{byte-array} should
+be the byte sequence of a UTF-8 encoded string. Example:
@lisp
(dbus-byte-array-to-string '(47 101 116 99 47 104 111 115 116 115))
minibuffer history is reserved for past minibuffer inputs.
+++
-** 'dbus-{string-to-byte-array,byte-array-to-string}' are strict UTF-8 conform.
-Both work over UTF-8 raw bytes only. The optional parameter MULTIBYTE
-of 'dbus-byte-array-to-string' is obsolete now.
+** Conversion of strings to and from byte-arrays works with multibyte strings.
+The functions 'dbus-string-to-byte-array' and
+'dbus-byte-array-to-string}' now accept and return multibyte Lisp
+strings, encoding to UTF-8 and decoding from UTF-8 internally. This
+means that the argument to 'dbus-byte-array-to-string' must be a valid
+UTF-8 byte sequence, and the optional parameter MULTIBYTE of
+'dbus-byte-array-to-string' is now obsolete and unused. The argument of
+'dbus-string-to-byte-array' should be a regular Lisp string, not a
+unibyte string.
\f
* Lisp Changes in Emacs 30.1
(defun dbus-string-to-byte-array (string)
"Transform STRING to list (:array :byte C1 :byte C2 ...).
The resulting byte array contains the raw bytes of the UTF-8 encoded
-STRING.."
+STRING."
(if (length= string 0)
'(:array :signature "y")
(cons :array
(encode-coding-string string 'utf-8 'nocopy))))))
(defun dbus-byte-array-to-string (byte-array &optional _multibyte)
- "Transform BYTE-ARRAY into UTF-8 coded string.
+ "Transform BYTE-ARRAY with UTF-8 byte sequence into a string.
BYTE-ARRAY must be a list of structure (c1 c2 ...), or a byte array as
-produced by `dbus-string-to-byte-array'."
+produced by `dbus-string-to-byte-array', and the individual bytes must
+be a valid UTF-8 byte sequence."
(declare (advertised-calling-convention (byte-array) "30.1"))
(if-let ((bytes (seq-filter #'characterp byte-array))
(string (apply #'unibyte-string bytes)))