Skip to content
This repository has been archived by the owner on Apr 25, 2024. It is now read-only.

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
hydroper committed Dec 9, 2023
1 parent 1108cf4 commit 9cfd1de
Show file tree
Hide file tree
Showing 5 changed files with 102 additions and 74 deletions.
56 changes: 29 additions & 27 deletions spec/1.0/live/overview/string-encoding.html
Original file line number Diff line number Diff line change
Expand Up @@ -168,38 +168,40 @@ <h1 class="menu-title">JetWork Language Specification</h1>
<main>
<h1 id="string-encoding"><a class="header" href="#string-encoding">String encoding</a></h1>
<p>The String data type uses an implementation-defined encoding and is supported by a <code>CharIndex</code> data type representing an index into a <code>String</code>.</p>
<pre><code>// String variable
const string1 = &quot;jetwork&quot;;

// Slice from second character
const string2 = string1.substring(string1.firstIndex.next(1));

// &quot;jet&quot;
trace(string1.slice(0, string1.firstIndex.next(3)));
trace(string1.slice(0, string1.lastIndex.next(-4)));

// Character count
trace(string1.chars().length());

// Character count between i and j
trace(string1.slice(i, j).chars().length());

// Whether the string is empty or not
trace(string1.isEmpty);
<h2 id="slicing"><a class="header" href="#slicing">Slicing</a></h2>
<p>Slice from second character:</p>
<pre><code>const string2 = &quot;jetwork&quot;.substring(&quot;jetwork&quot;.firstIndex.next(1));
</code></pre>
<p>First three characters:</p>
<pre><code>trace(&quot;jetwork&quot;.slice(0, &quot;jetwork&quot;.firstIndex.next(3)));
trace(&quot;jetwork&quot;.slice(0, &quot;jetwork&quot;.lastIndex.next(-4)));
</code></pre>
<h2 id="characters"><a class="header" href="#characters">Characters</a></h2>
<p>Character count:</p>
<pre><code>trace(string1.chars().length());
</code></pre>
<p>Character count between <em>i</em> and <em>j</em>:</p>
<pre><code>trace(string1.slice(i, j).chars().length());
</code></pre>
<p>Whether the string is empty or not:</p>
<pre><code>trace(string1.isEmpty);
trace(string1 == &quot;&quot;);

// Scalar Value at i
const character = string1.charAt(i);

// For each character
for each (const character in string1) {}
</code></pre>
<p>The following is the string length in the encoding units.</p>
<p>The following is the string length in the encoding units:</p>
<ul>
<li>For the UTF-8 encoding, this is the number of bytes.</li>
<li>For the UTF-16 encoding, this is the number of UCS-2 units.</li>
<li>for the UTF-8 encoding, the following is the number of bytes;</li>
<li>for the UTF-16 encoding, the following is the number of UCS-2 units;</li>
</ul>
<pre><code>trace(string1.length);
</code></pre>
<h2 id="miscellaneous"><a class="header" href="#miscellaneous">Miscellaneous</a></h2>
<p>Scalar value at <em>i</em>:</p>
<pre><code>const char: Char = string1.charAt(i);
</code></pre>
<p>For each Scalar Value:</p>
<pre><code>for each (const char in string1) {
/* char: Char */
}
</code></pre>

</main>
Expand Down
56 changes: 29 additions & 27 deletions spec/1.0/live/print.html
Original file line number Diff line number Diff line change
Expand Up @@ -217,39 +217,41 @@ <h2 id="number-overflow"><a class="header" href="#number-overflow">Number overfl
<p>Operations whose result cannot be represented due to range limit cause a number overflow, such as <code>Int.MAX_VALUE + 1</code>. The result of a number overflow is implementation defined.</p>
<div style="break-before: page; page-break-before: always;"></div><h1 id="string-encoding"><a class="header" href="#string-encoding">String encoding</a></h1>
<p>The String data type uses an implementation-defined encoding and is supported by a <code>CharIndex</code> data type representing an index into a <code>String</code>.</p>
<pre><code>// String variable
const string1 = &quot;jetwork&quot;;

// Slice from second character
const string2 = string1.substring(string1.firstIndex.next(1));

// &quot;jet&quot;
trace(string1.slice(0, string1.firstIndex.next(3)));
trace(string1.slice(0, string1.lastIndex.next(-4)));

// Character count
trace(string1.chars().length());

// Character count between i and j
trace(string1.slice(i, j).chars().length());

