Based on Allegro Unicode code (allegro/src/unicode.c)
| 24 | |
| 25 | // Based on Allegro Unicode code (allegro/src/unicode.c) |
| 26 | static 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 | |
| 65 | std::string string_printf(const char* format, ...) |
| 66 | { |
no outgoing calls
no test coverage detected