MCPcopy Create free account
hub / github.com/aseprite/laf / insert_utf8_char

Function insert_utf8_char

base/string.cpp:26–63  ·  view source on GitHub ↗

Based on Allegro Unicode code (allegro/src/unicode.c)

Source from the content-addressed store, hash-verified

24
25// Based on Allegro Unicode code (allegro/src/unicode.c)
26static std::size_t insert_utf8_char(const codepoint_t chr, std::string* result = nullptr)
27{
28 int size, bits, b, i;
29
30 if (chr < 128) {
31 if (result)
32 result->push_back(chr);
33 return 1;
34 }
35
36 bits = 7;
37 while (chr >= (1 << bits))
38 bits++;
39
40 size = 2;
41 b = 11;
42
43 while (b < bits) {
44 size++;
45 b += 5;
46 }
47
48 if (result) {
49 b -= (7 - size);
50 int firstbyte = chr >> b;
51 for (i = 0; i < size; i++)
52 firstbyte |= (0x80 >> i);
53
54 result->push_back(firstbyte);
55
56 for (i = 1; i < size; i++) {
57 b -= 6;
58 result->push_back(0x80 | ((chr >> b) & 0x3F));
59 }
60 }
61
62 return size;
63}
64
65std::string string_printf(const char* format, ...)
66{

Callers 2

codepoint_to_utf8Function · 0.85
to_utf8Function · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected