Function: dbus-escape-as-identifier

dbus-escape-as-identifier is a byte-compiled function defined in dbus.el.gz.

Signature

(dbus-escape-as-identifier STRING)

Documentation

Escape an arbitrary STRING so it follows the rules for a C identifier.

The escaped string can be used as object path component, interface element component, bus name component or member name in D-Bus.

The escaping consists of replacing all non-alphanumerics, and the first character if it's a digit, with an underscore and two lower-case hex digits:

   "0123abc_xyz\\x01\\xff" -> "_30123abc_5fxyz_01_ff"

i.e. similar to URI encoding, but with "_" taking the role of
"%", and a smaller allowed set. As a special case, "" is
escaped to "_".

Returns the escaped string. Algorithm taken from telepathy-glib's tp_escape_as_identifier.

Source Code

;; Defined in /usr/src/emacs/lisp/net/dbus.el.gz
(defun dbus-escape-as-identifier (string)
  "Escape an arbitrary STRING so it follows the rules for a C identifier.
The escaped string can be used as object path component, interface element
component, bus name component or member name in D-Bus.

The escaping consists of replacing all non-alphanumerics, and the
first character if it's a digit, with an underscore and two
lower-case hex digits:

   \"0123abc_xyz\\x01\\xff\" -> \"_30123abc_5fxyz_01_ff\"

i.e. similar to URI encoding, but with \"_\" taking the role of
\"%\", and a smaller allowed set.  As a special case, \"\" is
escaped to \"_\".

Returns the escaped string.  Algorithm taken from
telepathy-glib's `tp_escape_as_identifier'."
  (if (zerop (length string))
      "_"
    (replace-regexp-in-string
     "\\`[0-9]\\|[^A-Za-z0-9]"
     (lambda (x) (format "_%2x" (aref x 0)))
     string nil t)))