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
+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 π.