Function: string-as-unibyte

string-as-unibyte is a function defined in fns.c.

This function is obsolete since 26.1; use encode-coding-string.

Signature

(string-as-unibyte STRING)

Documentation

Return a unibyte string with the same individual bytes as STRING.

If STRING is unibyte, the result is STRING itself. Otherwise it is a newly created string, with no text properties. If STRING is multibyte and contains a character of charset eight-bit, it is converted to the corresponding single byte.

Probably introduced at or before Emacs version 20.3.

Aliases

pgg-string-as-unibyte

Source Code

// Defined in /usr/src/emacs/src/fns.c
{
  CHECK_STRING (string);

  if (STRING_MULTIBYTE (string))
    {
      unsigned char *str = (unsigned char *) xlispstrdup (string);
      ptrdiff_t bytes = str_as_unibyte (str, SBYTES (string));

      string = make_unibyte_string ((char *) str, bytes);
      xfree (str);
    }
  return string;
}