MCPcopy Create free account
hub / github.com/buke/quickjs-go / ToStringUTF16

Method ToStringUTF16

value.go:319–333  ·  view source on GitHub ↗

ToStringUTF16 returns the UTF-16 code units of the string representation of the value.

()

Source from the content-addressed store, hash-verified

317
318// ToStringUTF16 returns the UTF-16 code units of the string representation of the value.
319func (v *Value) ToStringUTF16() ([]uint16, error) {
320 if !v.hasValidContext() {
321 return nil, errors.New("value context is not available")
322 }
323
324 length := C.size_t(0)
325 ptr := C.JS_ToCStringLenUTF16(v.ctx.ref, &length, v.ref)
326 if ptr == nil {
327 return nil, v.ctx.Exception()
328 }
329 defer C.JS_FreeCStringUTF16(v.ctx.ref, ptr)
330
331 utf16 := unsafe.Slice((*uint16)(unsafe.Pointer(ptr)), int(length))
332 return append([]uint16(nil), utf16...), nil
333}
334
335// Len returns the length of the array.
336func (v *Value) Len() int64 {

Callers 2

Calls 3

hasValidContextMethod · 0.95
NewMethod · 0.80
ExceptionMethod · 0.80

Tested by 2