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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user