RFC 2781

UTF-16 (文字コード)

[23] UTF-16 は、 Unicode符号化方式の1つです。

本項は歴史的事項を説明しています。本項の内容の一部または全部は、現在の状況とは異なるかもしれません。

(なお本項の内容の一部または全部は、互換性または歴史的連続性のために現在も有効な場合もあります。しかし新たに利用することは避けるべきです。)

目次

  1. 代替
  2. 仕様書
  3. 名前
  4. UTF-16 符号化
  5. 符号化方式
  6. BOM
  7. Web における UTF-16
  8. XML における UTF-16
  9. PDF における UTF-16
  10. Python における UTF-16
  11. その他の応用
  12. 歴史
    1. ISO/IEC 10646 における UTF-16
    2. UTF-16x
    3. RFC
    4. Encoding Standard

代替#

[32] 新たに UTF-16 を使うべきではありません。かわりに、 UTF-8 を使うのが好ましいとされています。

仕様書#

[36] 既存のデータとの互換性のため、 Encoding Standard >>22UTF-16復号が規定されています。以前 >>35符号化も規定されていましたが、 Web互換性のためには不要であるとして、削除されました。

名前#

[21] Encoding Standard によれば、大エンディアンUTF-16 の名前が UTF-16BE であり、ラベルとして utf-16be を使って指定できます。また小エンディアンUTF-16 の名前が UTF-16LE であり、ラベルとして utf-16le または utf-16 を使って指定できます。

UTF-16 符号化#

[24] HTML StandardUTF-16BE, UTF-16LE , utf-16 の総称を UTF-16 符号化 (a UTF-16 encoding) としています >>25

[20] RFC 3023 は、 RFC 2781 における utf-16utf-16beutf-16le の総称を UTF-16 族 (the UTF-16 family) としています >>19

符号化方式#

  1. [6] U+D800 から U+DFFF までは表現できません。
  2. [7] U-00110000 から先は表現できません。 (ISO/IEC 10646 には存在しますが、Unicode には存在しません。)
  3. [8] それ以外で U+0000 から U+FFFF であるなら、その符号位置と同じ値の16ビット符号単位によって表現します。
  4. [9] それ以外なら、つまり U+10000 から U+10FFFF であるなら、
    1. [10] U'符号位置から 0x10000 引いた値とします。この結果の値は20ビット非負整数です。
    2. [11] W1U' の上位10ビットと 0xD800 の論理和とします。
    3. [12] W2U' の下位10ビットと 0xDC00 の論理和とします。
    4. [13] 当該符号位置W1 W2 の2つの16ビット符号単位の列によって表現します。

[14] >>9 を図示すると、次のようになります。

BOM#

[26] UTF-16 および派生文字コードでの BOM の取り扱いについては、 BOM の項を参照してください。

Web における UTF-16#

[29] Web文字コードUTF-8 であり、 UTF-16 は使うべきではないとされています。

[30] ただし JavaScriptDOM は、歴史的理由により、文字列の表現に UTF-16 による16ビット符号単位を使っています。

XML における UTF-16#

[27] XML には UTF-16 に関する特別な規定がいくつもあります。 詳しくは XMLにおける文字コードを参照してください。

PDF における UTF-16#

[40] PDF では BOM 付き UTF-16BE を使います。

[41] OpenTypeUTF-16BE を使います。

Python における UTF-16#

surrogateescape

その他の応用#

[42] DOMHASHUTF-16BE を使います。

[46] LeXMLUTF-16 を推奨しています.

歴史#

[37] UTF-16 は、 UCS-2 の16ビット平面ではすべての文字符号化に十分でないことが明確になったとしてサロゲートペアが導入されたことにより登場しました。

[45] UTF-16の誕生 | yasuokaの日記 | スラド, https://srad.jp/~yasuoka/journal/387747/

[47] Wayback Machine, https://web.archive.org/web/20000821235014/http://www.unicode.org/Public/TEXT/ALLOC.TXT

