[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
string-to-unibyte in image-jpeg-p
From: |
Thien-Thi Nguyen |
Subject: |
string-to-unibyte in image-jpeg-p |
Date: |
Wed, 23 May 2018 12:21:52 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/27.0.50 (gnu/linux) |
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
signature.asc
Description: PGP signature
- string-to-unibyte in image-jpeg-p,
Thien-Thi Nguyen <=
- Re: string-to-unibyte in image-jpeg-p, Stefan Monnier, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Andreas Schwab, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Stefan Monnier, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Paul Eggert, 2018/05/23
- Re: string-to-unibyte in image-jpeg-p, Robert Pluim, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Robert Pluim, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Eli Zaretskii, 2018/05/24
- Re: string-to-unibyte in image-jpeg-p, Stefan Monnier, 2018/05/24