ReactOS 0.4.15-dev-7931-gfd331f1
_codecvt.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 1999
3 * Silicon Graphics Computer Systems, Inc.
4 *
5 * Copyright (c) 1999
6 * Boris Fomitchev
7 *
8 * This material is provided "as is", with absolutely no warranty expressed
9 * or implied. Any use is at your own risk.
10 *
11 * Permission to use or copy this software for any purpose is hereby granted
12 * without fee, provided the above notices are retained on all copies.
13 * Permission to modify the code and to distribute modified code is granted,
14 * provided the above notices are retained, and a notice that the code was
15 * modified is included with the above copyright notice.
16 *
17 */
18// WARNING: This is an internal header file, included by other C++
19// standard library headers. You should not attempt to use this header
20// file directly.
21
22
23#ifndef _STLP_INTERNAL_CODECVT_H
24#define _STLP_INTERNAL_CODECVT_H
25
26#ifndef _STLP_C_LOCALE_H
27# include <stl/c_locale.h>
28#endif
29
30#ifndef _STLP_INTERNAL_LOCALE_H
31# include <stl/_locale.h>
32#endif
33
34#ifndef _STLP_INTERNAL_ALGOBASE_H
35# include <stl/_algobase.h>
36#endif
37
39
41public:
42 enum result {ok, partial, error, noconv};
43};
44
45template <class _InternT, class _ExternT, class _StateT>
46class codecvt : public locale::facet, public codecvt_base {
47public:
48 typedef _InternT intern_type;
49 typedef _ExternT extern_type;
50 typedef _StateT state_type;
51
52#if defined (_STLP_MSVC) && (_STLP_MSVC < 1300)
53 /* For the moment VC6 do not support this facet default implementation
54 * because of the static locale::id instance. When VC6 see this definition
55 * it goes crasy with locale::id static instances and all the has_facet tests
56 * unit tests are failing.
57 */
58};
59#else
60 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
61
63 const intern_type* __from,
64 const intern_type* __from_end,
65 const intern_type*& __from_next,
66 extern_type* __to,
67 extern_type* __to_limit,
68 extern_type*& __to_next) const {
69 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
70 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
71 return do_out(__state,
72 __from, __from_end, __from_next,
73 __to, __to_limit, __to_next);
74 }
75
77 extern_type* __to,
78 extern_type* __to_limit,
79 extern_type*& __to_next) const {
80 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
81 return do_unshift(__state, __to, __to_limit, __to_next);
82 }
83
85 const extern_type* __from,
86 const extern_type* __from_end,
87 const extern_type*& __from_next,
88 intern_type* __to,
89 intern_type* __to_limit,
90 intern_type*& __to_next) const {
91 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
92 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
93 return do_in(__state,
94 __from, __from_end, __from_next,
95 __to, __to_limit, __to_next);
96 }
97
98 int encoding() const _STLP_NOTHROW { return do_encoding(); }
99
100 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
101
102 int length(state_type& __state,
103 const extern_type* __from,
104 const extern_type* __from_end,
105 size_t __max) const {
106 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
107 return do_length(__state, __from, __from_end, __max);
108 }
109
110 int max_length() const _STLP_NOTHROW { return do_max_length(); }
111
113
114protected:
116
118 const intern_type* __from,
119 const intern_type*,
120 const intern_type*& __from_next,
121 extern_type* __to,
123 extern_type*& __to_next) const
124 { __from_next = __from; __to_next = __to; return noconv; }
125
127 const extern_type* __from,
128 const extern_type*,
129 const extern_type*& __from_next,
130 intern_type* __to,
132 intern_type*& __to_next) const
133 { __from_next = __from; __to_next = __to; return noconv; }
134
136 extern_type* __to,
138 extern_type*& __to_next) const
139 { __to_next = __to; return noconv; }
140
142 { return 1; }
143
145 { return true; }
146
147 virtual int do_length(state_type&,
148 const extern_type* __from,
149 const extern_type* __end,
150 size_t __max) const
151 { return (int)(min) ( __STATIC_CAST(size_t, (__end - __from)), __max); }
152
154 { return 1; }
155
156private:
159};
160
161# if defined (_STLP_EXPOSE_STREAM_IMPLEMENTATION) && !defined (_STLP_LINK_TIME_INSTANTIATION)
162# if !defined (__BORLANDC__) || (__BORLANDC__ >= 0x590)
163template <class _InternT, class _ExternT, class _StateT>
165# endif
166# endif
167#endif
168
169template <class _InternT, class _ExternT, class _StateT>
170class codecvt_byname : public codecvt<_InternT, _ExternT, _StateT> {};
171
174 : public locale::facet, public codecvt_base {
175public:
176 typedef char intern_type;
177 typedef char extern_type;
179
180 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
181
183 const char* __from,
184 const char* __from_end,
185 const char*& __from_next,
186 char* __to,
187 char* __to_limit,
188 char*& __to_next) const {
189 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
190 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
191 return do_out(__state,
192 __from, __from_end, __from_next,
193 __to, __to_limit, __to_next);
194 }
195
197 char* __to, char* __to_limit, char*& __to_next) const {
198 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
199 return do_unshift(__state, __to, __to_limit, __to_next);
200 }
201
203 const char* __from,
204 const char* __from_end,
205 const char*& __from_next,
206 char* __to,
207 char* __to_limit,
208 char*& __to_next) const {
209 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
210 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
211 return do_in(__state,
212 __from, __from_end, __from_next,
213 __to, __to_limit, __to_next);
214 }
215
216 int encoding() const _STLP_NOTHROW { return do_encoding(); }
217
218 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
219
220 int length(state_type& __state,
221 const char* __from, const char* __from_end,
222 size_t __max) const {
223 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
224 return do_length(__state, __from, __from_end, __max);
225 }
226
227 int max_length() const _STLP_NOTHROW { return do_max_length(); }
228
230
231protected:
232 ~codecvt();
233
234 virtual result do_out(state_type& /* __state */,
235 const char* __from,
236 const char* /* __from_end */,
237 const char*& __from_next,
238 char* __to,
239 char* /* __to_limit */,
240 char*& __to_next) const;
241
242 virtual result do_in (state_type& /* __state */ ,
243 const char* __from,
244 const char* /* __from_end */,
245 const char*& __from_next,
246 char* __to,
247 char* /* __to_end */,
248 char*& __to_next) const;
249
250 virtual result do_unshift(state_type& /* __state */,
251 char* __to,
252 char* /* __to_limit */,
253 char*& __to_next) const;
254
255 virtual int do_encoding() const _STLP_NOTHROW;
256 virtual bool do_always_noconv() const _STLP_NOTHROW;
257 virtual int do_length(state_type& __state,
258 const char* __from,
259 const char* __end,
260 size_t __max) const;
261 virtual int do_max_length() const _STLP_NOTHROW;
262private:
264 codecvt<char, char, mbstate_t>& operator =(const codecvt<char, char, mbstate_t>&);
265};
266
267# ifndef _STLP_NO_WCHAR_T
268
271 : public locale::facet, public codecvt_base {
272public:
273 typedef wchar_t intern_type;
274 typedef char extern_type;
276
277 explicit codecvt(size_t __refs = 0) : locale::facet(__refs) {}
278
280 const wchar_t* __from,
281 const wchar_t* __from_end,
282 const wchar_t*& __from_next,
283 char* __to,
284 char* __to_limit,
285 char*& __to_next) const {
286 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
287 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
288 return do_out(__state,
289 __from, __from_end, __from_next,
290 __to, __to_limit, __to_next);
291 }
292
294 char* __to, char* __to_limit, char*& __to_next) const {
295 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
296 return do_unshift(__state, __to, __to_limit, __to_next);
297 }
298
300 const char* __from,
301 const char* __from_end,
302 const char*& __from_next,
303 wchar_t* __to,
304 wchar_t* __to_limit,
305 wchar_t*& __to_next) const {
306 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
307 _STLP_VERBOSE_ASSERT(__to <= __to_limit, _StlMsg_INVALID_ARGUMENT)
308 return do_in(__state,
309 __from, __from_end, __from_next,
310 __to, __to_limit, __to_next);
311 }
312
313 int encoding() const _STLP_NOTHROW { return do_encoding(); }
314
315 bool always_noconv() const _STLP_NOTHROW { return do_always_noconv(); }
316
317 int length(state_type& __state,
318 const char* __from, const char* __from_end,
319 size_t __max) const {
320 _STLP_VERBOSE_ASSERT(__from <= __from_end, _StlMsg_INVALID_ARGUMENT)
321 return do_length(__state, __from, __from_end, __max);
322 }
323
324 int max_length() const _STLP_NOTHROW { return do_max_length(); }
325
327
328protected:
329 ~codecvt();
330
331 virtual result do_out(state_type& __state,
332 const wchar_t* __from,
333 const wchar_t* __from_end,
334 const wchar_t*& __from_next,
335 char* __to,
336 char* __to_limit,
337 char*& __to_next) const;
338
339 virtual result do_in (state_type& __state,
340 const char* __from,
341 const char* __from_end,
342 const char*& __from_next,
343 wchar_t* __to,
344 wchar_t* __to_limit,
345 wchar_t*& __to_next) const;
346
347 virtual result do_unshift(state_type& __state,
348 char* __to,
349 char* __to_limit,
350 char*& __to_next) const;
351
352 virtual int do_encoding() const _STLP_NOTHROW;
353
354 virtual bool do_always_noconv() const _STLP_NOTHROW;
355
356 virtual int do_length(state_type& __state,
357 const char* __from,
358 const char* __end,
359 size_t __max) const;
360
361 virtual int do_max_length() const _STLP_NOTHROW;
362
363private:
364 codecvt(const codecvt<wchar_t, char, mbstate_t>&);
365 codecvt<wchar_t, char, mbstate_t>& operator = (const codecvt<wchar_t, char, mbstate_t>&);
366};
367
368# endif
369
372 : public codecvt<char, char, mbstate_t> {
373public:
374 explicit codecvt_byname(const char* __name, size_t __refs = 0);
376private:
379};
380
381# ifndef _STLP_NO_WCHAR_T
384 : public codecvt<wchar_t, char, mbstate_t> {
385 friend class _Locale_impl;
386public:
387 explicit codecvt_byname(const char * __name, size_t __refs = 0);
388
389protected:
391
392 virtual result do_out(state_type& __state,
393 const wchar_t* __from,
394 const wchar_t* __from_end,
395 const wchar_t*& __from_next,
396 char* __to,
397 char* __to_limit,
398 char*& __to_next) const;
399
400 virtual result do_in (state_type& __state,
401 const char* __from,
402 const char* __from_end,
403 const char*& __from_next,
404 wchar_t* __to,
405 wchar_t* __to_limit,
406 wchar_t*& __to_next) const;
407
408 virtual result do_unshift(state_type& __state,
409 char* __to,
410 char* __to_limit,
411 char*& __to_next) const;
412
413 virtual int do_encoding() const _STLP_NOTHROW;
414
415 virtual bool do_always_noconv() const _STLP_NOTHROW;
416
417 virtual int do_length(state_type& __state,
418 const char* __from,
419 const char* __end,
420 size_t __max) const;
421
422 virtual int do_max_length() const _STLP_NOTHROW;
423
424private:
426 : _M_codecvt(__cvt) {}
427
431};
432
433# endif
434
436
437#endif /* _STLP_INTERNAL_CODECVT_H */
438
439// Local Variables:
440// mode:C++
441// End:
442
#define _STLP_VERBOSE_ASSERT(expr, diagnostic)
Definition: _debug.h:439
#define _STLP_NOTHROW
Definition: _intel.h:35
#define ok(value,...)
Definition: atltest.h:57
result in(state_type &__state, const char *__from, const char *__from_end, const char *&__from_next, char *__to, char *__to_limit, char *&__to_next) const
Definition: _codecvt.h:202
result out(state_type &__state, const char *__from, const char *__from_end, const char *&__from_next, char *__to, char *__to_limit, char *&__to_next) const
Definition: _codecvt.h:182
int encoding() const _STLP_NOTHROW
Definition: _codecvt.h:216
result unshift(state_type &__state, char *__to, char *__to_limit, char *&__to_next) const
Definition: _codecvt.h:196
int max_length() const _STLP_NOTHROW
Definition: _codecvt.h:227
bool always_noconv() const _STLP_NOTHROW
Definition: _codecvt.h:218
static _STLP_STATIC_DECLSPEC locale::id id
Definition: _codecvt.h:229
int length(state_type &__state, const char *__from, const char *__from_end, size_t __max) const
Definition: _codecvt.h:220
result out(state_type &__state, const wchar_t *__from, const wchar_t *__from_end, const wchar_t *&__from_next, char *__to, char *__to_limit, char *&__to_next) const
Definition: _codecvt.h:279
int max_length() const _STLP_NOTHROW
Definition: _codecvt.h:324
int encoding() const _STLP_NOTHROW
Definition: _codecvt.h:313
int length(state_type &__state, const char *__from, const char *__from_end, size_t __max) const
Definition: _codecvt.h:317
result unshift(state_type &__state, char *__to, char *__to_limit, char *&__to_next) const
Definition: _codecvt.h:293
result in(state_type &__state, const char *__from, const char *__from_end, const char *&__from_next, wchar_t *__to, wchar_t *__to_limit, wchar_t *&__to_next) const
Definition: _codecvt.h:299
static _STLP_STATIC_DECLSPEC locale::id id
Definition: _codecvt.h:326
bool always_noconv() const _STLP_NOTHROW
Definition: _codecvt.h:315
codecvt_byname(const codecvt_byname< char, char, mbstate_t > &)
codecvt_byname(const codecvt_byname< wchar_t, char, mbstate_t > &)
virtual int do_max_length() const _STLP_NOTHROW
Definition: _codecvt.h:153
virtual bool do_always_noconv() const _STLP_NOTHROW
Definition: _codecvt.h:144
virtual result do_unshift(state_type &, extern_type *__to, extern_type *, extern_type *&__to_next) const
Definition: _codecvt.h:135
result out(state_type &__state, const intern_type *__from, const intern_type *__from_end, const intern_type *&__from_next, extern_type *__to, extern_type *__to_limit, extern_type *&__to_next) const
Definition: _codecvt.h:62
static locale::id id
Definition: _codecvt.h:112
codecvt(size_t __refs=0)
Definition: _codecvt.h:60
result unshift(state_type &__state, extern_type *__to, extern_type *__to_limit, extern_type *&__to_next) const
Definition: _codecvt.h:76
int encoding() const _STLP_NOTHROW
Definition: _codecvt.h:98
bool always_noconv() const _STLP_NOTHROW
Definition: _codecvt.h:100
_ExternT extern_type
Definition: _codecvt.h:49
~codecvt()
Definition: _codecvt.h:115
virtual int do_encoding() const _STLP_NOTHROW
Definition: _codecvt.h:141
_InternT intern_type
Definition: _codecvt.h:48
codecvt(const codecvt< intern_type, extern_type, state_type > &)
_StateT state_type
Definition: _codecvt.h:50
int length(state_type &__state, const extern_type *__from, const extern_type *__from_end, size_t __max) const
Definition: _codecvt.h:102
virtual result do_in(state_type &, const extern_type *__from, const extern_type *, const extern_type *&__from_next, intern_type *__to, intern_type *, intern_type *&__to_next) const
Definition: _codecvt.h:126
virtual result do_out(state_type &, const intern_type *__from, const intern_type *, const intern_type *&__from_next, extern_type *__to, extern_type *, extern_type *&__to_next) const
Definition: _codecvt.h:117
int max_length() const _STLP_NOTHROW
Definition: _codecvt.h:110
virtual int do_length(state_type &, const extern_type *__from, const extern_type *__end, size_t __max) const
Definition: _codecvt.h:147
result in(state_type &__state, const extern_type *__from, const extern_type *__from_end, const extern_type *&__from_next, intern_type *__to, intern_type *__to_limit, intern_type *&__to_next) const
Definition: _codecvt.h:84
Definition: _locale.h:75
unsigned short wchar_t
Definition: crtdefs.h:345
unsigned char
Definition: typeof.h:29
#define _STLP_TEMPLATE_NULL
Definition: features.h:652
#define _STLP_STATIC_DECLSPEC
Definition: features.h:992
#define __STATIC_CAST(__x, __y)
Definition: features.h:585
#define _STLP_CLASS_DECLSPEC
Definition: features.h:983
#define _STLP_BEGIN_NAMESPACE
Definition: features.h:501
#define _STLP_END_NAMESPACE
Definition: features.h:503
#define __max(a, b)
Definition: stdlib.h:101
#define min(a, b)
Definition: monoChain.cc:55
operator
#define const
Definition: zconf.h:233