[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Compiling Elisp to a native code with a GCC plugin

From: Stephen J. Turnbull
Subject: Re: Compiling Elisp to a native code with a GCC plugin
Date: Sat, 18 Sep 2010 03:53:27 +0900

David Kastrup writes:

 > > If both the number of chars and bytes agree then they must be of
 > > the same multibyteness.
 > Why?

Actually, there's an exceptional case: if both strings are pure ASCII.
In that case it might be possible that one string is multibyte and the
other unibyte, while the numbers of characters and of bytes are equal.
However, in that case the two strings have the same semantics, so I
would suspect that allowing them to compare equal if their
representations are equal (ignoring multi-byte-ness) is intentional.

The example you gave proves nothing, however.  In fact, when that
string is presented by `string-as-multibyte', ?\351 will be converted
to a private space character in Unicode and therefore will have more
than one byte in its representation.  Thus the length in bytes of the
string (as multibyte) will be 7 (or maybe more, I forget which private
space naked bytes live in).  Here's one way to get byte length of a

(defun string-byte-count (s)
  (length (if (string-multibyte-p s) (encode-coding-string s 'utf-8) s)))

reply via email to

[Prev in Thread] Current Thread [Next in Thread]