Skip to content

byte sequence <> string #146

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Aug 15, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions infra.bs
Original file line number Diff line number Diff line change
Expand Up @@ -297,8 +297,9 @@ confusion with an actual <a>string</a>.
<p>Headers, such as `<code>Content-Type</code>`, are <a>byte sequences</a>.
</div>

<p class=note>To get a <a>byte sequence</a> out of a <a>string</a>, use an operation such as
<a>UTF-8 encode</a> from the Encoding Standard. [[ENCODING]]
<p class=note>To get a <a>byte sequence</a> out of a <a>string</a>, using <a>UTF-8 encode</a> from
the Encoding Standard is encouraged. In rare circumstances <a>isomorphic encode</a> might be needed.
[[ENCODING]]

<p>A <a>byte sequence</a>'s <dfn export for="byte sequence">length</dfn> is the number of
<a>bytes</a> it contains.
Expand All @@ -313,6 +314,11 @@ contains, in the range 0x61 (a) to 0x7A (z), inclusive, by 0x20.
<a>byte sequence</a> <var>B</var>, if the <a>byte-lowercase</a> of <var>A</var> is the
<a>byte-lowercase</a> of <var>B</var>.

<p>To <dfn export>isomorphic decode</dfn> a <a>byte sequence</a> <var>input</var>, return a
<a>string</a> whose <a for=string>length</a> is equal to <var>input</var>'s
<a for="byte sequence">length</a> and whose <a>code points</a> have the same values as
<var>input</var>'s <a>bytes</a>, in the same order.

<h3 id=code-points>Code points</h3>

<p>A <dfn export lt="code point|character">code point</dfn> is a Unicode code point and is
Expand Down Expand Up @@ -450,6 +456,18 @@ implementations of just <a>JavaScript strings</a> for performance and memory rea

<hr>

<p>To <dfn export>isomorphic encode</dfn> a <a>string</a> <var>input</var>, run these steps:</p>

<ol>
<li><p>Assert: <var>input</var> contains no <a>code points</a> greater than U+00FF.

<li><p>Return a <a>byte sequence</a> whose <a for="byte sequence">length</a> is equal to
<var>input</var>'s <a for=string>length</a> and whose <a>bytes</a> have the same values as
<var>input</var>'s <a>code points</a>, in the same order.
</ol>

<hr>

<p>An <dfn export>ASCII string</dfn> is a <a>string</a> whose <a>code points</a> are all
<a>ASCII code points</a>.

Expand Down