1 // { dg-do compile { target c++20 } }
3 #include <format> // includes <bits/unicode.h>
6 #include <testsuite_hooks.h>
8 namespace uc
= std::__unicode
;
9 using namespace std::string_view_literals
;
14 VERIFY(uc::__field_width(u8
"\N{LATIN SMALL LETTER E WITH ACUTE}"sv
) == 1 );
16 auto sv
= u8
"ee\N{COMBINING ACUTE ACCENT}e"sv
;
17 auto data
= sv
.data();
18 VERIFY( uc::__field_width(sv
) == 3 );
19 VERIFY( uc::__truncate(sv
, 3) == 3 );
20 VERIFY( uc::__truncate(sv
, 4) == 3 );
23 VERIFY( uc::__truncate(sv
, 2) == 2 );
24 VERIFY( sv
== u8
"ee\N{COMBINING ACUTE ACCENT}"sv
);
28 VERIFY( uc::__field_width(sv
) == 2 );
29 VERIFY( uc::__truncate(sv
, 3) == 2 );
30 VERIFY( sv
== data
+1 );
32 sv
= u8
"\N{REGIONAL INDICATOR SYMBOL LETTER G}"
33 "\N{REGIONAL INDICATOR SYMBOL LETTER B}"; // GB flag emoji
35 VERIFY( uc::__field_width(sv
) == 1 );
36 VERIFY( uc::__truncate(sv
, 2) == 1 );
38 VERIFY( uc::__truncate(sv
, 1) == 1 ); // Do not break inside a flag emoji.
42 "\N{REGIONAL INDICATOR SYMBOL LETTER G}" // 4 bytes
43 "\N{REGIONAL INDICATOR SYMBOL LETTER B}" // 4 bytes
44 "\N{DEVANAGARI LETTER KA}" // 3 bytes
45 "\N{DEVANAGARI SIGN VIRAMA}" // 3 bytes
46 "\N{DEVANAGARI LETTER RA}" // 3 bytes
47 "\N{MAN}\N{ZERO WIDTH JOINER}" // 4+3 bytes
48 "\N{WOMAN}\N{ZERO WIDTH JOINER}" // 4+3 bytes
49 "\N{GIRL}\N{ZERO WIDTH JOINER}" // 4+3 bytes
50 "\N{BOY}\N{ZERO WIDTH JOINER}" // 4+3 bytes
51 "\N{HANGUL CHOSEONG KIYEOK}" // 3 bytes
52 "\N{HANGUL CHOSEONG KIYEOK}" // 3 bytes
53 "\N{HANGUL CHOSEONG KIYEOK}" // 3 bytes
54 "\N{HANGUL CHOSEONG KIYEOK}" // 3 bytes
55 "\N{HANGUL JUNGSEONG A}" // 3 bytes
56 "\N{HANGUL JONGSEONG KIYEOK}" // 3 bytes
57 "\N{HANGUL JONGSEONG KIYEOK}" // 3 bytes
58 "\N{HANGUL JONGSEONG KIYEOK}"; // 3 bytes
60 uc::_Grapheme_cluster_view
gv(sv
);
61 auto iter
= gv
.begin();
62 VERIFY( iter
.base() == sv
.data() );
63 VERIFY( *iter
== U
'a' );
64 std::ranges::advance(iter
, 3);
65 VERIFY( *iter
== U
'd' );
66 VERIFY( iter
.base() == sv
.data() + 3 );
68 VERIFY( *iter
== U
'\N{REGIONAL INDICATOR SYMBOL LETTER G}' );
69 VERIFY( iter
.base() == sv
.data() + 4 );
71 VERIFY( *iter
== U
'\N{DEVANAGARI LETTER KA}' );
72 VERIFY( iter
.base() == sv
.data() + 4 + 8 );
74 VERIFY( *iter
== U
'\N{MAN}' );
75 VERIFY( iter
.base() == sv
.data() + 4 + 8 + 9 );
77 VERIFY( iter
.base() == sv
.data() + 4 + 8 + 9 + 28 );
78 VERIFY( *iter
== U
'\N{HANGUL CHOSEONG KIYEOK}' );
80 VERIFY( iter
.base() == sv
.data() + 4 + 8 + 9 + 28 + 24 );
81 VERIFY( iter
== gv
.end() );
83 VERIFY( iter
== gv
.end() );
93 VERIFY( run_tests() );
94 static_assert( run_tests() );