| 1219 | } |
| 1220 | |
| 1221 | utf8_int8_t *utf8catcodepoint(utf8_int8_t *str, utf8_int32_t chr, size_t n) { |
| 1222 | if (0 == ((utf8_int32_t)0xffffff80 & chr)) { |
| 1223 | // 1-byte/7-bit ascii |
| 1224 | // (0b0xxxxxxx) |
| 1225 | if (n < 1) { |
| 1226 | return utf8_null; |
| 1227 | } |
| 1228 | str[0] = (utf8_int8_t)chr; |
| 1229 | str += 1; |
| 1230 | } else if (0 == ((utf8_int32_t)0xfffff800 & chr)) { |
| 1231 | // 2-byte/11-bit utf8 code point |
| 1232 | // (0b110xxxxx 0b10xxxxxx) |
| 1233 | if (n < 2) { |
| 1234 | return utf8_null; |
| 1235 | } |
| 1236 | str[0] = (utf8_int8_t)(0xc0 | (utf8_int8_t)((chr >> 6) & 0x1f)); |
| 1237 | str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); |
| 1238 | str += 2; |
| 1239 | } else if (0 == ((utf8_int32_t)0xffff0000 & chr)) { |
| 1240 | // 3-byte/16-bit utf8 code point |
| 1241 | // (0b1110xxxx 0b10xxxxxx 0b10xxxxxx) |
| 1242 | if (n < 3) { |
| 1243 | return utf8_null; |
| 1244 | } |
| 1245 | str[0] = (utf8_int8_t)(0xe0 | (utf8_int8_t)((chr >> 12) & 0x0f)); |
| 1246 | str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); |
| 1247 | str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); |
| 1248 | str += 3; |
| 1249 | } else { // if (0 == ((int)0xffe00000 & chr)) { |
| 1250 | // 4-byte/21-bit utf8 code point |
| 1251 | // (0b11110xxx 0b10xxxxxx 0b10xxxxxx 0b10xxxxxx) |
| 1252 | if (n < 4) { |
| 1253 | return utf8_null; |
| 1254 | } |
| 1255 | str[0] = (utf8_int8_t)(0xf0 | (utf8_int8_t)((chr >> 18) & 0x07)); |
| 1256 | str[1] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 12) & 0x3f)); |
| 1257 | str[2] = (utf8_int8_t)(0x80 | (utf8_int8_t)((chr >> 6) & 0x3f)); |
| 1258 | str[3] = (utf8_int8_t)(0x80 | (utf8_int8_t)(chr & 0x3f)); |
| 1259 | str += 4; |
| 1260 | } |
| 1261 | |
| 1262 | return str; |
| 1263 | } |
| 1264 | |
| 1265 | utf8_constexpr14_impl int utf8islower(utf8_int32_t chr) { |
| 1266 | return chr != utf8uprcodepoint(chr); |
no outgoing calls
no test coverage detected