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)
| 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. |
| 344 | func 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 | } |
searching dependent graphs…