xref: /reactos/sdk/lib/3rdparty/stlport/src/codecvt.cpp (revision c2c66aff)
1*c2c66affSColin Finck /*
2*c2c66affSColin Finck  * Copyright (c) 1999
3*c2c66affSColin Finck  * Silicon Graphics Computer Systems, Inc.
4*c2c66affSColin Finck  *
5*c2c66affSColin Finck  * Copyright (c) 1999
6*c2c66affSColin Finck  * Boris Fomitchev
7*c2c66affSColin Finck  *
8*c2c66affSColin Finck  * This material is provided "as is", with absolutely no warranty expressed
9*c2c66affSColin Finck  * or implied. Any use is at your own risk.
10*c2c66affSColin Finck  *
11*c2c66affSColin Finck  * Permission to use or copy this software for any purpose is hereby granted
12*c2c66affSColin Finck  * without fee, provided the above notices are retained on all copies.
13*c2c66affSColin Finck  * Permission to modify the code and to distribute modified code is granted,
14*c2c66affSColin Finck  * provided the above notices are retained, and a notice that the code was
15*c2c66affSColin Finck  * modified is included with the above copyright notice.
16*c2c66affSColin Finck  *
17*c2c66affSColin Finck  */
18*c2c66affSColin Finck #include "stlport_prefix.h"
19*c2c66affSColin Finck 
20*c2c66affSColin Finck #include <locale>
21*c2c66affSColin Finck #include <algorithm>
22*c2c66affSColin Finck 
23*c2c66affSColin Finck _STLP_BEGIN_NAMESPACE
24*c2c66affSColin Finck 
25*c2c66affSColin Finck //----------------------------------------------------------------------
26*c2c66affSColin Finck // codecvt<char, char, mbstate_t>
27*c2c66affSColin Finck 
~codecvt()28*c2c66affSColin Finck codecvt<char, char, mbstate_t>::~codecvt() {}
29*c2c66affSColin Finck 
do_length(state_type &,const char * from,const char * end,size_t mx) const30*c2c66affSColin Finck int codecvt<char, char, mbstate_t>::do_length(state_type&,
31*c2c66affSColin Finck                                               const  char* from,
32*c2c66affSColin Finck                                               const  char* end,
33*c2c66affSColin Finck                                               size_t mx) const
34*c2c66affSColin Finck { return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }
35*c2c66affSColin Finck 
do_max_length() const36*c2c66affSColin Finck int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
37*c2c66affSColin Finck { return 1; }
38*c2c66affSColin Finck 
39*c2c66affSColin Finck bool
do_always_noconv() const40*c2c66affSColin Finck codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
41*c2c66affSColin Finck { return true; }
42*c2c66affSColin Finck 
43*c2c66affSColin Finck int
do_encoding() const44*c2c66affSColin Finck codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
45*c2c66affSColin Finck { return 1; }
46*c2c66affSColin Finck 
47*c2c66affSColin Finck codecvt_base::result
do_unshift(state_type &,char * __to,char *,char * & __to_next) const48*c2c66affSColin Finck codecvt<char, char, mbstate_t>::do_unshift(state_type& /* __state */,
49*c2c66affSColin Finck                                            char*       __to,
50*c2c66affSColin Finck                                            char*       /* __to_limit */,
51*c2c66affSColin Finck                                            char*&      __to_next) const
52*c2c66affSColin Finck { __to_next = __to; return noconv; }
53*c2c66affSColin Finck 
54*c2c66affSColin Finck codecvt_base::result
do_in(state_type &,const char * __from,const char *,const char * & __from_next,char * __to,char *,char * & __to_next) const55*c2c66affSColin Finck codecvt<char, char, mbstate_t>::do_in (state_type&  /* __state */ ,
56*c2c66affSColin Finck                                        const char*  __from,
57*c2c66affSColin Finck                                        const char*  /* __from_end */,
58*c2c66affSColin Finck                                        const char*& __from_next,
59*c2c66affSColin Finck                                        char*        __to,
60*c2c66affSColin Finck                                        char*        /* __to_end */,
61*c2c66affSColin Finck                                        char*&       __to_next) const
62*c2c66affSColin Finck { __from_next = __from; __to_next   = __to; return noconv; }
63*c2c66affSColin Finck 
64*c2c66affSColin Finck codecvt_base::result
do_out(state_type &,const char * __from,const char *,const char * & __from_next,char * __to,char *,char * & __to_next) const65*c2c66affSColin Finck codecvt<char, char, mbstate_t>::do_out(state_type&  /* __state */,
66*c2c66affSColin Finck                                        const char*  __from,
67*c2c66affSColin Finck                                        const char*  /* __from_end */,
68*c2c66affSColin Finck                                        const char*& __from_next,
69*c2c66affSColin Finck                                        char*        __to,
70*c2c66affSColin Finck                                        char*        /* __to_limit */,
71*c2c66affSColin Finck                                        char*&       __to_next) const
72*c2c66affSColin Finck { __from_next = __from; __to_next   = __to; return noconv; }
73*c2c66affSColin Finck 
74*c2c66affSColin Finck 
75*c2c66affSColin Finck #if !defined (_STLP_NO_WCHAR_T)
76*c2c66affSColin Finck //----------------------------------------------------------------------
77*c2c66affSColin Finck // codecvt<wchar_t, char, mbstate_t>
78*c2c66affSColin Finck 
~codecvt()79*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::~codecvt() {}
80*c2c66affSColin Finck 
81*c2c66affSColin Finck 
82*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::result
do_out(state_type &,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) const83*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::do_out(state_type&         /* state */,
84*c2c66affSColin Finck                                           const intern_type*  from,
85*c2c66affSColin Finck                                           const intern_type*  from_end,
86*c2c66affSColin Finck                                           const intern_type*& from_next,
87*c2c66affSColin Finck                                           extern_type*        to,
88*c2c66affSColin Finck                                           extern_type*        to_limit,
89*c2c66affSColin Finck                                           extern_type*&       to_next) const {
90*c2c66affSColin Finck   ptrdiff_t len = (min) (from_end - from, to_limit - to);
91*c2c66affSColin Finck   copy(from, from + len, to);
92*c2c66affSColin Finck   from_next = from + len;
93*c2c66affSColin Finck   to_next   = to   + len;
94*c2c66affSColin Finck   return ok;
95*c2c66affSColin Finck }
96*c2c66affSColin Finck 
97*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::result
do_in(state_type &,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) const98*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::do_in (state_type&       /* state */,
99*c2c66affSColin Finck                                           const extern_type*  from,
100*c2c66affSColin Finck                                           const extern_type*  from_end,
101*c2c66affSColin Finck                                           const extern_type*& from_next,
102*c2c66affSColin Finck                                           intern_type*        to,
103*c2c66affSColin Finck                                           intern_type*        to_limit,
104*c2c66affSColin Finck                                           intern_type*&       to_next) const {
105*c2c66affSColin Finck   ptrdiff_t len = (min) (from_end - from, to_limit - to);
106*c2c66affSColin Finck   copy(__REINTERPRET_CAST(const unsigned char*, from),
107*c2c66affSColin Finck        __REINTERPRET_CAST(const unsigned char*, from) + len, to);
108*c2c66affSColin Finck   from_next = from + len;
109*c2c66affSColin Finck   to_next   = to   + len;
110*c2c66affSColin Finck   return ok;
111*c2c66affSColin Finck }
112*c2c66affSColin Finck 
113*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::result
do_unshift(state_type &,extern_type * to,extern_type *,extern_type * & to_next) const114*c2c66affSColin Finck codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type&   /* state */,
115*c2c66affSColin Finck                                               extern_type*  to,
116*c2c66affSColin Finck                                               extern_type*  ,
117*c2c66affSColin Finck                                               extern_type*& to_next) const {
118*c2c66affSColin Finck   to_next = to;
119*c2c66affSColin Finck   return noconv;
120*c2c66affSColin Finck }
121*c2c66affSColin Finck 
do_encoding() const122*c2c66affSColin Finck int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
123*c2c66affSColin Finck { return 1; }
124*c2c66affSColin Finck 
do_always_noconv() const125*c2c66affSColin Finck bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
126*c2c66affSColin Finck { return true; }
127*c2c66affSColin Finck 
do_length(state_type &,const extern_type * from,const extern_type * end,size_t mx) const128*c2c66affSColin Finck int codecvt<wchar_t, char, mbstate_t>::do_length(state_type&,
129*c2c66affSColin Finck                                                  const  extern_type* from,
130*c2c66affSColin Finck                                                  const  extern_type* end,
131*c2c66affSColin Finck                                                  size_t mx) const
132*c2c66affSColin Finck { return (int)(min) ((size_t) (end - from), mx); }
133*c2c66affSColin Finck 
do_max_length() const134*c2c66affSColin Finck int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
135*c2c66affSColin Finck { return 1; }
136*c2c66affSColin Finck #endif /* wchar_t */
137*c2c66affSColin Finck 
138*c2c66affSColin Finck _STLP_END_NAMESPACE
139*c2c66affSColin Finck 
140*c2c66affSColin Finck // Local Variables:
141*c2c66affSColin Finck // mode:C++
142*c2c66affSColin Finck // End:
143*c2c66affSColin Finck 
144