Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
22.locale.codecvt.stdcxx-435.cpp
Go to the documentation of this file.
1
29#include <cassert>
30#include <clocale>
31#include <cwchar>
32#include <locale>
33
34int main ()
35{
36 // multibyte locale
37 std::locale mbloc;
38
39 // names of some well-known multibyte locales
40 const char* const names[] = {
41 "EN_US.UTF-8", // AIX
42 "en_US.UTF-8", // AIX, Linux, Solaris
43 "en_US.utf8", // HP-UX
44
45 // starting with Vista, Windows follows RFC 4646 name format
46 // http://msdn2.microsoft.com/en-us/library/ms776260(VS.85).aspx
47 "hy-AM", // Win 2000
48 "as-IN", // Win Vista
49 "bn-IN", // Win XP SP2
50 "zh-HK",
51 "zh-CN",
52
53 0
54 };
55
56 // try to find the first multibyte locale on this system
57 for (unsigned i = 0; names [i]; ++i) {
58 if (std::setlocale (LC_ALL, names [i])) {
59 mbloc = std::locale (names [i]);
60 break;
61 }
62 }
63
64 // fall back on the "C" locale...
65
66 typedef std::codecvt<wchar_t, char, std::mbstate_t> MbCvt;
67
68 const MbCvt &cvt = std::use_facet<MbCvt>(mbloc);
69
70 // source and destination buffers
71 const char src[] = "abc";
72 wchar_t dst [2] = { L'\0', L'\1' };
73
74 const char* from_next;
75
76 wchar_t* to_next;
77
78 std::mbstate_t state = std::mbstate_t ();
79
80 // convert exactly one source character, expect exactly
81 // one wide character in the destination buffer
82 const std::codecvt_base::result res =
83 cvt.in (state,
84 src, src + 1, from_next,
85 dst, dst + 2, to_next);
86
87 assert (cvt.ok == res);
88 assert (1 == from_next - src);
89 assert (1 == to_next - dst);
90 assert ('a' == dst [0] && '\1' == dst [1]);
91}
#define i
Definition 17.names.cpp:126
#define res
Definition 17.names.cpp:531
#define assert(expr)
Definition _cassert.h:40
#define LC_ALL