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

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

Re: How to determine encoding for file?


From: Pascal J. Bourguignon
Subject: Re: How to determine encoding for file?
Date: Sun, 24 Jan 2010 22:59:46 +0100
User-agent: Gnus/5.101 (Gnus v5.10.10) Emacs/22.3 (gnu/linux)

kj <address@hidden> writes:

> I've downloaded a large file that is supposed to contain a mixture
> of Japanese and English (it's basically a learner's dictionary).
> The English is displayed correctly, but not so for the Japanese.
>
> I've tried setting the buffer's coding system to utf-8,
> japanese-shift-jis, japanese-shift-jis-mac, japanese-shift-jis-dos
> (just guessing).  None worked.
>
> In fact, I'm not even sure that any of these changes of the coding
> system achieved *anything*, since the buffer's appearance remained
> unchanged throughout all this mucking around.  I used the command
> set-buffer-file-coding-system to do this.  Should I need to do
> anything besides re-setting the coding system to see a change in
> how the file is displayed?
>
> More importantly, is there a better way to determine a file's
> correct coding system besides trial and error?

No, there is no better way.

>From the sequences of bytes you can find inside the files, you may
eliminate some encodings (eg. some byte sequences are invalid in
UTF-8), but there are several encodings that use all the byte values
and where any sequence of byte is valid, so you cannot choose between
these encoding without knowing the meaning of the file.

For example, the following file:

$ od -t x1 -c /tmp/a.txt
0000000  50  72  69  63  65  20  6f  66  20  74  68  65  20  69  74  65
          P   r   i   c   e       o   f       t   h   e       i   t   e
0000020  6d  3a  20  31  34  20  a4  0a
          m   :       1   4     244  \n
0000030


The encoding cannot be determined without knowing what item is
referenced, and what price ranges are probable for this item.  It
could contain:

Price of the item: 14 €

or:

Price of the item: 14 ¤

(It could also contain another character, but it would be less probable).


-- 
__Pascal Bourguignon__                     http://www.informatimago.com/


reply via email to

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