; Fix documentation of a recent change in dbus.el (bug#70301)

* lisp/net/dbus.el (dbus-string-to-byte-array)
(dbus-byte-array-to-string):
* etc/NEWS:
* doc/misc/dbus.texi (Type Conversion): Fix documentation of these
two D-Bus functions.
This commit is contained in:
Eli Zaretskii 2024-04-12 14:26:27 +03:00
parent 4ff852a558
commit f93df59e8c
3 changed files with 18 additions and 10 deletions

View file

@ -1083,8 +1083,8 @@ elements of this array. Example:
@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")
@ -1156,8 +1156,9 @@ The signal @code{PropertyModified}, discussed as an example in
@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))

View file

@ -1775,9 +1775,15 @@ Instead, use 'eshell-process-wait-time', which supports floating-point
values.
+++
** '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.
* Lisp Changes in Emacs 30.1

View file

@ -995,7 +995,7 @@ association to the service from D-Bus."
(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
@ -1004,9 +1004,10 @@ STRING.."
(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)))