12
12
#include < filesystem>
13
13
#endif // CLI11_HAS_FILESYSTEM
14
14
15
- // "Hello Halló Привет 你好 👩🚀❤️"
16
- static const uint8_t utf8_codeunits[] = {0x48 , 0x65 , 0x6c , 0x6c , 0x6f , 0x20 , 0x48 , 0x61 , 0x6c , 0x6c , 0xc3 , 0xb3 , 0x20 ,
17
- 0xd0 , 0x9f , 0xd1 , 0x80 , 0xd0 , 0xb8 , 0xd0 , 0xb2 , 0xd0 , 0xb5 , 0xd1 , 0x82 , 0x20 ,
18
- 0xe4 , 0xbd , 0xa0 , 0xe5 , 0xa5 , 0xbd , 0x20 , 0xf0 , 0x9f , 0x91 , 0xa9 , 0xe2 , 0x80 ,
19
- 0x8d , 0xf0 , 0x9f , 0x9a , 0x80 , 0xe2 , 0x9d , 0xa4 , 0xef , 0xb8 , 0x8f };
20
- static const std::string str (reinterpret_cast <const char *>(utf8_codeunits),
21
- sizeof(utf8_codeunits) / sizeof(utf8_codeunits[0 ]));
15
+ // "abcd"
16
+ static const std::string abcd_str = " abcd" ; // NOLINT(runtime/string)
17
+ static const std::wstring abcd_wstr = L" abcd" ; // NOLINT(runtime/string)
18
+
19
+ // "𓂀𓂀𓂀" - 4-byte utf8 characters
20
+ static const uint8_t egypt_utf8_codeunits[] = {0xF0 , 0x93 , 0x82 , 0x80 , 0xF0 , 0x93 , 0x82 , 0x80 , 0xF0 , 0x93 , 0x82 , 0x80 };
21
+ static const std::string egypt_str (reinterpret_cast <const char *>(egypt_utf8_codeunits),
22
+ sizeof(egypt_utf8_codeunits) / sizeof(egypt_utf8_codeunits[0 ]));
23
+
24
+ #ifdef _WIN32
25
+ static const uint16_t egypt_utf16_codeunits[] = {0xD80C , 0xDC80 , 0xD80C , 0xDC80 , 0xD80C , 0xDC80 };
26
+ static const std::wstring egypt_wstr (reinterpret_cast <const wchar_t *>(egypt_utf16_codeunits),
27
+ sizeof(egypt_utf16_codeunits) / sizeof(egypt_utf16_codeunits[0 ]));
28
+
29
+ #else
30
+ static const uint32_t egypt_utf32_codeunits[] = {0x00013080 , 0x00013080 , 0x00013080 };
31
+ static const std::wstring egypt_wstr (reinterpret_cast <const wchar_t *>(egypt_utf32_codeunits),
32
+ sizeof(egypt_utf32_codeunits) / sizeof(egypt_utf32_codeunits[0 ]));
33
+
34
+ #endif
35
+
36
+ // "Hello Halló Привет 你好 👩🚀❤️" - many languages and complex emojis
37
+ static const uint8_t hello_utf8_codeunits[] = {
38
+ 0x48 , 0x65 , 0x6c , 0x6c , 0x6f , 0x20 , 0x48 , 0x61 , 0x6c , 0x6c , 0xc3 , 0xb3 , 0x20 , 0xd0 , 0x9f , 0xd1 , 0x80 ,
39
+ 0xd0 , 0xb8 , 0xd0 , 0xb2 , 0xd0 , 0xb5 , 0xd1 , 0x82 , 0x20 , 0xe4 , 0xbd , 0xa0 , 0xe5 , 0xa5 , 0xbd , 0x20 , 0xf0 ,
40
+ 0x9f , 0x91 , 0xa9 , 0xe2 , 0x80 , 0x8d , 0xf0 , 0x9f , 0x9a , 0x80 , 0xe2 , 0x9d , 0xa4 , 0xef , 0xb8 , 0x8f };
41
+ static const std::string hello_str (reinterpret_cast <const char *>(hello_utf8_codeunits),
42
+ sizeof(hello_utf8_codeunits) / sizeof(hello_utf8_codeunits[0 ]));
22
43
23
44
#ifdef _WIN32
24
- static const uint16_t utf16_codeunits [] = {0x0048 , 0x0065 , 0x006c , 0x006c , 0x006f , 0x0020 , 0x0048 , 0x0061 ,
25
- 0x006c , 0x006c , 0x00f3 , 0x0020 , 0x041f , 0x0440 , 0x0438 , 0x0432 ,
26
- 0x0435 , 0x0442 , 0x0020 , 0x4f60 , 0x597d , 0x0020 , 0xd83d , 0xdc69 ,
27
- 0x200d , 0xd83d , 0xde80 , 0x2764 , 0xfe0f };
28
- static const std::wstring wstr (reinterpret_cast <const wchar_t *>(utf16_codeunits ),
29
- sizeof(utf16_codeunits ) / sizeof(utf16_codeunits [0 ]));
45
+ static const uint16_t hello_utf16_codeunits [] = {0x0048 , 0x0065 , 0x006c , 0x006c , 0x006f , 0x0020 , 0x0048 , 0x0061 ,
46
+ 0x006c , 0x006c , 0x00f3 , 0x0020 , 0x041f , 0x0440 , 0x0438 , 0x0432 ,
47
+ 0x0435 , 0x0442 , 0x0020 , 0x4f60 , 0x597d , 0x0020 , 0xd83d , 0xdc69 ,
48
+ 0x200d , 0xd83d , 0xde80 , 0x2764 , 0xfe0f };
49
+ static const std::wstring hello_wstr (reinterpret_cast <const wchar_t *>(hello_utf16_codeunits ),
50
+ sizeof(hello_utf16_codeunits ) / sizeof(hello_utf16_codeunits [0 ]));
30
51
31
52
#else
32
- static const uint32_t utf32_codeunits [] = {
53
+ static const uint32_t hello_utf32_codeunits [] = {
33
54
0x00000048 , 0x00000065 , 0x0000006c , 0x0000006c , 0x0000006f , 0x00000020 , 0x00000048 , 0x00000061 , 0x0000006c ,
34
55
0x0000006c , 0x000000f3 , 0x00000020 , 0x0000041f , 0x00000440 , 0x00000438 , 0x00000432 , 0x00000435 , 0x00000442 ,
35
56
0x00000020 , 0x00004f60 , 0x0000597d , 0x00000020 , 0x0001f469 , 0x0000200d , 0x0001f680 , 0x00002764 , 0x0000fe0f };
36
- static const std::wstring wstr (reinterpret_cast <const wchar_t *>(utf32_codeunits ),
37
- sizeof(utf32_codeunits ) / sizeof(utf32_codeunits [0 ]));
57
+ static const std::wstring hello_wstr (reinterpret_cast <const wchar_t *>(hello_utf32_codeunits ),
58
+ sizeof(hello_utf32_codeunits ) / sizeof(hello_utf32_codeunits [0 ]));
38
59
39
60
#endif
40
61
41
62
// #14
42
63
TEST_CASE (" Encoding: Widen" , " [unicode]" ) {
43
64
using CLI::widen;
44
65
45
- CHECK (wstr == widen (str));
46
- CHECK (wstr == widen (str.c_str ()));
47
- CHECK (wstr == widen (str.c_str (), str.size ()));
66
+ CHECK (abcd_wstr == widen (abcd_str));
67
+ CHECK (egypt_wstr == widen (egypt_str));
68
+ CHECK (hello_wstr == widen (hello_str));
69
+
70
+ CHECK (hello_wstr == widen (hello_str.c_str ()));
71
+ CHECK (hello_wstr == widen (hello_str.c_str (), hello_str.size ()));
48
72
}
49
73
50
74
// #14
51
75
TEST_CASE (" Encoding: Narrow" , " [unicode]" ) {
52
76
using CLI::narrow;
53
77
54
- CHECK (str == narrow (wstr));
55
- CHECK (str == narrow (wstr.c_str ()));
56
- CHECK (str == narrow (wstr.c_str (), wstr.size ()));
78
+ CHECK (abcd_str == narrow (abcd_wstr));
79
+ CHECK (egypt_str == narrow (egypt_wstr));
80
+ CHECK (hello_str == narrow (hello_wstr));
81
+
82
+ CHECK (hello_str == narrow (hello_wstr.c_str ()));
83
+ CHECK (hello_str == narrow (hello_wstr.c_str (), hello_wstr.size ()));
57
84
}
58
85
59
86
#if defined CLI11_HAS_FILESYSTEM && CLI11_HAS_FILESYSTEM > 0
@@ -62,12 +89,12 @@ TEST_CASE("Encoding: to_path roundtrip", "[unicode]") {
62
89
using std::filesystem::path;
63
90
64
91
#ifdef _WIN32
65
- std::wstring native_str = CLI::widen (str );
92
+ std::wstring native_str = CLI::widen (hello_str );
66
93
#else
67
- std::string native_str = str ;
94
+ std::string native_str = hello_str ;
68
95
#endif // _WIN32
69
96
70
- CHECK (CLI::to_path (str ).native () == native_str);
97
+ CHECK (CLI::to_path (hello_str ).native () == native_str);
71
98
}
72
99
73
100
#endif // CLI11_HAS_FILESYSTEM
0 commit comments