Ne.app NeANT
The Ne.app NeANT User module of the NeANT distribution.
_messages.cc
Go to the documentation of this file.
1
29#include <loc/_ctype.h>
30
31
33
34
35template <class _CharT>
36_RW::__rw_facet_id messages<_CharT>::id;
37
38
39// outlined to avoid generating a vtable in each translation unit
40// that uses the class
41template <class _CharT>
42/* virtual */ messages<_CharT>::
43~messages ()
44{
45 // no-op
46}
47
48
49template <class _CharT>
50messages_base::catalog
51messages<_CharT>::
52do_open (const string& __fun, const locale&__loc) const
53{
54 return _RW::__rw_cat_open (__fun, __loc);
55}
56
57
58template <class _CharT>
59void
60messages<_CharT>::
61do_close (messages_base::catalog __cat) const
62{
63 _RW::__rw_cat_close (__cat);
64}
65
66
67template <class _CharT>
68typename messages<_CharT>::string_type
69messages<_CharT>::do_get (messages_base::catalog __cat,
70 int __set,
71 int __msgid,
72 const string_type &__dfault) const
73{
74 const char* const __text = _RW::__rw_get_message (__cat, __set, __msgid);
75
76 if (__text) {
77 typedef _STD::codecvt<_CharT, char, _RWSTD_MBSTATE_T>
78 _CodeCvt;
79
80 typedef typename _CodeCvt::state_type state_type;
81
82 const _CodeCvt& __codecvt =
83 _RWSTD_USE_FACET (_CodeCvt, _RW::__rw_get_locale (__cat));
84
85 if (sizeof (_CharT) == sizeof (char) && __codecvt.always_noconv ()) {
86 // lwg issue 19: always_noconv() is only allowed to return
87 // true if extern_type and intern_type are one and the same
88 return _RWSTD_REINTERPRET_CAST (const _CharT*, __text);
89 }
90
91 typedef char_traits<char> _CharTraits;
92 typedef _RWSTD_SIZE_T _SizeT;
93
94 const _SizeT __src_len = _CharTraits::length (__text);
95 const char* const __src_first = __text;
96 const char* const __src_last = __text + __src_len;
97 const char* __src_next = __src_first;
98
99 // allocate a [wide] string large enough to hold at least
100 // as many internal characters as there are bytes in the
101 // multibyte characater message
102 string_type __result_str ((const _CharT*)0, __src_len);
103
104 _CharT* const __dst_first = &__result_str [0];
105 _CharT* const __dst_last = __dst_first + __src_len;
106 _CharT* __dst_next = __dst_first;
107
108 state_type __state = state_type ();
109
110 // avoid using const codecvt_base::result here
111 // to prevent HP aCC 3.27 errors
112 const int __res =
113 __codecvt.in (__state, __src_first, __src_last, __src_next,
114 __dst_first, __dst_last, __dst_next);
115
116 switch (__res) {
117 case codecvt_base::ok:
118 // shrink the converted string accordingly
119 _RWSTD_ASSERT (__dst_first <= __dst_next);
120
121 __result_str.resize (_SizeT (__dst_next - __dst_first));
122 return __result_str;
123
124 case codecvt_base::noconv:
125 if (sizeof (_CharT) == sizeof (char)) {
126 // lwg issue 19: in() is only allowed to return noconv
127 // if extern_type and intern_type are one and the same
128 return _RWSTD_REINTERPRET_CAST (const _CharT*, __text);
129 }
130 else {
131 // should not happen - bad codecvt implementation
132
133 typedef ctype<_CharT> _Ctype;
134
135 const _Ctype& __ctp =
136 _RWSTD_USE_FACET (_Ctype, _RW::__rw_get_locale (__cat));
137
138 for (_SizeT __i = 0; __i != __src_len; ++__i)
139 __dst_first [__i] = __ctp.widen (__text [__i]);
140
141 return __result_str;
142 }
143
144 case codecvt_base::partial:
145 // should not happen (bad catalog?)
146 default:
147 break;
148 }
149 }
150 return __dfault;
151}
152
153
154// outlined to avoid generating a vtable in each translation unit
155// that uses the class
156template <class _CharT>
157/* virtual */ messages_byname<_CharT>::
158~messages_byname ()
159{
160 // no-op
161}
162
163
164} // namespace std
#define _RWSTD_USE_FACET(type, arg)
Definition _defs.h:949
#define _RWSTD_REINTERPRET_CAST(T, x)
Definition _defs.h:535
#define _RWSTD_NAMESPACE(name)
Definition _defs.h:567
#define _RWSTD_ASSERT(ignore)
Definition _defs.h:1108
Definition json.h:5363