string (Web IDL)

String、文字列 (JavaScript)

目次

  1. String、文字列値 (JavaScript)
    1. Unicode との関係
    2. DOM・WebIDL との関係
    3. 関連
  2. String オブジェクト (JavaScript)
  3. 文字列表記 (JavaScript)
  4. 文字列 (JSON)
  5. メモ

String、文字列値 (JavaScript)#

[1]

A string value is a member of the type String and is a finite ordered sequence of zero or more 16-bit unsigned integer values.

NOTE Although each value usually represents a single 16-bit unit of UTF-16 text, the language does not place any restrictions or requirements on the values except that they be 16-bit unsigned integers.

[2]

The type String is the set of all string values.

Unicode との関係#

[5] >>1 の定義と NOTE より、 UTF-16 として不正な値 (サロゲート・ペアの片割れ) が含まれていたり、 Unicode文字ではない符号位置 (非文字) や文字が割り当てられていない符号位置U+0000 NULL が含まれていても JavaScript 的には構わないことになります。

[6] ただし JavaScript関数すべてで UTF-16 として不適切な値がチェックなしで素通しになるわけではありません。 例えば encodeURIComponent()サロゲート・ペアの片割れが見つかると例外を投げます。

[8] また、明記されていませんが BOM も特別扱いされないことになります。実際上は BOM を使わない UTF-16 符号単位の列として理解・実装されています。 UTF-16符号単位文字列の構成要素として定義されているので、 定義上エンディアン問題は JavaScript プログラム内には持ち込まれていません。文字列に内部的に BOM を持たせる実装は理論上あり得ますが、現実にはそのような実装は複雑になるだけで利点もなく、 存在しないと思います。

DOM・WebIDL との関係#

[7] DOMWebIDL では DOMString に相当します。 JavaScriptUTF-16 を採用していた歴史的経緯もあって DOMStringUTF-16符号単位の列とされています。

関連#

[9] 多くのプログラミング言語に存在する文字列型に相当しますが、各言語とは細部で色々と異なります。

[10] UTF-16符号単位の列である点では JavaString と同じです。

[11] C文字列 (char配列) はバイト列であり、 JavaScript とは大きく異なります。

[12] Perl文字列バイト列または utf8 文字列であり、 JavaScript とは違いがあります。

[13] XPathデータ・モデルstring文字列であり、 JavaScript とは異なります。

String オブジェクト (JavaScript)#

[3]

A String object is a member of the type Object and is an instance of the built-in String object. That is, a String object is created by using the String constructor in a new expression, supplying a string as an argument. The resulting object has an implicit (unnamed) property that is the string. A String object can be coerced to a string value by calling the String constructor as a function (15.5.1).

文字列表記 (JavaScript)#

[4] Kazuho@Cybozu Labs: JavaScript の文字列定数でエスケープが必要な文字 ( 版) http://labs.cybozu.co.jp/blog/kazuho/archives/2006/11/js_string_literal2.php (名無しさん 2007-01-12 14:14:06 +00:00)

文字列 (JSON)#

[15] JSON における文字列 (string) は、0個以上Unicode文字の列です。

メモ#

[16] Slimmer and faster JavaScript strings in Firefox | JavaScript ( 版) https://blog.mozilla.org/javascript/2014/07/21/slimmer-and-faster-javascript-strings-in-firefox/

[18] Issue 2217 - v8 - HTML extensions to String.prototype shouldn’t escape ', < and > in argument values; only " - V8 JavaScript Engine - Google Project Hosting ( ( 版)) http://code.google.com/p/v8/issues/detail?id=2217

[17] Define JavaScript string and scalar value string (annevk著, ) https://github.com/whatwg/infra/commit/f1be763cfba23d2fc780b35403074c599e69616e

[19] Define length for byte sequences and strings (annevk著, ) https://github.com/whatwg/infra/commit/c484a4fe0d7bdc52b0f17ab99e49eaa9e56e3f56

[20] Editorial: let code point and friends be defined by Infra (annevk著, ) https://github.com/whatwg/html/commit/59595d9c2ccadb9332c15048be5d30174532ee70

[21] Remove `String` extensions · whatwg/javascript@b7ade3d ( 版) https://github.com/whatwg/javascript/commit/b7ade3d9ebbb3373aca1303f4f6516c884dc362c

[22] Breaking: refactor structured clone into serialize/deserialize (domenic著, ) https://github.com/whatwg/html/commit/97d644c97335956610a31e8ad98d1a388c063e84

[23] Clarify the interpretation of string literal tokens (Ms2ger著, ) https://github.com/heycam/webidl/commit/1fa8c43d2dc0ade28b79464b95078c7d030d19b9

[24] Defining a ByteString default value using a string literal gives no clear link to the explanation of how the string is converted to ByteString · Issue #141 · heycam/webidl () https://github.com/heycam/webidl/issues/141

[25] Clarify the interpretation of string literal tokens. by Ms2ger · Pull Request #621 · heycam/webidl () https://github.com/heycam/webidl/pull/621