aboutsummaryrefslogtreecommitdiff
path: root/src/codecvt.cpp
blob: 113a262340a718b10e232a82ed04a9f3cf802e94 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
/*
 * Copyright (c) 1999
 * Silicon Graphics Computer Systems, Inc.
 *
 * Copyright (c) 1999
 * Boris Fomitchev
 *
 * This material is provided "as is", with absolutely no warranty expressed
 * or implied. Any use is at your own risk.
 *
 * Permission to use or copy this software for any purpose is hereby granted
 * without fee, provided the above notices are retained on all copies.
 * Permission to modify the code and to distribute modified code is granted,
 * provided the above notices are retained, and a notice that the code was
 * modified is included with the above copyright notice.
 *
 */
#include "stlport_prefix.h"

#include <locale>
#include <algorithm>

_STLP_BEGIN_NAMESPACE

//----------------------------------------------------------------------
// codecvt<char, char, mbstate_t>

codecvt<char, char, mbstate_t>::~codecvt() {}

int codecvt<char, char, mbstate_t>::do_length(state_type&,
                                              const  char* from,
                                              const  char* end,
                                              size_t mx) const
{ return (int)(min) ( __STATIC_CAST(size_t, (end - from)), mx); }

int codecvt<char, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
{ return 1; }

bool
codecvt<char, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
{ return true; }

int
codecvt<char, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
{ return 1; }

codecvt_base::result
codecvt<char, char, mbstate_t>::do_unshift(state_type& /* __state */,
                                           char*       __to,
                                           char*       /* __to_limit */,
                                           char*&      __to_next) const
{ __to_next = __to; return noconv; }

codecvt_base::result
codecvt<char, char, mbstate_t>::do_in (state_type&  /* __state */ ,
                                       const char*  __from,
                                       const char*  /* __from_end */,
                                       const char*& __from_next,
                                       char*        __to,
                                       char*        /* __to_end */,
                                       char*&       __to_next) const
{ __from_next = __from; __to_next   = __to; return noconv; }

codecvt_base::result
codecvt<char, char, mbstate_t>::do_out(state_type&  /* __state */,
                                       const char*  __from,
                                       const char*  /* __from_end */,
                                       const char*& __from_next,
                                       char*        __to,
                                       char*        /* __to_limit */,
                                       char*&       __to_next) const
{ __from_next = __from; __to_next   = __to; return noconv; }


#if !defined (_STLP_NO_WCHAR_T)
//----------------------------------------------------------------------
// codecvt<wchar_t, char, mbstate_t>

codecvt<wchar_t, char, mbstate_t>::~codecvt() {}


codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_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 {
  ptrdiff_t len = (min) (from_end - from, to_limit - to);
  copy(from, from + len, to);
  from_next = from + len;
  to_next   = to   + len;
  return ok;
}

codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_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 {
  ptrdiff_t len = (min) (from_end - from, to_limit - to);
  copy(__REINTERPRET_CAST(const unsigned char*, from),
       __REINTERPRET_CAST(const unsigned char*, from) + len, to);
  from_next = from + len;
  to_next   = to   + len;
  return ok;
}

codecvt<wchar_t, char, mbstate_t>::result
codecvt<wchar_t, char, mbstate_t>::do_unshift(state_type&   /* state */,
                                              extern_type*  to,
                                              extern_type*  ,
                                              extern_type*& to_next) const {
  to_next = to;
  return noconv;
}

int codecvt<wchar_t, char, mbstate_t>::do_encoding() const _STLP_NOTHROW
{ return 1; }

bool codecvt<wchar_t, char, mbstate_t>::do_always_noconv() const _STLP_NOTHROW
{ return true; }

int codecvt<wchar_t, char, mbstate_t>::do_length(state_type&,
                                                 const  extern_type* from,
                                                 const  extern_type* end,
                                                 size_t mx) const
{ return (int)(min) ((size_t) (end - from), mx); }

int codecvt<wchar_t, char, mbstate_t>::do_max_length() const _STLP_NOTHROW
{ return 1; }
#endif /* wchar_t */

_STLP_END_NAMESPACE

// Local Variables:
// mode:C++
// End: