As the standard requires, take 4 hex digits after the \u opener of a Universal Character Name, or take 8 hex digits after \U, but reject smaller counts and don't consume more (https://port70.net/~nsz/c/c11/n1570.html#6.4.3, https://port70.net/~nsz/c/c99/n1256.html#6.4.3). The unicode codepoint used to get truncated to 1 byte. Now it gets expanded into UTF-8, matching gcc & clang behavior on Linux.
Showing the changes to tests (1 of 2 files). Show all
Unified · Split
| @@ -1,12 +1,19 @@ | |||
| 1 | // this file contains BMP chars encoded in UTF-8 | 1 | // this file contains BMP chars encoded in UTF-8 |
| 2 | #include <stdio.h> | 2 | #include <stdio.h> |
| 3 | #include <wchar.h> | 3 | #include <wchar.h> |
| 4 | #include <stdlib.h> | ||
| 5 | #include <string.h> | ||
| 4 | 6 | ||
| 5 | int main() | 7 | int main() |
| 6 | { | 8 | { |
| 9 | char hello_world_in_czech[] = "čau, světe"; | ||
| 10 | char hello_world_in_czech_ucn[] = "\u010dau, sv\u011bte"; | ||
| 11 | if (sizeof(hello_world_in_czech) != sizeof(hello_world_in_czech_ucn) | ||
| 12 | || strcmp(hello_world_in_czech, hello_world_in_czech_ucn)) | ||
| 13 | abort(); | ||
| 14 | |||
| 7 | wchar_t s[] = L"hello$$你好¢¢世界€€world"; | 15 | wchar_t s[] = L"hello$$你好¢¢世界€€world"; |
| 8 | wchar_t *p; | 16 | wchar_t *p; |
| 9 | for (p = s; *p; p++) printf("%04X ", (unsigned) *p); | 17 | for (p = s; *p; p++) printf("%04X ", (unsigned) *p); |
| 10 | printf("\n"); | ||
| 11 | return 0; | 18 | return 0; |
| 12 | } | 19 | } |