File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -479,7 +479,7 @@ IndexedUTF32String IndexUTF8ToUTF32(std::string_view input)
479479 auto p0 = (uint32_t )b[0 ] & 0b111 ;
480480 auto p1 = (uint32_t )b[1 ] & 0b11'1111 ;
481481 auto p2 = (uint32_t )b[2 ] & 0b11'1111 ;
482- auto p3 = (uint32_t )b[2 ] & 0b11'1111 ;
482+ auto p3 = (uint32_t )b[3 ] & 0b11'1111 ;
483483 codepoint = p0 << 18 | p1 << 12 | p2 << 6 | p3;
484484 byteIdx += 4 ;
485485 }
Original file line number Diff line number Diff line change @@ -281,7 +281,13 @@ void sys_console_c::Print(std::u32string_view string_view_text)
281281 // Skip colour escapes
282282 b+= escLen - 1 ;
283283 } else {
284- len++;
284+ if (text[b] > UINT16_MAX ) {
285+ // Higher codepoints will be separated into surrogate pairs
286+ len += 2 ;
287+ }
288+ else {
289+ len++;
290+ }
285291 }
286292 }
287293
@@ -298,7 +304,16 @@ void sys_console_c::Print(std::u32string_view string_view_text)
298304 b+= escLen - 1 ;
299305 } else {
300306 // Add character
301- *(p++) = (char16_t )text[b];
307+ if (text[b] > UINT16_MAX ) { // Outside the BMP
308+ char16_t high_surrogate = ((text[b] - 0x10000 ) / 0x400 ) + 0xD800 ;
309+ char16_t low_surrogate = ((text[b] - 0x10000 ) % 0x400 ) + 0xDC00 ;
310+ *(p++) = high_surrogate;
311+ *(p++) = low_surrogate;
312+ }
313+ else {
314+ *(p++) = (char16_t )text[b];
315+ }
316+
302317 }
303318 }
304319 winText[len] = 0 ;
You can’t perform that action at this time.
0 commit comments