41#define TMP_BUFFER_SIZE 1024
46 "\xc6\xfc\x0a\xc6\xfc\xcd\xcb\xc6\xfc\x0a\xb7\xee\x0a\xb7\xee\xcd"
47 "\xcb\xc6\xfc\x0a\xb2\xd0\x0a\xb2\xd0\xcd\xcb\xc6\xfc\x0a\xbf\xe5"
48 "\x0a\xbf\xe5\xcd\xcb\xc6\xfc\x0a\xcc\xda\x0a\xcc\xda\xcd\xcb\xc6"
49 "\xfc\x0a\xb6\xe2\x0a\xb6\xe2\xcd\xcb\xc6\xfc\x0a\xc5\xda\x0a\xc5"
50 "\xda\xcd\xcb\xc6\xfc\x0a"
54 "\x93\xfa\x0a\x93\xfa\x97\x6a\x93\xfa\x0a\x8c\x8e\x0a\x8c\x8e\x97"
55 "\x6a\x93\xfa\x0a\x89\xce\x0a\x89\xce\x97\x6a\x93\xfa\x0a\x90\x85"
56 "\x0a\x90\x85\x97\x6a\x93\xfa\x0a\x96\xd8\x0a\x96\xd8\x97\x6a\x93"
57 "\xfa\x0a\x8b\xe0\x0a\x8b\xe0\x97\x6a\x93\xfa\x0a\x93\x79\x0a\x93"
58 "\x79\x97\x6a\x93\xfa\x0a"
62 "\xe6\x97\xa5\x0a\xe6\x97\xa5\xe6\x9b\x9c\xe6\x97\xa5\x0a\xe6\x9c"
63 "\x88\x0a\xe6\x9c\x88\xe6\x9b\x9c\xe6\x97\xa5\x0a\xe7\x81\xab\x0a"
64 "\xe7\x81\xab\xe6\x9b\x9c\xe6\x97\xa5\x0a\xe6\xb0\xb4\x0a\xe6\xb0"
65 "\xb4\xe6\x9b\x9c\xe6\x97\xa5\x0a\xe6\x9c\xa8\x0a\xe6\x9c\xa8\xe6"
66 "\x9b\x9c\xe6\x97\xa5\x0a\xe9\x87\x91\x0a\xe9\x87\x91\xe6\x9b\x9c"
67 "\xe6\x97\xa5\x0a\xe5\x9c\x9f\x0a\xe5\x9c\x9f\xe6\x9b\x9c\xe6\x97"
80std::mbstate_t
init = std::mbstate_t ();
87 typedef std::codecvt_byname<wchar_t,char,std::mbstate_t> wcodecvt_byname_t;
92 std::mbstate_t state =
init;
93 std::codecvt_base::result
res;
96 std::locale
loc (locname);
97 const wcodecvt_byname_t& cc =
98 std::use_facet<wcodecvt_byname_t> (
loc);
102 const char* cpen =
buffer;
110 res = cc.in (state, cpe, cpe_limit, cpen, pi, pi_limit, pin);
114 const wchar_t* cpi = pi;
115 const wchar_t* cpin = pi;
116 const wchar_t* cpi_limit = pin;
124 res = cc.out (state, cpi, cpi_limit, cpin, pe, pe_limit, pen);
125 std::cout << locname <<
" -> INT -> " << locname <<
'\n';
127 std::cout <<
" Size comparison of buffers yields "
128 << (std::codecvt_base::ok ==
res && (cpen - cpe == pen - pe)
129 ?
"equal\n" :
"not equal\n");
131 const int cmp = std::memcmp (cpe, pe, std::min ((cpen - cpe), (pen - pe)));
132 std::cout <<
" Content comparison of buffers yields "
133 << (
cmp ?
"not equal\n" :
"equal\n");
139 typedef std::codecvt_byname<wchar_t,char,std::mbstate_t> wcodecvt_byname_t;
144 std::codecvt_base::result
res;
156 const std::locale loc1 (
"ja_JP.EUC-JP");
157 const std::locale loc2 (
"ja_JP.UTF-8");
159 const wcodecvt_byname_t& cc1 = std::use_facet<wcodecvt_byname_t> (loc1);
160 const wcodecvt_byname_t& cc2 = std::use_facet<wcodecvt_byname_t> (loc2);
162 std::mbstate_t state1 =
init;
163 std::mbstate_t state2 =
init;
165 const std::size_t
len = std::strlen (
wd_utf8);
177 res = cc1.in (state1, cpe, cpe_limit, cpen, pi, pi_limit, pin);
181 const wchar_t* cpi = pi;
182 const wchar_t* cpin = pi;
183 const wchar_t* cpi_limit = pin;
189 res = cc2.out (state2, cpi, cpi_limit, cpin, pe, pe_limit, pen);
191 std::cout <<
"\nEUC-JP -> INT -> UTF-8 conversion\n";
192 std::cout <<
" Size comparison of buffers yields "
193 << (std::codecvt_base::ok ==
res && std::size_t (pen - pe) ==
len
198 std::memcmp (pe,
wd_utf8, std::min ((pen - pe), std::ptrdiff_t (
len)));
200 std::cout <<
" Content comparison of buffers yields "
201 << (
cmp ?
"not equal\n" :
"equal\n");
214 std::cout <<
"Caught an exception: " <<
e.what () << std::endl;
219 std::cout <<
"Caught an unknown exception" << std::endl;
const struct @19 locales[]
void do_diff_conversion()
void do_roundtrip_conversion(const char *locname, const char *buffer)