MCPcopy Create free account
hub / github.com/ElementsProject/lightning / utf8_encode

Function utf8_encode

ccan/ccan/utf8/utf8.c:136–178  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

134}
135
136size_t utf8_encode(uint32_t point, char dest[UTF8_MAX_LEN])
137{
138 if ((point >> 7) == 0) {
139 if (point == 0) {
140 errno = ERANGE;
141 return 0;
142 }
143 /* 0xxxxxxx */
144 dest[0] = point;
145 return 1;
146 }
147
148 if ((point >> 11) == 0) {
149 /* 110xxxxx 10xxxxxx */
150 dest[1] = 0x80 | (point & 0x3F);
151 dest[0] = 0xC0 | (point >> 6);
152 return 2;
153 }
154
155 if ((point >> 16) == 0) {
156 if (point >= 0xD800 && point <= 0xDFFF) {
157 errno = ERANGE;
158 return 0;
159 }
160 /* 1110xxxx 10xxxxxx 10xxxxxx */
161 dest[2] = 0x80 | (point & 0x3F);
162 dest[1] = 0x80 | ((point >> 6) & 0x3F);
163 dest[0] = 0xE0 | (point >> 12);
164 return 3;
165 }
166
167 if (point > 0x10FFFF) {
168 errno = ERANGE;
169 return 0;
170 }
171
172 /* 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx */
173 dest[3] = 0x80 | (point & 0x3F);
174 dest[2] = 0x80 | ((point >> 6) & 0x3F);
175 dest[1] = 0x80 | ((point >> 12) & 0x3F);
176 dest[0] = 0xF0 | (point >> 18);
177 return 4;
178}

Callers 3

mainFunction · 0.85
mainFunction · 0.85
graphql_lexFunction · 0.85

Calls

no outgoing calls

Tested by 2

mainFunction · 0.68
mainFunction · 0.68