all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kenichi Handa <handa@m17n.org>
To: Lars Magne Ingebrigtsen <larsi@gnus.org>
Cc: emacs-devel@gnu.org
Subject: Re: undecided vs utf-8
Date: Fri, 05 Nov 2010 11:01:58 +0900	[thread overview]
Message-ID: <tl7hbfwv889.fsf@m17n.org> (raw)
In-Reply-To: <m3d3qkpvv6.fsf@quimbies.gnus.org> (message from Lars Magne Ingebrigtsen on Thu, 04 Nov 2010 23:27:57 +0100)

In article <m3d3qkpvv6.fsf@quimbies.gnus.org>, Lars Magne Ingebrigtsen <larsi@gnus.org> writes:

> When using erc, it decodes iso-8859-1 fine with the default `undecided'
> into encoding.  However, any utf-8 strings are, sort of, just translated
> into the same coding system:

> (decode-coding-string "u-te-\303\246ff \303\245tte" 'undecided)
>>> "u-te-æff åtte"

It's perhaps because you are in some of iso-8859-1 locale.
As I'm in ja_JP.UTF-8 locale, the above is decoded by utf-8.

> (decode-coding-string "u-te-\303\246ff \303\245tte" 'utf-8)
>>> "u-te-æff åtte"

> So, uhm...  Is this meant to be this way?  I know that guessing the
> first thing is, well, correct, sort of -- it's valid iso-8859-1,
> although very strange.  But it's also valid utf-8.  Shouldn't
> `decode-coding-string' prefer utf-8 if it's actually valid?  If it's
> valid utf-8, then it's quite likely that it's meant to be utf-8, even
> though other coding systems are also possible.

I don't want to add such a heuristic in
decode-coding-string/region (the lowest functions available
from Lisp).  Please note that above sequence is also valid
as Big5.  If people are in Big5 locale, it's hard to answer
which of utf-8 or big5 is preferred unless we implement NLP
system.

Perhaps making an upper layer function that will accept a
list of preferred coding systems will be good; something
like this.

(defun detect-and-decode-coding-string (str preferred)
  (let ((detected (detect-coding-string str))
	decided)
    (while (and preferred (not decided)) 
      (if (memq (car preferred) detected)
	  (setq decided (car preferred))
	(setq preferred (cdr preferred))))
    (decode-coding-string str (or decided (car detected)))))

---
Kenichi Handa
handa@m17n.org



  parent reply	other threads:[~2010-11-05  2:01 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-11-04 22:27 undecided vs utf-8 Lars Magne Ingebrigtsen
2010-11-04 22:40 ` Lars Magne Ingebrigtsen
2010-11-05  0:02   ` Stefan Monnier
2010-11-05  8:01     ` Eli Zaretskii
2010-11-05  2:01 ` Kenichi Handa [this message]
2010-11-05  2:32   ` Lars Magne Ingebrigtsen
2010-11-05  4:42     ` Kenichi Handa
2010-11-05 13:02       ` Lars Magne Ingebrigtsen
2010-11-05  8:09     ` Eli Zaretskii
2010-11-05 13:06       ` Lars Magne Ingebrigtsen
2010-11-05  8:10     ` Eli Zaretskii
2010-11-05 12:28       ` Deniz Dogan
2010-11-05 12:50       ` Lars Magne Ingebrigtsen
2010-11-05  7:56 ` 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=tl7hbfwv889.fsf@m17n.org \
    --to=handa@m17n.org \
    --cc=emacs-devel@gnu.org \
    --cc=larsi@gnus.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.