// Whether the string is empty or not
trace(string1.isEmpty);
<h2 id="slicing"><a class="header" href="#slicing">Slicing</a></h2>
<p>Slice from second character:</p>
<pre><code>const string2 = &quot;jetwork&quot;.substring(&quot;jetwork&quot;.firstIndex.next(1));
</code></pre>
<p>First three characters:</p>
<pre><code>trace(&quot;jetwork&quot;.slice(0, &quot;jetwork&quot;.firstIndex.next(3)));
trace(&quot;jetwork&quot;.slice(0, &quot;jetwork&quot;.lastIndex.next(-4)));
</code></pre>
<h2 id="characters"><a class="header" href="#characters">Characters</a></h2>
<p>Character count:</p>
<pre><code>trace(string1.chars().length());
</code></pre>
<p>Character count between <em>i</em> and <em>j</em>:</p>
<pre><code>trace(string1.slice(i, j).chars().length());
</code></pre>
<p>Whether the string is empty or not:</p>
<pre><code>trace(string1.isEmpty);
trace(string1 == &quot;&quot;);

// Scalar Value at i
const character = string1.charAt(i);

// For each character
for each (const character in string1) {}
</code></pre>
<p>The following is the string length in the encoding units.</p>
<p>The following is the string length in the encoding units:</p>
<ul>
<li>For the UTF-8 encoding, this is the number of bytes.</li>
<li>For the UTF-16 encoding, this is the number of UCS-2 units.</li>
<li>for the UTF-8 encoding, the following is the number of bytes;</li>
<li>for the UTF-16 encoding, the following is the number of UCS-2 units;</li>
</ul>
<pre><code>trace(string1.length);
</code></pre>
<h2 id="miscellaneous"><a class="header" href="#miscellaneous">Miscellaneous</a></h2>
<p>Scalar value at <em>i</em>:</p>
<pre><code>const char: Char = string1.charAt(i);
</code></pre>
<p>For each Scalar Value:</p>
<pre><code>for each (const char in string1) {
/* char: Char */
}
</code></pre>
<div style="break-before: page; page-break-before: always;"></div><h1 id="exceptions"><a class="header" href="#exceptions">Exceptions</a></h1>
<p>JetWork supports checked exceptions and fatal exceptions. Fatal exceptions are not caught by user code in JetWork.</p>
<pre><code>function task(): void throws RangeError {
Expand Down
2 changes: 1 addition & 1 deletion spec/1.0/live/searchindex.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion spec/1.0/live/searchindex.json

Large diffs are not rendered by default.

60 changes: 42 additions & 18 deletions spec/1.0/source/src/overview/string-encoding.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,63 @@

The String data type uses an implementation-defined encoding and is supported by a `CharIndex` data type representing an index into a `String`.

## Slicing

Slice from second character:

```
const string2 = "jetwork".substring("jetwork".firstIndex.next(1));
```

First three characters:

```
trace("jetwork".slice(0, "jetwork".firstIndex.next(3)));
trace("jetwork".slice(0, "jetwork".lastIndex.next(-4)));
```
// String variable
const string1 = "jetwork";

// Slice from second character
const string2 = string1.substring(string1.firstIndex.next(1));
## Characters

// "jet"
trace(string1.slice(0, string1.firstIndex.next(3)));
trace(string1.slice(0, string1.lastIndex.next(-4)));
Character count:

// Character count
```
trace(string1.chars().length());
```

// Character count between i and j
Character count between *i* and *j*:

```
trace(string1.slice(i, j).chars().length());
```

// Whether the string is empty or not
Whether the string is empty or not:

```
trace(string1.isEmpty);
trace(string1 == "");
```

// Scalar Value at i
const character = string1.charAt(i);
The following is the string length in the encoding units:

// For each character
for each (const character in string1) {}
- for the UTF-8 encoding, the following is the number of bytes;
- for the UTF-16 encoding, the following is the number of UCS-2 units;

```
trace(string1.length);
```

The following is the string length in the encoding units.
## Miscellaneous

- For the UTF-8 encoding, this is the number of bytes.
- For the UTF-16 encoding, this is the number of UCS-2 units.
Scalar value at *i*:

```
trace(string1.length);
const char: Char = string1.charAt(i);
```

For each Scalar Value:

```
for each (const char in string1) {
/* char: Char */
}
```

0 comments on commit 9cfd1de

Please sign in to comment.