bug-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: detect-coding-string doesn't return all possibilities


From: Kenichi Handa
Subject: Re: detect-coding-string doesn't return all possibilities
Date: Fri, 14 Mar 2003 13:55:17 +0900 (JST)
User-agent: SEMI/1.14.3 (Ushinoya) FLIM/1.14.2 (Yagi-Nishiguchi) APEL/10.2 Emacs/21.2.92 (sparc-sun-solaris2.6) MULE/5.0 (SAKAKI)

In article <m3adfyefc7.fsf@defun.localdomain>, Jesper Harder <harder@ifa.au.dk> 
writes:
> Do you know of any other way to decide if using a given coding system
> for decoding a string would give a valid result?

> A function similar to this would be really useful:

> (defun possible-coding-system-for-string-p (str coding-system)
>   "Return t if CODING-SYSTEM is a possible coding system for decoding
>    STR."
>   ...)

How about this?

(defun decode-coding-string-safely (string coding-system)
  "Decode STRING by CODING-SYSYTEM and return the result.
If STRING contains invalid byte sequence for CODING-SYSTEM, return nil."
  (let* ((decoded (decode-coding-string str coding-system))
         (charsets (find-charset-string decoded)))
    (and (not (memq 'eight-bit-control charsets))
         (not (memq 'eight-bit-graphic charsets))
         decoded)))

---
Ken'ichi HANDA
handa@m17n.org




reply via email to

[Prev in Thread] Current Thread [Next in Thread]