MCPcopy Create free account
hub / github.com/dop251/goja / StringFromUTF16

Function StringFromUTF16

string.go:344–364  ·  view source on GitHub ↗

StringFromUTF16 creates a string value from an array of UTF-16 code units. The result is a copy, so the initial slice can be modified after calling this function (but it must not be modified while the function is running). No validation of any kind is performed.

(chars []uint16)

Source from the content-addressed store, hash-verified

342// slice can be modified after calling this function (but it must not be modified while the function is running).
343// No validation of any kind is performed.
344func StringFromUTF16(chars []uint16) String {
345 isAscii := true
346 for _, c := range chars {
347 if c >= utf8.RuneSelf {
348 isAscii = false
349 break
350 }
351 }
352 if isAscii {
353 var sb strings.Builder
354 sb.Grow(len(chars))
355 for _, c := range chars {
356 sb.WriteByte(byte(c))
357 }
358 return asciiString(sb.String())
359 }
360 buf := make([]uint16, len(chars)+1)
361 buf[0] = unistring.BOM
362 copy(buf[1:], chars)
363 return unicodeString(buf)
364}

Callers 1

TestStringFromUTF16Function · 0.85

Calls 4

asciiStringTypeAlias · 0.85
unicodeStringTypeAlias · 0.85
StringMethod · 0.65
GrowMethod · 0.45

Tested by 1

TestStringFromUTF16Function · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…