[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: character encoding question
From: |
Stefan Monnier |
Subject: |
Re: character encoding question |
Date: |
Wed, 20 Feb 2013 09:42:49 -0500 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/24.3.50 (gnu/linux) |
> 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