MCPcopy Create free account
hub / github.com/HaxeFoundation/hxcpp / codepoint

Method codepoint

src/cpp/encoding/Encodings.cpp:368–406  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

366}
367
368char32_t cpp::encoding::Utf8::codepoint(const cpp::marshal::View<uint8_t>& buffer)
369{
370 auto b0 = static_cast<char32_t>(buffer[0]);
371
372 if ((b0 & 0x80) == 0)
373 {
374 return b0;
375 }
376 else if ((b0 & 0xE0) == 0xC0)
377 {
378 return (static_cast<char32_t>(b0 & 0x1F) << 6) | static_cast<char32_t>(buffer.slice(1)[0] & 0x3F);
379 }
380 else if ((b0 & 0xF0) == 0xE0)
381 {
382 auto staging = std::array<uint8_t, 2>();
383 auto dst = View<uint8_t>(staging.data(), staging.size());
384
385 buffer.slice(1, staging.size()).copyTo(dst);
386
387 return (static_cast<char32_t>(b0 & 0x0F) << 12) | (static_cast<char32_t>(staging[0] & 0x3F) << 6) | static_cast<char32_t>(staging[1] & 0x3F);
388 }
389 else if ((b0 & 0xF8) == 0xF0)
390 {
391 auto staging = std::array<uint8_t, 3>();
392 auto dst = View<uint8_t>(staging.data(), staging.size());
393
394 buffer.slice(1, staging.size()).copyTo(dst);
395
396 return
397 (static_cast<char32_t>(b0 & 0x07) << 18) |
398 (static_cast<char32_t>(staging[0] & 0x3F) << 12) |
399 (static_cast<char32_t>(staging[1] & 0x3F) << 6) |
400 static_cast<char32_t>(staging[2] & 0x3F);
401 }
402 else
403 {
404 return int{ hx::Throw(HX_CSTRING("Failed to read codepoint")) };
405 }
406}
407
408namespace
409{

Callers

nothing calls this directly

Calls 4

ThrowFunction · 0.85
copyToMethod · 0.80
sliceMethod · 0.45
sizeMethod · 0.45

Tested by

no test coverage detected