2 * Portions Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
5 * Silicon Graphics Computer Systems, Inc.
10 * This material is provided "as is", with absolutely no warranty expressed
11 * or implied. Any use is at your own risk.
13 * Permission to use or copy this software for any purpose is hereby granted
14 * without fee, provided the above notices are retained on all copies.
15 * Permission to modify the code and to distribute modified code is granted,
16 * provided the above notices are retained, and a notice that the code was
17 * modified is included with the above copyright notice.
20 // WARNING: This is an internal header file, included by other C++
21 // standard library headers. You should not attempt to use this header
25 #ifndef _STLP_INTERNAL_CODECVT_H
26 #define _STLP_INTERNAL_CODECVT_H
28 #ifndef _STLP_C_LOCALE_H
29 # include <stl/c_locale.h>
32 #ifndef _STLP_INTERNAL_LOCALE_H
33 # include <stl/_locale.h>
36 #ifndef _STLP_INTERNAL_ALGOBASE_H
37 # include <stl/_algobase.h>
42 class _STLP_CLASS_DECLSPEC codecvt_base {
44 enum result {ok, partial, error, noconv};
47 template <class _InternT, class _ExternT, class _StateT>
48 class codecvt : public locale::facet, public codecvt_base {
50 typedef _InternT intern_type;
51 typedef _ExternT extern_type;
52 typedef _StateT state_type;
54 #if defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
55 /* For the moment VC6 do not support this facet default implementation
56 * because of the static locale::id instance. When VC6 see this definition
57 * it goes crasy with locale::id static instances and all the has_facet tests
58 * unit tests are failing.
62 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
64 result out(state_type& __state,
65 const intern_type* __from,
66 const intern_type* __from_end,
67 const intern_type*& __from_next,
69 extern_type* __to_limit,
70 extern_type*& __to_next) const {
71 return do_out(__state,
72 __from, __from_end, __from_next,
73 __to, __to_limit, __to_next);
76 result unshift(state_type& __state,
78 extern_type* __to_limit,
79 extern_type*& __to_next) const {
80 return do_unshift(__state, __to, __to_limit, __to_next);
83 result in(state_type& __state,
84 const extern_type* __from,
85 const extern_type* __from_end,
86 const extern_type*& __from_next,
88 intern_type* __to_limit,
89 intern_type*& __to_next) const {
91 __from, __from_end, __from_next,
92 __to, __to_limit, __to_next);
95 int encoding() const _STLP_NOTHROW { return do_encoding(); }
97 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
99 int length(const state_type& __state,
100 const extern_type* __from,
101 const extern_type* __end,
102 size_t __max) const {
103 return do_length(__state, __from, __end, __max);
106 int max_length() const _STLP_NOTHROW { return do_max_length(); }
108 #if defined(__SYMBIAN32__WSD__)
109 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
110 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
111 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
112 static locale::id id;
114 // NOTE: Symbian doesn't support exporting static data.
115 // Users of this class should use GetFacetLocaleId() to access the data member id
116 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
123 virtual result do_out(state_type&,
124 const intern_type* __from,
126 const intern_type*& __from_next,
129 extern_type*& __to_next) const
130 { __from_next = __from; __to_next = __to; return noconv; }
132 virtual result do_in (state_type&,
133 const extern_type* __from,
135 const extern_type*& __from_next,
138 intern_type*& __to_next) const
139 { __from_next = __from; __to_next = __to; return noconv; }
141 virtual result do_unshift(state_type&,
144 extern_type*& __to_next) const
145 { __to_next = __to; return noconv; }
147 virtual int do_encoding() const _STLP_NOTHROW
150 virtual bool do_always_noconv() const _STLP_NOTHROW
153 virtual int do_length(const state_type&,
154 const extern_type* __from,
155 const extern_type* __end,
157 { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); }
159 virtual int do_max_length() const _STLP_NOTHROW
163 codecvt(const codecvt<intern_type, extern_type, state_type>&);
164 codecvt<intern_type, extern_type, state_type>& operator = (const codecvt<intern_type, extern_type, state_type>&);
167 # if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
168 # if (_STLP_STATIC_TEMPLATE_DATA > 0)
169 # if !defined (__BORLANDC__) && !defined(__SYMBIAN32__WSD__)
170 template <class _InternT, class _ExternT, class _StateT>
171 locale::id codecvt<_InternT, _ExternT, _StateT>::id;
177 template <class _InternT, class _ExternT, class _StateT>
178 class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
181 class _STLP_CLASS_DECLSPEC codecvt<char, char, mbstate_t>
182 : public locale::facet, public codecvt_base
184 friend class _Locale_impl;
187 typedef char intern_type;
188 typedef char extern_type;
189 typedef mbstate_t state_type;
191 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
193 result out(mbstate_t& __state,
195 const char* __from_end,
196 const char*& __from_next,
199 char*& __to_next) const {
200 return do_out(__state,
201 __from, __from_end, __from_next,
202 __to, __to_limit, __to_next);
205 result unshift(mbstate_t& __state,
206 char* __to, char* __to_limit, char*& __to_next) const
207 { return do_unshift(__state, __to, __to_limit, __to_next); }
209 result in(state_type& __state,
211 const char* __from_end,
212 const char*& __from_next,
215 char*& __to_next) const {
216 return do_in(__state,
217 __from, __from_end, __from_next,
218 __to, __to_limit, __to_next);
221 int encoding() const _STLP_NOTHROW { return do_encoding(); }
223 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
225 int length(const state_type& __state,
226 const char* __from, const char* __end,
228 { return do_length(__state, __from, __end, __max); }
230 int max_length() const _STLP_NOTHROW { return do_max_length(); }
231 #if defined(__SYMBIAN32__WSD__)
232 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
233 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
234 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
235 static locale::id id;
237 // NOTE: Symbian doesn't support exporting static data.
238 // Users of this class should use GetFacetLocaleId() to access the data member id
239 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
242 _STLP_DECLSPEC ~codecvt();
244 _STLP_DECLSPEC virtual result do_out(mbstate_t& /* __state */,
246 const char* /* __from_end */,
247 const char*& __from_next,
249 char* /* __to_limit */,
250 char*& __to_next) const;
252 _STLP_DECLSPEC virtual result do_in (mbstate_t& /* __state */ ,
254 const char* /* __from_end */,
255 const char*& __from_next,
257 char* /* __to_end */,
258 char*& __to_next) const;
260 _STLP_DECLSPEC virtual result do_unshift(mbstate_t& /* __state */,
262 char* /* __to_limit */,
263 char*& __to_next) const;
265 _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
266 _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
267 _STLP_DECLSPEC virtual int do_length(const mbstate_t& __state,
271 _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
273 codecvt(const codecvt<char, char, mbstate_t>&);
274 codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
277 # ifndef _STLP_NO_WCHAR_T
280 class _STLP_CLASS_DECLSPEC codecvt<wchar_t, char, mbstate_t>
281 : public locale::facet, public codecvt_base
283 friend class _Locale_impl;
285 typedef wchar_t intern_type;
286 typedef char extern_type;
287 typedef mbstate_t state_type;
289 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
291 result out(mbstate_t& __state,
292 const wchar_t* __from,
293 const wchar_t* __from_end,
294 const wchar_t*& __from_next,
297 char*& __to_next) const {
298 return do_out(__state,
299 __from, __from_end, __from_next,
300 __to, __to_limit, __to_next);
303 result unshift(mbstate_t& __state,
304 char* __to, char* __to_limit, char*& __to_next) const {
305 return do_unshift(__state, __to, __to_limit, __to_next);
308 result in(mbstate_t& __state,
310 const char* __from_end,
311 const char*& __from_next,
314 wchar_t*& __to_next) const {
315 return do_in(__state,
316 __from, __from_end, __from_next,
317 __to, __to_limit, __to_next);
320 int encoding() const _STLP_NOTHROW { return do_encoding(); }
322 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
324 int length(const mbstate_t& __state,
325 const char* __from, const char* __end,
327 { return do_length(__state, __from, __end, __max); }
329 int max_length() const _STLP_NOTHROW { return do_max_length(); }
330 #if defined(__SYMBIAN32__WSD__)
331 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
332 #elif defined (__SYMBIAN32__NO_STATIC_IMPORTS__)
333 static _STLP_STATIC_MEMBER_DECLSPEC locale::id& GetFacetLocaleId();
334 static locale::id id;
336 // NOTE: Symbian doesn't support exporting static data.
337 // Users of this class should use GetFacetLocaleId() to access the data member id
338 static _STLP_STATIC_MEMBER_DECLSPEC locale::id id;
341 _STLP_DECLSPEC ~codecvt();
343 _STLP_DECLSPEC virtual result do_out(mbstate_t& __state,
344 const wchar_t* __from,
345 const wchar_t* __from_end,
346 const wchar_t*& __from_next,
349 char*& __to_next) const;
351 _STLP_DECLSPEC virtual result do_in (mbstate_t& __state,
353 const char* __from_end,
354 const char*& __from_next,
357 wchar_t*& __to_next) const;
359 _STLP_DECLSPEC virtual result do_unshift(mbstate_t& __state,
362 char*& __to_next) const;
364 _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
366 _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
368 _STLP_DECLSPEC virtual int do_length(const mbstate_t& __state,
373 _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
376 codecvt(const codecvt<wchar_t, char, mbstate_t>&);
377 codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
383 class _STLP_CLASS_DECLSPEC codecvt_byname<char, char, mbstate_t>
384 : public codecvt<char, char, mbstate_t> {
386 _STLP_DECLSPEC explicit codecvt_byname(const char* __name, size_t __refs = 0);
387 _STLP_DECLSPEC ~codecvt_byname();
389 codecvt_byname(const codecvt_byname<char, char, mbstate_t>&);
390 codecvt_byname<char, char, mbstate_t>& operator =(const codecvt_byname<char, char, mbstate_t>&);
393 # ifndef _STLP_NO_WCHAR_T
395 class _STLP_CLASS_DECLSPEC codecvt_byname<wchar_t, char, mbstate_t>
396 : public codecvt<wchar_t, char, mbstate_t>
399 _STLP_DECLSPEC explicit codecvt_byname(const char * __name, size_t __refs = 0, _Locale_name_hint* __hint = 0);
402 _STLP_DECLSPEC ~codecvt_byname();
404 _STLP_DECLSPEC virtual result do_out(mbstate_t& __state,
405 const wchar_t* __from,
406 const wchar_t* __from_end,
407 const wchar_t*& __from_next,
410 char*& __to_next) const;
412 _STLP_DECLSPEC virtual result do_in (mbstate_t& __state,
414 const char* __from_end,
415 const char*& __from_next,
418 wchar_t*& __to_next) const;
420 _STLP_DECLSPEC virtual result do_unshift(mbstate_t& __state,
423 char*& __to_next) const;
425 _STLP_DECLSPEC virtual int do_encoding() const _STLP_NOTHROW;
427 _STLP_DECLSPEC virtual bool do_always_noconv() const _STLP_NOTHROW;
429 _STLP_DECLSPEC virtual int do_length(const mbstate_t& __state,
434 _STLP_DECLSPEC virtual int do_max_length() const _STLP_NOTHROW;
437 _Locale_ctype* _M_ctype;
438 codecvt_byname(const codecvt_byname<wchar_t, char, mbstate_t>&);
439 codecvt_byname<wchar_t, char, mbstate_t>& operator =(const codecvt_byname<wchar_t, char, mbstate_t>&);
446 #endif /* _STLP_INTERNAL_CODECVT_H */