From: Kenichi Handa <handa@m17n.org>
To: Eli Zaretskii <eliz@gnu.org>
Cc: emacs-devel@gnu.org
Subject: Re: Emacs 23 character code space
Date: Wed, 26 Nov 2008 10:31:19 +0900 [thread overview]
Message-ID: <E1L59FP-0005W8-QD@etlken.m17n.org> (raw)
In-Reply-To: <uk5aviv36.fsf@gnu.org> (message from Eli Zaretskii on Sat, 22 Nov 2008 18:28:13 +0200)
In article <uk5aviv36.fsf@gnu.org>, Eli Zaretskii <eliz@gnu.org> writes:
> Emacs can convert unibyte text to multibyte; it can also convert
> multibyte text to unibyte provided that the multibyte text contains
> only @acronym{ASCII} and 8-bit characters.
> What exactly is meant here by ``8-bit characters''? Do you mean
> eight-bit raw bytes, or do you mean Unicode characters whose
> codepoints are below 256?
The former; more precisely, characters representing
eight-bit raw bytes. They have different character codes in
multibyte text (#x3FFF80..#x3FFFFF) and unibyte text
(#x80..#xFF).
> Converting unibyte text to multibyte text leaves @acronym{ASCII} characters
> unchanged, and converts 8-bit characters (codes 128 through 159) to
> the corresponding representation for multibyte text.
> Again, by ``8-bit characters'' you mean raw 8-bit bytes here, right?
Yes.
> @defun string-to-multibyte string
> This function returns a multibyte string containing the same sequence
> of characters as @var{string}. If @var{string} is a multibyte string,
> it is returned unchanged.
> @end defun
> I'm not sure I understand the effect of this function. Does it decode
> its argument, converting each byte to the corresponding internal
> representation of the encoded single-byte character? I think this is
> not what it does, but then what does it do?
No, all 8-bit characters (#x80..#xFF) in the source unibyte
string is converted to the multibyte representation of those
8-bit characters (#x3FFF80..#x3FFFFF).
> @defun string-to-unibyte string
> This function returns a unibyte string containing the same sequence of
> characters as @var{string}. It signals an error if @var{string}
> contains a non-@acronym{ASCII} character. If @var{string} is a
> unibyte string, it is returned unchanged.
> @end defun
> Since this function handles any non-ASCII characters lossily, when
> would it be useful?
If you know that a string containts only ASCII or 8-bit
characters, you can use it to get a unibyte string without
loosing information.
> @defun multibyte-char-to-unibyte char
> This convert the multibyte character @var{char} to a unibyte
> character. If @var{char} is a non-@acronym{ASCII} character, the
> value is -1.
> @end defun
> @defun unibyte-char-to-multibyte char
> This convert the unibyte character @var{char} to a multibyte
> character.
> @end defun
> Again, when are these functions useful?
Perhaps, we don't need them anymore. We can use get-byte.
Anyway, the relationship of they and
string-to-unibyte/multibyte is this:
(defun string-to-unibyte (str)
(let ((new (make-string (length str) 0)))
(dotimes (i (length str))
(let ((byte (multibyte-char-to-unibyte (aref str i))))
(if (< byte 0)
(error))
(aset new i byte)))
new))
(defun string-to-multibyte (str)
(let ((new (make-string (length str) 0)))
(dotimes (i (length str))
(aset new i (unibyte-char-to-multibyte (aref str i))))
new))
---
Kenichi Handa
handa@ni.aist.go.jp
next prev parent reply other threads:[~2008-11-26 1:31 UTC|newest]
Thread overview: 39+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-11-01 14:20 Emacs 23 character code space Eli Zaretskii
2008-11-01 16:46 ` Eli Zaretskii
2008-11-03 1:34 ` Kenichi Handa
2008-11-03 12:45 ` Kenichi Handa
2008-11-03 20:13 ` Eli Zaretskii
2008-11-04 7:35 ` Kenichi Handa
2008-11-04 20:19 ` Eli Zaretskii
2008-11-05 12:27 ` Kenichi Handa
2008-11-05 18:23 ` Eli Zaretskii
2008-11-22 18:25 ` Eli Zaretskii
2008-11-26 1:41 ` Kenichi Handa
2008-11-26 4:13 ` Eli Zaretskii
2008-11-26 4:24 ` Kenichi Handa
2008-11-26 4:58 ` Kenichi Handa
2008-11-26 20:26 ` Eli Zaretskii
2008-11-26 22:52 ` Juanma Barranquero
2008-11-27 1:10 ` Stephen J. Turnbull
2008-11-27 1:35 ` Kenichi Handa
2008-11-26 20:18 ` Eli Zaretskii
2008-11-27 1:29 ` Kenichi Handa
2008-11-29 17:12 ` Eli Zaretskii
2008-12-02 5:40 ` Kenichi Handa
2008-11-28 13:19 ` Eli Zaretskii
2008-12-02 5:44 ` Kenichi Handa
2008-12-02 19:40 ` Eli Zaretskii
2008-11-29 12:01 ` Eli Zaretskii
2008-11-22 16:28 ` Eli Zaretskii
2008-11-23 4:16 ` Stefan Monnier
2008-11-23 11:22 ` Eli Zaretskii
2008-11-26 1:51 ` Kenichi Handa
2008-11-23 8:29 ` Ulrich Mueller
2008-11-23 11:11 ` Eli Zaretskii
2008-11-23 11:55 ` Ulrich Mueller
2008-11-24 3:06 ` Stefan Monnier
2008-11-26 1:31 ` Kenichi Handa [this message]
2008-11-22 17:03 ` New function: what-file-line, used when writing gdb script richardeng
2008-11-07 7:21 ` Emacs 23 character code space Kenichi Handa
2008-11-07 10:27 ` Eli Zaretskii
2008-11-07 11:52 ` Kenichi Handa
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=E1L59FP-0005W8-QD@etlken.m17n.org \
--to=handa@m17n.org \
--cc=eliz@gnu.org \
--cc=emacs-devel@gnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this external index
https://git.savannah.gnu.org/cgit/emacs.git
https://git.savannah.gnu.org/cgit/emacs/org-mode.git
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.