MCPcopy Create free account
hub / github.com/diasurgical/DevilutionX / DecodeFirstUtf8CodePoint

Function DecodeFirstUtf8CodePoint

Source/utils/utf8.cpp:13–30  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

11namespace devilution {
12
13char32_t DecodeFirstUtf8CodePoint(string_view input, std::size_t *len)
14{
15 uint32_t codepoint = 0;
16 uint8_t state = UTF8_ACCEPT;
17 for (std::size_t i = 0; i < input.size(); ++i) {
18 state = utf8_decode_step(state, static_cast<uint8_t>(input[i]), &codepoint);
19 if (state == UTF8_ACCEPT) {
20 *len = i + 1;
21 return codepoint;
22 }
23 if (state == UTF8_REJECT) {
24 *len = i + 1;
25 return Utf8DecodeError;
26 }
27 }
28 *len = input.size();
29 return Utf8DecodeError;
30}
31
32string_view TruncateUtf8(string_view str, std::size_t len)
33{

Callers 5

DoDrawStringFunction · 0.85
GetLineWidthFunction · 0.85
WordWrapStringFunction · 0.85
DrawStringWithColorsFunction · 0.85

Calls 2

utf8_decode_stepFunction · 0.85
sizeMethod · 0.45

Tested by

no test coverage detected