In the ISO-IEC SC2/WG2 meetings where the current structure of the 10646 BMP was decided, there was discussion of the potential use of the O-Zone as a target zone for swapping in designated quarters of supplemental planes. The topic was however deferred, and no formal definition of such a regime was defined. The Japan national body negative vote on DIS 10646-1.2 explicitly requested that the O-Zone be expanded from 64 to 94 rows "for swapping-in the existing standards"; again no formal details were provided. In the absence of detailed proposals, general comments may be made on these two broad variants of the swap zone idea.

Considering the Japanese innovation first, this proposal to expand the O-Zone and swap in existing standards was explicitly rejected by WG2, because it is opposed to the basic intent of this standard, which is to assign a single code position to each graphical character, not to provide an indexing mechanism into existing standards. The expansion of the O-Zone to 94 rows is impossible in any case.

[48] 日本はこの段階でもまだ DIS 10646 みたいなのをぶっこもうとしてたのか、攻めてるなあw

ISO/IEC 10646 における UTF-16#

[1] UTF-16 は、 ISO/IEC 10646 の附属書 C で規定されている UCS符号化表現の一つです。

[2] 送信装置は、受信装置UCS-2 しか解釈できない場合でも UTF-16 を送って構いません。 (C.7 参照。)

[3] C.7 は、 UTF-16/UCS-2 の実装を次のように分類しています。

(00 群 01 面以降を表す区点要素対の表示方法)

記号知らない文字知っている文字
UCS-2の実装U〓〓
弱い実装W〓〓α
中程度の強さの実装Aα
強い実装Sα

(αが 00 群 01 面以降にある知っている文字、 は知らない文字の代替表現とする。)

[4] >>3 W の実装ってあるのだろうか?

[5] 中程度の強さの実装と強い実装の違いはなんだ?

UTF-16x#

[43] UTF-16x (UTF-16 extension), Apr.30 1999, , http://hp.vector.co.jp/authors/VA002891/UTF16X.TXT

[44] Shift-Mojikyo も参照。

RFC#

[15] RFC 2781 - UTF-16, an encoding of ISO 10646 ( ( 版)) http://tools.ietf.org/html/rfc2781

[19] RFC 3023 - XML Media Types ( 版) http://tools.ietf.org/html/rfc3023#section-2

Encoding Standard#

[16] Web Applications 1.0 r6498 Clean up how we refer to UTF-16. ( ( 版)) http://html5.org/tools/web-apps-tracker?from=6497&to=6498

[17] IRC logs: freenode / #whatwg / 20111226 ( ( 版)) http://krijnhoetmer.nl/irc-logs/whatwg/20111226#l-109

[18] [whatwg] [encoding] utf-16 ( ( 版)) http://lists.whatwg.org/htdig.cgi/whatwg-whatwg.org/2011-December/034260.html

[28] Describe the security situation around encodings and require browsers to... · 2e43ead · whatwg/encoding ( ( 版)) https://github.com/whatwg/encoding/commit/2e43ead5c796e314cd3aaada10a2dc33de7bfaf1#diff-8d4d847e6257b75f4bf8030496281de4R2632

[31] 24120 – The Encoding Standard only recognizes utf-16le and utf-16be. This should just refer to those if this is needed at all. ( 版) https://www.w3.org/Bugs/Public/show_bug.cgi?id=24120#c6

[33] Update integration with Encoding Standard · whatwg/html@6a31c26 ( 版) https://github.com/whatwg/html/commit/6a31c26cf12e39dab1a488e75dd56c03d6786d39

[34] Fix #18: remove UTF-16 support from TextEncoder · whatwg/encoding@8360f77 ( 版) https://github.com/whatwg/encoding/commit/8360f775c8df145f649047c7d59c5ff733ade112

[38] Editorial: check non-null before null (annevk著, ) https://github.com/whatwg/encoding/commit/4e53e160b9e0ade6e33a25d21580106a0db2c47f

[39] XLIFF Version 2.0 () http://docs.oasis-open.org/xliff/xliff-core/v2.0/os/xliff-core-v2.0-os.html#d0e15952