From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: character encoding question
Date: Wed, 20 Feb 2013 09:42:49 -0500 [thread overview]
Message-ID: <jwvmwuz2gvt.fsf-monnier+gmane.emacs.help@gnu.org> (raw)
In-Reply-To: 87mwuzze5s.fsf@ericabrahamsen.net
> So the character 中 has a codepoint of #o47055 in octal notation.
Internally, in your Emacs, yes. This value actually depends on the
internal representation chosen by Emacs, which happens to be Unicode
since Emacs-23 (and was something else before).
> Meanwhile:
> (string-as-unibyte "中") --> \344\270\255
This again shows the internal byte representation of this char inside
a buffer, which is utf-8 since Emacs-23 and was something else before.
Strong recommendation: stay far away from string-as-* because that will
mess you up.
You want instead to use encode-coding-string. E.g.
(encode-coding-string "中" 'utf-8) ==> "\344\270\255"
> What's the correspondence between these bytes and the multibyte
> character's octal codepoint?
#o47055 is not "multibyte". It's just its "name" aka "codepoint".
"\344\270\255" is one if its multibyte encodings.
> Are there any functions that will get from one to the other?
(encode-coding-string (string #o47055) 'utf-8) ==> "\344\270\255"
> Given a series of mystery bytes, can I test them against different
> charsets, and see what gibberish Emacs comes up with?
(decode-coding-string "\344\270\255" 'utf-8) ==> "中"
-- Stefan
next prev parent reply other threads:[~2013-02-20 14:42 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-02-20 6:34 character encoding question Eric Abrahamsen
2013-02-20 10:44 ` Peter Dyballa
2013-02-20 14:42 ` Stefan Monnier [this message]
2013-02-20 18:48 ` Eli Zaretskii
2013-02-21 2:42 ` Eric Abrahamsen
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
List information: https://www.gnu.org/software/emacs/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=jwvmwuz2gvt.fsf-monnier+gmane.emacs.help@gnu.org \
--to=monnier@iro.umontreal.ca \
--cc=help-gnu-emacs@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.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).