| ... | @@ -654,17 +654,14 @@ pub fn formatUnicodeCodepoint( | ... | @@ -654,17 +654,14 @@ pub fn formatUnicodeCodepoint( |
| 654 | options: FormatOptions, | 654 | options: FormatOptions, |
| 655 | writer: anytype, | 655 | writer: anytype, |
| 656 | ) !void { | 656 | ) !void { |
| 657 | if (unicode.utf8ValidCodepoint(c)) { | 657 | var buf: [4]u8 = undefined; |
| 658 | var buf: [4]u8 = undefined; | 658 | const len = std.unicode.utf8Encode(c, &buf) catch |err| switch (err) { |
| 659 | // The codepoint is surely valid, hence the use of unreachable | 659 | error.Utf8CannotEncodeSurrogateHalf, error.CodepointTooLarge => { |
| 660 | const len = std.unicode.utf8Encode(c, &buf) catch |err| switch (err) { | 660 | // In case of error output the replacement char U+FFFD |
| 661 | error.Utf8CannotEncodeSurrogateHalf, error.CodepointTooLarge => unreachable, | 661 | return formatBuf(&[_]u8{ 0xef, 0xbf, 0xbd }, options, writer); |
| 662 | }; | 662 | }, |
| 663 | return formatBuf(buf[0..len], options, writer); | 663 | }; |
| 664 | } | 664 | return formatBuf(buf[0..len], options, writer); |
| 665 | | | |
| 666 | // In case of error output the replacement char U+FFFD | | |
| 667 | return formatBuf(&[_]u8{ 0xef, 0xbf, 0xbd }, options, writer); | | |
| 668 | } | 665 | } |
| 669 | | 666 | |
| 670 | pub fn formatBuf( | 667 | pub fn formatBuf( |