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