]> git.buserror.net Git - polintos/scott/priv.git/blob - lib/c++/stlport/codecvt.cpp
Add STLport 5.1.4
[polintos/scott/priv.git] / lib / c++ / stlport / codecvt.cpp
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 #include "stlport_prefix.h"
19
20 #ifndef _STLP_NO_MBSTATE_T
21
22 #include <locale>
23 #include <algorithm>
24
25 _STLP_BEGIN_NAMESPACE
26
27 //----------------------------------------------------------------------
28 // codecvt<char, char, mbstate_t>
29
30 codecvt<char, char, mbstate_t>::~codecvt() {}
31
32 int codecvt<char, char, mbstate_t>::do_length(const mbstate_t&,
33                                               const  char* from,
34                                               const  char* end,
35                                               size_t mx) const
36 { return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }
37
38 int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
39 { return 1; }
40
41 bool
42 codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
43 { return true; }
44
45 int
46 codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
47 { return 1; }
48
49 codecvt_base::result
50 codecvt<char, char, mbstate_t>::do_unshift(mbstate_t& /* __state */,
51                                            char*      __to,
52                                            char*      /* __to_limit */,
53                                            char*&     __to_next) const
54 { __to_next = __to; return noconv; }
55
56 codecvt_base::result
57 codecvt<char, char, mbstate_t>::do_in (mbstate_t&   /* __state */ ,
58                                        const char*  __from,
59                                        const char*  /* __from_end */,
60                                        const char*& __from_next,
61                                        char*        __to,
62                                        char*        /* __to_end */,
63                                        char*&       __to_next) const
64 { __from_next = __from; __to_next   = __to; return noconv; }
65
66 codecvt_base::result
67 codecvt<char, char, mbstate_t>::do_out(mbstate_t&   /* __state */,
68                                        const char*  __from,
69                                        const char*  /* __from_end */,
70                                        const char*& __from_next,
71                                        char*        __to,
72                                        char*        /* __to_limit */,
73                                        char*&       __to_next) const
74 { __from_next = __from; __to_next   = __to; return noconv; }
75
76
77 #if !defined (_STLP_NO_WCHAR_T)
78 //----------------------------------------------------------------------
79 // codecvt<wchar_t, char, mbstate_t>
80
81 codecvt<wchar_t, char, mbstate_t>::~codecvt() {}
82
83
84 codecvt<wchar_t, char, mbstate_t>::result
85 codecvt<wchar_t, char, mbstate_t>::do_out(state_type&         /* state */,
86                                           const intern_type*  from,
87                                           const intern_type*  from_end,
88                                           const intern_type*& from_next,
89                                           extern_type*        to,
90                                           extern_type*        to_limit,
91                                           extern_type*&       to_next) const {
92   ptrdiff_t len = (min) (from_end - from, to_limit - to);
93   copy(from, from + len, to);
94   from_next = from + len;
95   to_next   = to   + len;
96   return ok;
97 }
98
99 codecvt<wchar_t, char, mbstate_t>::result
100 codecvt<wchar_t, char, mbstate_t>::do_in (state_type&       /* state */,
101                                           const extern_type*  from,
102                                           const extern_type*  from_end,
103                                           const extern_type*& from_next,
104                                           intern_type*        to,
105                                           intern_type*        to_limit,
106                                           intern_type*&       to_next) const {
107   ptrdiff_t len = (min) (from_end - from, to_limit - to);
108   copy(__REINTERPRET_CAST(const unsigned char*, from),
109        __REINTERPRET_CAST(const unsigned char*, from) + len, to);
110   from_next = from + len;
111   to_next   = to   + len;
112   return ok;
113 }
114
115 codecvt<wchar_t, char, mbstate_t>::result
116 codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type&   /* state */,
117                                               extern_type*  to,
118                                               extern_type*  ,
119                                               extern_type*& to_next) const {
120   to_next = to;
121   return noconv;
122 }
123
124 int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
125 { return 1; }
126
127 bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
128 { return true; }
129
130 int codecvt<wchar_t, char, mbstate_t>::do_length(const  state_type&,
131                                                  const  extern_type* from,
132                                                  const  extern_type* end,
133                                                  size_t mx) const
134 { return (int)(min) ((size_t) (end - from), mx); }
135
136 int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
137 { return 1; }
138 #endif /* wchar_t */
139
140 _STLP_END_NAMESPACE
141
142 #endif /* _STLP_NO_MBSTATE_T */
143
144 // Local Variables:
145 // mode:C++
146 // End:
147