-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cuchar.cpp
85 lines (71 loc) · 1.72 KB
/
test_cuchar.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// $HOME/bin/bin/g++ -o test_cuchar test_cuchar.cpp
#include <cwchar>
#include <cuchar>
#include <iostream>
#include <bits/c++config.h>
int
test_c16rtomb()
{
const char16_t* pt = u"Juan Souli\u00e9";
std::mbstate_t mbs{};
size_t total = 0;
char buffer[MB_CUR_MAX];
while (*pt)
{
size_t length = std::c16rtomb(buffer, *pt, &mbs);
total += length;
if (length == 0 || length > MB_CUR_MAX)
break;
for (int i = 0; i < length; ++i)
std::cout.put(buffer[i]);
++pt;
}
std::cout << '\n';
std::cout << "total: " << total << '\n';
return 0;
}
int
test_c32rtomb()
{
const char32_t* pt = U"Juan Souli\u00e9";
std::mbstate_t mbs{};
size_t total = 0;
char buffer[MB_CUR_MAX];
while (*pt)
{
size_t length = std::c32rtomb(buffer, *pt, &mbs);
total += length;
if (length == 0 || length > MB_CUR_MAX)
break;
for (int i = 0; i < length; ++i)
std::cout.put(buffer[i]);
++pt;
}
std::cout << '\n';
std::cout << "total: " << total << '\n';
return 0;
}
int
main()
{
#ifdef HAVE_UCHAR_H
std::cout << "HAVE_UCHAR_H : " << HAVE_UCHAR_H << std::endl;
#endif
#ifdef _GLIBCXX_USE_C11_UCHAR_CXX11
std::cout << "_GLIBCXX_USE_C11_UCHAR_CXX11 : " << _GLIBCXX_USE_C11_UCHAR_CXX11 << std::endl;
#endif
#ifdef _GLIBCXX_HAVE_UCHAR_H
std::cout << "_GLIBCXX_HAVE_UCHAR_H : " << _GLIBCXX_HAVE_UCHAR_H << std::endl;
#endif
#ifdef _GLIBCXX_HAVE_MBSTATE_T
std::cout << "_GLIBCXX_HAVE_MBSTATE_T : " << _GLIBCXX_HAVE_MBSTATE_T << std::endl;
#endif
#ifdef __STDC_UTF_16__
std::cout << "__STDC_UTF_16__ : " << __STDC_UTF_16__ << std::endl;
#endif
test_c16rtomb();
#ifdef __STDC_UTF_32__
std::cout << "__STDC_UTF_32__ : " << __STDC_UTF_32__ << std::endl;
#endif
test_c32rtomb();
}