History

Better handling of UCNs in strings

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.

Petr Skocik committed 5 years ago

Commit ffb95c21 parent 6b614c42 files · +46 −7Browse files

Showing the changes to tests (1 of 2 files). Show all

Unified · Split

tests/tests2/97_utf8_string_literal.c+8−1
@@ -1,12 +1,19 @@
1// this file contains BMP chars encoded in UTF-81// 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
5int main()7int 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}

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t