文字コードの混合

文字コードの混合

[1] 1つのテキストファイル文字コード体系は通常は1つだけですが、 稀に複数の文字コード体系が混在していることがあります。

実利用例

[42] i-DNS.net Main Page, , https://web.archive.org/web/20010201060300/http://i-dns.net/

[43] >>42Big5, GB 2312, Shift_JIS, EUC-KR, Windows-1256 が混在した文書です(!)。

[44] document.charset も参照。

[45] 現在の WindowsFirefoxChrome では Windows-1252 と誤認されてしまいます。 文字コード選択メニューもないので文字化けの解消方法がありません。 Firefox の修復機能も有効になりません。

[2] https://web.archive.org/web/19961219091131im_/http://websmile.pef.zcu.cz/

[6] https://web.archive.org/web/20000829132216im_/http://www.cdac.org.in/html/gist/multitxt.htm

[7] https://web.archive.org/web/20000302172616im_/http://www.cdac.org.in:80/html/gist/multidld.htm

[8] https://web.archive.org/web/20000819083216im_/http://www.aczone.com/itrans/s1html.html

[9] https://web.archive.org/web/20000304161654im_/http://www.geocities.com/Athens/Delphi/2627/ttfonts.html

8bit + Latin1 entities

[10] https://members.tripod.com/tomcat_f14/link.html

Big5 + Shift_JIS

[11] https://web.archive.org/web/20190806093220im_/http://www.angelfire.com/empire/thamizh/padanGaL/index.html

UTF-16ed TSCII, broken by insertion of ASCII trailer by the hosting server

[12] https://web.archive.org/web/20070627000015im_/http://parc.cdac.in/Contents.asp

PASCII + 7bit "UTOPIC"

[13] https://lists.fu-berlin.de/pipermail/ipoa-forum/2012-September.txt

ISO-8859-1, ISO-8859-15, UTF-8

[14] https://thieunuvh.tripod.com/vanhoa/ConGaiviq.html

VISCII + VIQR

[15] https://thieunuvh.tripod.com/vanhoa/BaMeviq.html

VISCII + VIQR

[16] https://thieunuvh.tripod.com/vanhoa/MeToiviq.html

VISCII + VIQR

[17] https://web.archive.org/web/20230409125357im_/https://burmese.voanews.com/a/7042708.html

UTF-8 Unicode + Zawgyi

[18] https://www.tamillexicon.com/uc/help

UTF-8 TSCII + TAB

[22] >>21 「Føroyar」は ISO-8859-1。 「台灣」は Big5FirefoxWindows-1252 として読み、すぐに Big5 として再読み込み。 ソース表示では Windows-1252ChromeWindows-1250 と誤判定。

[25] >>23 「Føroyar」は ISO-8859-1。 この時点では Big5 は無し。

[26] >>24 には Mozilla でそれまで >>23 が正しく表示できていたものが、 Johab 対応が入った結果文字化けするようになったとの報告。 ただし本当に因果関係があったのかは不明。

[100] ftp://ontologia.hu/Hunglish/data/readme.html

The encoding of the sentence pair and the alignment files is mixed: ISO Latin-2 on the Hungarian side, and ISO Latin-1 on the English side. The overwhelming majority of the texts use compatible subsets of these two encodings, so for viewing, the files can be considered ISO Latin-2 encoded.


[46] ISO-2022-JPシフトJISの混在については ISO-2022-JP 参照。

[47] ASCII7ビット符号の混在についてはフォント依存符号化参照。

[28] 明らかに誤ったもの、完全なる修復が困難なものは文字コードの修復を参照。

人工的な利用例

[3] https://zsigri.tripod.com/fontboard/cjk/gbhzgbk.html

EUC-CN + HZ

[4] https://zsigri.tripod.com/fontboard/cjk/jis.html

SJIS + 日本語EUC + JISコード

[5] https://zsigri.tripod.com/fontboard/cjk/ksc.html

ISO-2022-KR + EUC-KR

[27] null, , https://www.regata.yar.ru/error/contact.html.var

いろいろが混合。

[32] Russification of Macintosh: Testing, https://web.archive.org/web/20001120020200fw_/http://www.friends-partners.org/partners/rusmac/test.html

いろいろが混合。


[19] Slovni standardi, , https://web.archive.org/web/19971021150753/http://www.hina.hr/hina/standardi.html

[20] >>19 これは厳密には「混在」ではありませんが、 当時の netscape.ini からの引用を含みます。 FirefoxWindows-1252 と認識し、 ChromeShift_JIS と認識します。 当時の著者は Windows-1250 の環境だったと推測されます。

Windows-1252 として読むと

    [INTL]
    Font0=iso-8859-1,HRHelvetica,10,Courier New,10
    Font1=x-sjis,‚l‚r –¾’©,10,‚l‚r –¾’©,10

Shift_JIS として読むと

[INTL]
Font0=iso-8859-1,HRHelvetica,10,Courier New,10
Font1=x-sjis,MS全角 明朝,10,MS全角 明朝,10

文字コードごとのフォント指定で、日本語環境以外で読めないとしてもそのままフォント名が書かれた部分だったわけです。

おそらく著者は読めないままコピペしたはずです。

この引用部分以外は ASCII文字

実装

[29] compact_enc_det/compact_enc_det/compact_enc_det.cc at master · google/compact_enc_det · GitHub, https://github.com/google/compact_enc_det/blob/master/compact_enc_det/compact_enc_det.cc#L232

// We try here to avoid having title text dominate the encoding detection,
// for the not-infrequent error case of title in encoding1, body in encoding2:
// we want to bias toward encoding2 winning.

[30] >>29文字コードの判定の実装である ced の注釈ですが、 title と本文とで符号化が異なるような場合がままあり、 本文を優先させるとしています。

[31] 確かに、本文データベースからのデータを配信システム生成 HTML に差し込む際の処理が適切でないと思われる、 UI 部分と本文部分とで文字コードが異なり文字化けしている事例はしばしば見かけます。

関連

Webブラウザーによる文字コード判定の失敗事例集

Webにおける文字コード, HTMLにおける文字コード

文字コードの修復

メモ