From: Stefan Monnier <monnier@iro.umontreal.ca>
To: help-gnu-emacs@gnu.org
Subject: Re: Conversion to unibyte, magic latin-1?
Date: Sat, 04 May 2019 18:53:46 -0400 [thread overview]
Message-ID: <jwvzho1zvv6.fsf-monnier+emacs@gnu.org> (raw)
In-Reply-To: CAD1CDTUGpG872Xv6VyCPCpLPzGc1+WHwbZ+ULXp=CaHX3mesjw@mail.gmail.com
> (secure-hash 'sha256 (concat [#x52 #xbc #xdd #x9e]))
> "cfdc1612961dc873079178b92bf0aafaa6bd33731cbaa60841eef163f85074e8"
(concat [#x52 #xbc #xdd #x9e]) takes the character codes you specified
and interprets them as unicode chars rather than as bytes. So that's
the origin of your problem.
You want to use (unibyte-string #x52 #xbc #xdd #x9e) instead.
> `string-make-unibyte':
Don't. This will just paper over problems.
If you have a multibyte string (i.e. a sequence of characters) and you
need to convert it to a unibyte string (i.e. a sequence of bytes), then
you want to use `encode-coding-string` where the CODING-SYSTEM indicates
how to convert each char to a corresponding sequence of bytes.
> with a few obvious encodings, but no luck:
`raw-text` is not an obvious encoding.
Encoding with `raw-text` only works in a meaningful way on sequences of
chars where the chars are themselves bytes (these are the char codes
0-127 and #x3fff80-#x3fffff).
> This works, but I'm confused... why does latin-1 work but raw-text or
> binary doesn't?
latin-1 will work in some cases, but only by accident.
Better go back to the origin of the problem (why do you end up with
a multibyte string when what you wanted was a unibyte string).
Stefan
prev parent reply other threads:[~2019-05-04 22:53 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-05-04 15:48 Conversion to unibyte, magic latin-1? Julian Scheid
2019-05-04 22:53 ` Stefan Monnier [this message]
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=jwvzho1zvv6.fsf-monnier+emacs@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.
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.