@@ -289,9 +289,9 @@ number of code units represent these sizes as unsigned values.
289289
290290```
291291(string.measure_wtf8 $wtf8_policy str:stringref)
292- -> bytes :i32
292+ -> codeunits :i32
293293(string.measure_wtf16 str:stringref)
294- -> bytes :i32
294+ -> codeunits :i32
295295```
296296Measure the number of code units that would be required to encode the
297297contents of the string * ` str ` * to WTF-8 or WTF-16 respectively.
@@ -305,11 +305,13 @@ require more code units than the limit, the result is -1.
305305
306306```
307307(string.encode_wtf8 $memory $wtf8_policy str:stringref ptr:address)
308+ -> codeunits:i32
308309(string.encode_wtf16 $memory str:stringref ptr:address)
310+ -> codeunits:i32
309311```
310312Encode the contents of the string * ` str ` * as UTF-8, WTF-8, or WTF-16,
311- respectively, to memory at * ` ptr ` * . The number of code units written
312- will be the same as returned by the corresponding
313+ respectively, to memory at * ` ptr ` * . Return the number of code units
314+ written, which will be the same as returned by the corresponding
313315` string.measure_*encoding* ` .
314316
315317Each code unit is written to memory as if stored by ` i32.store8 ` or
@@ -564,8 +566,8 @@ stringrefs ::= section_14(0x00 vec(vec(u8)))
564566
565567## Examples
566568
567- We assume that the textual syntax for ` string.encode ` and ` string.new `
568- allows you to elide the memory, in which case it defaults to 0.
569+ We assume that the textual syntax for instructions that take a memory
570+ operand allows you to elide the memory, in which case it defaults to 0.
569571
570572### Make string from NUL-terminated UTF-8 in memory
571573
@@ -809,10 +811,9 @@ open to considering adding more instructions.
809811
810812 local.get $str
811813 local.get $ptr
812- string.encode_wtf8 wtf8
814+ string.encode_wtf8 wtf8 ;; push bytes written, same as $len
813815
814816 local.get $ptr
815- local.get $len
816817 i32.add
817818 i32.const 0
818819 i32.store8 ;; write NUL
0 commit comments