From: Thien-Thi Nguyen <ttn@gnu.org>
To: emacs-devel@gnu.org
Subject: string-to-unibyte in image-jpeg-p
Date: Wed, 23 May 2018 12:21:52 +0200 [thread overview]
Message-ID: <87zi0q3c5b.fsf@gnuvola.org> (raw)
[-- Attachment #1: Type: text/plain, Size: 1655 bytes --]
One of the last ‘string-to-unibyte’ (deprecated for a while)
calls is in ‘image-jpeg-p’:
(defun image-jpeg-p (data)
"..."
(setq data (ignore-errors (string-to-unibyte data)))
...)
We can simulate ‘string-to-unibyte’ (except for error message
particulars) with ‘FAKE-string-to-unibyte’, which uses the
modern ‘encode-coding-string’:
(defun FAKE-string-to-unibyte (s)
(let ((tem (encode-coding-string s 'binary)))
(when (string-match-p "\xc2" tem)
(error "badness"))
tem))
However, the original call ignores errors, so this:
(setq data (ignore-errors (FAKE-string-to-unibyte data)))
can be simplified to this:
(setq data (FAKE/NOERROR-string-to-unibyte data))
by defining:
(defun FAKE/NOERROR-string-to-unibyte (s)
(let ((tem (encode-coding-string s 'binary)))
(unless (string-match-p "\xc2" tem)
tem)))
The last step is to simply inline the definition:
(setq data (let ((tem (encode-coding-string data 'binary)))
(unless (string-match-p "\xc2" tem)
tem)))
My questions are:
- Is my reasoning correct? In particular, i'd like to confirm
that the "error" detection via "\xc2" is a valid strategy.
- If so, which branch gets the change, ‘emacs-26’ or ‘master’?
- If not, what am i missing?
--
Thien-Thi Nguyen -----------------------------------------------
(defun responsep (query)
(pcase (context query)
(`(technical ,ml) (correctp ml))
...)) 748E A0E8 1CB8 A748 9BFA
--------------------------------------- 6CE4 6703 2224 4C80 7502
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 197 bytes --]
next reply other threads:[~2018-05-23 10:21 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-23 10:21 Thien-Thi Nguyen [this message]
2018-05-23 19:43 ` string-to-unibyte in image-jpeg-p Stefan Monnier
2018-05-23 20:01 ` Eli Zaretskii
2018-05-23 20:17 ` Andreas Schwab
2018-05-23 20:29 ` Stefan Monnier
2018-05-23 20:46 ` Paul Eggert
2018-05-24 8:51 ` Robert Pluim
2018-05-24 15:19 ` Eli Zaretskii
2018-05-24 15:31 ` Robert Pluim
2018-05-24 17:09 ` Eli Zaretskii
2018-05-24 19:51 ` Stefan Monnier
2018-05-25 6:10 ` Eli Zaretskii
2018-05-25 18:01 ` Stefan Monnier
2018-05-25 19:13 ` Eli Zaretskii
2018-05-25 20:39 ` Stefan Monnier
2018-05-26 8:27 ` Eli Zaretskii
2018-05-31 10:40 ` Robert Pluim
2018-05-31 14:50 ` Eli Zaretskii
2018-05-31 15:17 ` Robert Pluim
2018-05-24 15:59 ` Stefan Monnier
2018-05-24 17:00 ` Eli Zaretskii
2018-05-24 19:51 ` Stefan Monnier
2018-05-25 6:10 ` Eli Zaretskii
2018-05-26 21:02 ` Stefan Monnier
2018-05-24 16:57 ` Eli Zaretskii
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=87zi0q3c5b.fsf@gnuvola.org \
--to=ttn@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.