def encode.char

bolt@1.27.0.0 · src/lsp/frame.bend:68

import bolt@1.27.0.0/src/lsp/frame.bend as Frame
import Base

68# a code point's bytes, by its width, in front of the rest
69def encode.char(ww: U32, +xx: U32, rest: List<&2, U32>) -> List<&2, U32>:
70  match ww:
71    case 1:
72      xx <> rest
73    case 2:
74      (192 .|. (xx >> 6n) : U32) <> (128 .|. (xx .&. 63) : U32) <> rest
75    case 3:
76      (224 .|. (xx >> 12n) : U32) <> (128 .|. ((xx >> 6n) .&. 63) : U32) <> (128 .|. (xx .&. 63) : U32) <> rest
77    case other:
78      (240 .|. (xx >> 18n) : U32) <> (128 .|. ((xx >> 12n) .&. 63) : U32) <> (128 .|. ((xx >> 6n) .&. 63) : U32)
79        <> (128 .|. (xx .&. 63) : U32) <> rest

Uses (8)

Used by (1)