feat: add String.fromCodePoint static method and refactor UTF-8 encoding into reusable utilities

Implement the `String.fromCodePoint(_)` primitive that creates a string from a Unicode code point, with validation for integer range 0–0x10ffff. Extract inline UTF-8 encoding logic from `readUnicodeEscape` in the compiler into new `wrenUtf8NumBytes` and `wrenUtf8Encode` utility functions in `wren_utils`, and add `wrenStringFromCodePoint` helper in `wren_value`. Update documentation for core classes to add "Methods" and "Static Methods" section headers, and include `String.fromCodePoint` docs with example. Add a test file `from_code_point.wren` covering various code points.
This commit is contained in:
Bob Nystrom
2015-03-27 14:43:36 +00:00
parent 6ff60a8c4a
commit b7904a89c9
23 changed files with 166 additions and 43 deletions
+2
View File
@@ -3,6 +3,8 @@
Boolean values. There are two instances, `true` and `false`.
## Methods
### **!** operator
Returns the logical complement of the value.
+2
View File
@@ -1,6 +1,8 @@
^title Class Class
^category core
## Methods
### **name**
The name of the class.
+4
View File
@@ -13,6 +13,8 @@ fiber is run. Does not immediately start running the fiber.
IO.print("I won't get printed")
}
## Static Methods
### Fiber.**current**
The currently executing fiber.
@@ -69,6 +71,8 @@ Similar to `Fiber.yield` but provides a value to return to the parent fiber's
IO.print(fiber.call()) // "value"
## Methods
### **call**()
**TODO**
+2
View File
@@ -18,6 +18,8 @@ argument](../functions.html#block-arguments) to some other method.
It is a runtime error if `function` is not a function.
## Methods
### **arity**
The number of arguments the function requires.
+2
View File
@@ -5,6 +5,8 @@ Extends [Sequence](sequence.html).
An indexable contiguous collection of elements. More details [here](../lists.html).
## Methods
### **add**(item)
Appends `item` to the end of the list.
+2
View File
@@ -3,6 +3,8 @@
An associative collection that maps keys to values. More details [here](../maps.html).
## Methods
### **clear**()
Removes all entries from the map.
+2
View File
@@ -1,6 +1,8 @@
^title Null Class
^category core
## Methods
### **!** operator
Returns `true`, since `null` is considered [false](../control-flow.html#truth).
+15 -11
View File
@@ -1,6 +1,21 @@
^title Num Class
^category core
## Static Methods
### Num.**fromString**(value)
Attempts to parse `value` as a decimal literal and return it as an instance of
`Num`. If the number cannot be parsed `null` will be returned.
It is a runtime error if `value` is not a string.
### Num.**pi**
The value of π.
## Methods
### **abs**
The absolute value of the number.
@@ -131,14 +146,3 @@ from the beginning number to the ending number not including the ending number.
IO.print(range.min) // 1.2
IO.print(range.max) // 3.4
IO.print(range.isInclusive) // false
### Num.**fromString**(value)
Attempts to parse `value` as a decimal literal and return it as an instance of
`Num`. If the number cannot be parsed `null` will be returned.
It is a runtime error if `value` is not a string.
### Num.**pi**
The value of π.
+2
View File
@@ -1,6 +1,8 @@
^title Object Class
^category core
## Methods
### **!** operator
Returns `false`, since most objects are considered [true](control-flow.html#truth).
+2
View File
@@ -5,6 +5,8 @@
Extends [Sequence](sequence.html).
## Methods
### **from**
**TODO**
+2
View File
@@ -6,6 +6,8 @@ core [iterator protocol][] can extend this to get a number of helpful methods.
[iterator protocol]: ../control-flow.html#the-iterator-protocol
## Methods
### **all**(predicate)
Tests whether all the elements in the sequence pass the `predicate`.
+12
View File
@@ -31,6 +31,18 @@ on string *return* byte indices too. So, for example, this does what you want:
In general, methods on strings will work in terms of code units if they can do
so efficiently, and will otherwise deal in bytes.
## Static Methods
### String.**fromCodePoint**(codePoint)
Creates a new string containing the UTF-8 encoding of `codePoint`.
It is a runtime error if `codePoint` is not an integer between `0` and
`0x10ffff`, inclusive.
:::dart
String.fromCodePoint(8225) // "‡"
## Methods
### **contains**(other)