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
+5
View File
@@ -0,0 +1,5 @@
IO.print(String.fromCodePoint(65)) // expect: A
IO.print(String.fromCodePoint(164)) // expect: ¤
IO.print(String.fromCodePoint(398)) // expect: Ǝ
IO.print(String.fromCodePoint(8225)) // expect: ‡
IO.print(String.fromCodePoint(0x254b)) // expect: ╋
@@ -0,0 +1 @@
IO.print(String.fromCodePoint(12.34)) // expect runtime error: Code point must be an integer.
@@ -0,0 +1 @@
IO.print(String.fromCodePoint("not num")) // expect runtime error: Code point must be a number.
@@ -0,0 +1,3 @@
// UTF-8 mandates that only values up to 10ffff can be encoded.
// See: http://tools.ietf.org/html/rfc3629
IO.print(String.fromCodePoint(0x10ffff + 1)) // expect runtime error: Code point cannot be greater than 0x10ffff.
@@ -0,0 +1 @@
IO.print(String.fromCodePoint(-1)) // expect runtime error: Code point cannot be negative.