MCPcopy Create free account
hub / github.com/fmtlib/fmt / utf8_encode

Function utf8_encode

test/format-impl-test.cc:361–381  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

359}
360
361FMT_CONSTEXPR auto utf8_encode(char* s, uint32_t c) -> char* {
362 if (c >= (1UL << 16)) {
363 s[0] = static_cast<char>(0xf0 | (c >> 18));
364 s[1] = static_cast<char>(0x80 | ((c >> 12) & 0x3f));
365 s[2] = static_cast<char>(0x80 | ((c >> 6) & 0x3f));
366 s[3] = static_cast<char>(0x80 | ((c >> 0) & 0x3f));
367 return s + 4;
368 } else if (c >= (1UL << 11)) {
369 s[0] = static_cast<char>(0xe0 | (c >> 12));
370 s[1] = static_cast<char>(0x80 | ((c >> 6) & 0x3f));
371 s[2] = static_cast<char>(0x80 | ((c >> 0) & 0x3f));
372 return s + 3;
373 } else if (c >= (1UL << 7)) {
374 s[0] = static_cast<char>(0xc0 | (c >> 6));
375 s[1] = static_cast<char>(0x80 | ((c >> 0) & 0x3f));
376 return s + 2;
377 } else {
378 s[0] = static_cast<char>(c);
379 return s + 1;
380 }
381}
382
383// Make sure it can decode every character
384TEST(format_impl_test, utf8_decode_decode_all) {

Callers 1

TESTFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected